Today I Learned - Rocky Kev

Today I Learned

Things I pick up through the hairy journey of development.

Tag Cloud

The Latest 100 Posts

  1. TIL what is npm Script

    Despite their high usage they are not particularly well optimized and add about 400ms of overhead. In this article we were able to bring that down to ~22ms.

  2. TIL Netflix's System Design

    Netflix operates in two clouds: Everything that happens after you hit play is handled by Open Connect. Open Connect stores Netflix video in different locations throughout the world. Anything that doesn’t involve serving video is handled in AWS.

  3. TIL the Waluigi Effect in LLMs

    The Waluigi Effect: After you train an LLM to satisfy a desirable property 'P', then it's easier to elicit the chatbot into satisfying the exact opposite of property 'P'.

  4. TIL using the find command

    find [path] -user [username] [options]

  5. TIL defining your video game in hooks

    I like to think of a game’s potential in terms of 'hooks.' By this, I’m referring to the inherent momentum within a title to hook a buyer. I was just looking at the data on Steam, and there were 10,963 new game titles released in 2022. My strong suspicion is that most of them never generated a dime in revenue. Without some hook for your game, no one will ever play it, much less buy it.

  6. TIL fancy methods to transform Javascript Objects

    You can use Object.entries(), Object.keys(), Object.fromEntries()...

  7. TIL how to hide your JS code

    ONE THING TO NOTE: Encrypting a script is stronger than obfuscation, both methods are still not adequate to protect secret content. Honestly, I don't think it's worth it on a production site, and instead just go with pure server-side if you want security. But it's fascinating.

  8. TIL how build tools work

    There's 4 steps. Compiling -> Minifying -> Bundling -> Code-splitting

  9. TIL how to build a chrome extension that steals everything

    There's 3 components that will be used - background Service worker, Content script, and popup.

  10. TIL minimal responsive image component

    So when I saw that JS frameworks made image wrapper components (like Nuxt was with nuxt-img), I was blown away and wanted this power at work.

  11. TIL executing a xss using a SVG image

    This user was able to upload a '.svg', that then executed a xss attack to steal local storage data.

  12. TIL How to steal localData using an XSS attack

    But that's just a red flag that opens the door to bigger issues.

  13. TIL Dwarf Fortress Game Design

    'Do not design for your experienced players' and some more tips from one of the most complicated games ever

  14. TIL the alternate keyword

    If 'alternate' appears along with the stylesheet keyword, the linked file is an alternative stylesheet. It won’t be applied to the document, but it will be ready for when we need it.

  15. TIL Clear-Site-Data

    The Clear-Site-Data header clears browsing data (cookies, storage, cache) associated with the requesting website. It allows web developers to have more control over the data stored by a client browser for their origins.

  16. TIL not obsessively trying to be DRY

    Quite often, DRY is applied to any duplication, rather than specifically to the duplication of business rules and knowledge. This is often made worse by automated code analysis tools, which will often highlight any duplication as a code smell.

  17. TIL the cost of spaces on TypeScript compile

    One nice surprise we found from using esbuild was that on-disk size was reduced by more than we expected. It turns out that a big reason for this is that esbuild uses 2 spaces for indentation in output instead of the 4 spaces that TypeScript uses. When gzipping, the difference is very small; but on disk, we saved a considerable amount.

  18. TIL a bunch of new functional programming words

    It's so funny seeing developers re-invent functional programming paradigms. We really need to teach this stuff better.

  19. TIL Indirection and Swallowing the error

    Op shared a tryCatch util that is problematic.

  20. TIL Why is TextEncoder a class

    My assumed answer - it was for extension. What does reddit commenters have to say about it?

  21. TIL Logical Properties

    For that sweet sweet Internationalization you want to avoid directional words like 'left', 'right', 'top', and 'bottom'.

  22. TIL Evil code

    These examples are unethical, and can even be criminal. You can get jailtime. You have been warned and I cannot be held liable for your dumb-assery.

  23. TIL Static Blocks vs Dynamic Blocks

    A static block is a piece of content whose markup is known when the page is saved. The block saves its content and markup directly in the post content. A dynamic block is a piece of content whose markup and exact content are not known when the page is saved.

  24. TIL how to convert a shortcode to a WP block

    Traditionally, shortcodes were a way that plugin developers could provide users the ability to add specific plugin functionality anwhere on their site. But shortcodes are not very user friendly, nor was hunting down the relevant data you needed to render the correct data for the shortcode. Converting existing shortcodes to blocks provides a much greater user experience in all aspects.

  25. TIL Play music in a bash script

    On Macs, you have the afplay command. to play some sweet tunes.

  26. TIL Google Sheets has named functions

    It's a way for you to make functions using built-in formulas.

  27. TIL how to JUICE up your UI

    The delightful chimes sound that plays when Mario collects a mushroom. The 1UP text that appears is essential. Communicating the player gained an extra life. The sound is the Juice.

  28. TIL why google recommends you avoid document.write()

    By injecting it with code, it bypasses the preload scanner. This means that the browser can’t request this file until it’s actually run the '<script>' block that inserts it, which is very much just-in-time (and too late).

  29. TIL Using pseudo-classes in your querySelector!

    let notTuna = document.querySelectorAll('.sandwich:not(.tuna)')

  30. TIL using abortController to removing events

    Trying to unhook a eventListener? Don't use `removeEventListener`, instead use AbortController.

  31. TIL detecting if a user is online with JS

    You can use the navigator.onLine api.

  32. TIL prioritizing Javascript

    ... async and defer attributes should be used where possible to avoid render blocking of the DOM. Render blocking is when the browser must halt all rendering of the page in order to process a resource that the page depends on.

  33. TIL problem with AJAX

    Synchronous XHR is harmful for performance because the event loop and main thread is blocked until the request is finished, resulting in the page hanging until the data becomes available. fetch is a much more effective and efficient alternative with a simpler API, and has no support for synchronous fetching of data.

  34. TIL why jpeg vs jpg

    In DOS systems, a filename extension was a different part of the name stored in a different field that can only be 3 characters. You still see this legacy today in Microsoft's .NET software, where most system calls that use the word 'filename' in their name don't really mean the whole filename. They mean just the part without the extension.

  35. TIL Container Queries are live!

    After @container, elements can respond to a parent container size or style! The only caveat is the containers must declare themselves as possible query targets, which is a small requirement for a large benefit.

  36. TIL the history of fonts and COLRv1

    COLRv1 fonts, have a smaller footprint, vector-scalable, reposition-able, gradient-featuring, and blend-mode powered fonts that accept parameters to customize the font per use case or to match a brand.

  37. TIL ":has" selector

    Before :has(), the subject of a selector was always at the end. Like 'ul > li:hover' or 'ul > li:not(.selected)'. Now we can do ul:has(> li)

  38. TIL Harmful language

    We’ve talked before, we’ve used that phrase “words matter” because words matter, words are the way we communicate with one another, it is how we perceive our self value in our own head.

  39. TIL ways to organize eventListeners

    Some code spaghetti I made recently was creating a lot of eventListeners for multiple buttons, and then forgot what they all connected to.

  40. TIL a helper to make things uppercase

    ucWords function converts the first character of each word in a string to uppercase. This function is the same as PHP’s ucWords function.

  41. TIL the core-js spam trolling

    This entire repo is a hilarious rabbit-hole when you combine this with everyone complaining about the console spam that the dev added to it asking if anyone can find him a job. One of my favorite PRs

  42. TIL how Error correction works in HTML

    You never get an 'Invalid Syntax' error on an HTML page. Browsers fix any invalid content and go on.

  43. TIL Legend of Zelda course corrects movement

    If you play The Legend of Zelda for a while, you’ll notice that Link doesn’t ever get hung up on obstacles due to unexpected collisions, nor do you ever just miss a bad guy by a pixel or two when attacking him.

  44. TIL what DOCTYPE means

    tl;dr: DOCTYPE declaration in the first line of the HTML file, to instruct the browser to run the code in Standard mode.

  45. TIL how Levels.fyi used Google Sheets

    Our philosophy to scaling is simple, avoid premature optimization.

  46. TIL How many Fucks there are in Linux

    As of today, in the Linux Repo, there are comments that contains the following mentions: 1,651 for hacks, 2,863 for workarounds, and 4,102 for fixme

  47. TIL Dirty bit systems in browsers

    In order not to do a full layout for every small change, browsers use a 'dirty bit' system. A renderer that is changed or added marks itself and its children as 'dirty': needing layout. There are two flags: 'dirty', and 'children are dirty' which means that although the renderer itself may be OK, it has at least one child that needs a layout.

  48. TIL individual transform CSS

    We now have individual transform CSS!

  49. TIL Web Performance with Javascript

    Overall, we should be loading the most important JS first to get the website working. Then load all your third-party scripts onto your web worker, which then responds with 'Success' once it loads, so you can then interact with it.

  50. TIL how QR codes work

    The Quick Response code was invented by a subsidiary of Toyota to track parts across the manufacturing process.

  51. TIL Shape-Outside to wrap text

    Shape-outside provides a way to customize this wrapping, making it possible to wrap text around complex objects rather than simple boxes.

  52. TIL keywords in package.json

    Today I learned what keywords are in a package.json file! It's a collection of keywords about a module. Keywords can help identify a package, related modules and software, and concepts.

  53. TIL Tagged Templates

    Tags allow you to parse template literals with a function. The first argument of a tag function contains an array of string values. The remaining arguments are related to the expressions.

  54. TIL Find Command

    I wanted to look for files with a specific extension. You can do that with ls *.(mp3|exe|mp4)

  55. TIL Multiple Fetch Requests

    I've been frequently dealing with this scenario in the past few weeks. I wanted to make multiple fetch requests, and then merge everything together when it's all done. To make multiple/parallel fetch requests:

  56. TIL Forever Seinfeld

    Nothing, Forever is a parody of '90s sitcoms, done in the style of '90s point-and-click PC games (but, you know, in 3D). We set out to build something weird, new, and novel, and this is what we ended up with.

  57. TIL wanting to use the latest thing

    In evaluating a solution, be sure to consider the library dying out or becoming a maintenance burden after 5 years (e.g., everyone trying to get off jQuery onto Web Components).

  58. TIL why you should always use textContent

    Today I learned the difference between 'Node.textContent'. It handles all elements, even hidden ones. It also prevents XSS attacks since it strips tags.

  59. TIL critical 14kb

    On the OSI Model -- the physical layer, we send data in 14kb packets. And servers respond to HTTP requests in 14kb chunks. (Note: It can be set to different sizes, but by default... 14kb is the standard/magic number)

  60. TIL no global styles

    Global styles is the largest **anti-pattern** in CSS --- strong DISAGREE.

  61. TIL types of malicious npm attacks

    In the case of ionicons, the miscreants published 18 versions containing malicious form-stealing code; for example, icon-package (according to NPM download stats) has over 17,000 downloads. Other typo-squatting examples include umbrellaks instead of umbrellajs and so on.

  62. TIL malware in node_modules

    The very first line fetches the victim's country code using their IP address. If the victim is from Russia, Ukraine, Belarus, or Kazakhstan, then the malware exits early.

  63. TIL Infinite State Machines in Doom

    The actual core logic of the enemies is a Finite State Machines: a simple but effective mechanism to state that a character executes a specific behaviour when in a given state, and what the conditions are that will force it to change.

  64. TIL Land in Virtual Games

    in [Star Wars] Galaxies … there was ample room for everyone to own a house if they chose – but people did things like build player cities atop the entrances to dungeons to monopolize access to resources.

  65. TIL Scoping with Cypress

    So you wanted to find a specific element called `heading`. But you have a BUNCH of elements called `heading`. By using `within()` helper, you can force it to only look inside `main` elements.

  66. TIL the first webcam

    The Trojan Room coffee pot was a coffee machine located in the Computer Laboratory of the University of Cambridge, England. Created in 1991 by Quentin Stafford-Fraser and Paul Jardetzky, it was migrated from their laboratory network to the web in 1993 becoming the world's first webcam.

  67. TIL SolidJS reactivity

    SolidJS is a JavaScript framework that supports binding data to elements that it then syncs and displays on web pages.

  68. TIL a mod dedicated to his fiance

    The best way to avoid DVT is simple: Save your game, stand up, and walk around for 2-3 minutes every 3 or 4 hours. Go to the fridge, pee, look out the window, play with your pet...anything, just MOVE. That simple action would have saved her life: it could save yours.

  69. TIL porting Zelda Classic from a Windows App to the browser

    He learned about each layer of the codebase, and how to transpile it down to the next layer until finally hitting Web APIs.

  70. TIL Computed Properties in Javascript

    Today I learned about Computed Property names.

  71. TIL outputting objects in Node

    In your Node projects -- sometimes you just need to output the object. Stringify it.

  72. TIL if TypeScript is worth it

    The answer: No, according to HackerNews. But HackerNews audience aren't exactly representative of average developers? From my perspective, they're the 'startup' and 'ship fast and break things' folks. (I mean, I am too!)

  73. TIL Very Efficient Code

    This is a great solution. Easy to understand. Executes really fast. No real-time string concatenation. No over-engineering. String appearance is easily customized.

  74. TIL delta time

    Delta time, also known as 'time delta,' refers to the difference between the 'current time' and the 'last time' a piece of code was executed. In JavaScript, delta time can be calculated using the Date object or by using the performance.now() method.

  75. TIL finding the browser being used

    How to detect the browser you're using, with javascript.

  76. TIL ChatGPT prompts

    Don’t ask it to write an essay about how human error causes catastrophes. The AI will come up with a boring and straightforward piece that does the minimum possible to satisfy your simple demand.

  77. TIL Libuv

    Libuv also implements two extremely important features of Nodejs which are the event loop and the thread pool and in simple terms, the event loop is responsible for handling easy tasks like executing callbacks and network I/O while the thread pool deals with heavy work like file access or compression.

  78. TIL brackets breaking elements in JavaScript

    The 'automatic semicolon insertion' it does is an error correction process

  79. TIL obscure search engines

    We all know the big ones like Google and Bing that have massive Indexes. THen we know about Wolfram Alpha and DuckDuckGo. But have you heard of Thunderstone?

  80. TIL IndexNow

    IndexNow is an open-source protocol that allows website publishers to instantly index across participating search engines, updating results based upon the latest content changes.

  81. TIL the fix everything script

    A script that fixes everything for end-users

  82. TIL RXJchess and how it was built

    How was this chess engine made?

  83. TIL all the different security roles

    In appsec most notably offense vs defense. They are complimentary of course but the skills differ. For offense you need specific tools, need to get used to testing applications sometimes without source code access.

  84. TIL Trovald's Magic Numbers

    These magic numbers are intended to safeguard against a typo or potential bit flips in the syscall number. Since reboot is a destructive and non-syncing operation, it's important to make absolutely sure that it isn't called accidentally due to a typo, a misbehaving program, or memory error

  85. TIL node modules fs and os

    with fs - you can access files, read files, make directories, chmod. With os - get stats, machine, version, hosts.

  86. TIL Node Streams

    Imagine if you did some data-extensive fetch request getting a 1 gig file. 1 gig can take a while, and it's fetching it in memory.

  87. TIL Websockets

    They offer a long lived, bidirectional communication channel between client and server. Once established, the channel is kept open, offering a very fast connection with low latency and overhead.

  88. TIL Node.js Event Emitter

    This is kinda like the addEventListener() for browser javascript.

  89. TIL Double Exclamation shorthand for booleans

    JavaScript (and TypeScript) lets you convert a non-Boolean value to Boolean using the double exclamation shorthand. '!!'

  90. TIL how to delete all cookies with Javascript

    If someone selects 'Reject', you want to remove all the tracking cookies. You can easily clear all cookies stored in a web page by accessing the cookie using document.cookie and clearing it.

  91. TIL Content sectioning

    Content sectioning or landmarks, like sidebar, content, footer. You know, like better names.

  92. TIL the Description List element

    Lists of name–value pairs (or, in some cases, name–value groups) are a common pattern across the web, in part due to their versatility. HTML lets us mark up these lists with a combination of three elements

  93. TIL MSW for mocking

    MSW is a API mocking tool. Mock by intercepting requests on the network level. Seamlessly reuse the same mock definition for testing, development, and debugging.

  94. TIL Sparse Arrays

    The ['Batman', , 'Bane'] array is a sparse array. See how it there is a blank?

  95. TIL accessing different data attributes

    You can access it in javascript using element.getAttribute('data-sandwich'). A better way is to go with the Element.dataset property.

  96. TIL aspect ratios

    We can target iframe elements directly with a few lines of CSS to preserve their dimensions in responsive layouts, without the need for a wrapper element.

  97. TIL Performance tests

    While doing performance tests, I was curious how long a loop was running. I used the performance.now() trick.

  98. TIL playing Tetris inside Zsh

    If you're using a Mac, you're probably using iTerm. 1. Load iTerm 2. launch emacs. 3. Launch Tetris.

More posts can be found in the archive.