Today I Learned

Catastrophic backtracking in regular expressions

performance,regular-expressions

#TIL about Catastrophic backtracking in regexps that can potentially bring down your service as it happened in the case of Cloudfare. Be mindful of your repetition op usage!

Read more: https://www.regular-expressions.info/catastrophic.html

Created at: Mon Jul 15 2019 13:53:05 GMT+0000 (Coordinated Universal Time)

Set default apps in macOS with EASE!

software,tools,macos

#TIL about RCDefaultApp, a wonderful blast from the past! It adds a pane in the System Preferences app to set defaults for pretty much anything on macOS. brew cask install rcdefaultapp ftw!

Read more: https://apple.stackexchange.com/questions/261881/set-default-mail-client-without-adding-mail-account

Created at: Tue Jul 09 2019 09:16:30 GMT+0000 (Coordinated Universal Time)

Semigroups and monoids ftw!

category-theory,functional-programming

#TIL that any function of type a -> a is a monoid under function composition with the identity value of the identity function. I.e., given ∘ is fn composition, (f ∘ f) ∘ f = f ∘ (f ∘ f) and f ∘ id = id ∘ f where id is the identity fn: id(a) = a

Read more: https://twitter.com/muditameta/status/1137828272501399552?s=21

Created at: Sun Jun 09 2019 21:50:58 GMT+0000 (Coordinated Universal Time)

Create a docker container without starting it with docker-compose

docker

#TIL that you can create a docker container without starting it using docker-compose up --no-start <service name>. This is handy when all you really want to do is copy some artifacts from the built image onto the host filesystem (in CI or locally).

Read more: https://github.com/zeusdeux/docker-playground

Created at: Thu Mar 28 2019 11:24:21 GMT+0000 (Coordinated Universal Time)

Removing the passphrase from an RSA private key

docker,openssl

#TIL: Run openssl rsa -in locked.pem -out unlocked.pem to remove the passphrase from the input key! It's great for testing docker builds locally that require an ssh key for example. And yes, you'll be prompted for the passphrase when you run that cmd.

Read more: https://www.openssl.org/docs/manmaster/man1/rsa.html

Created at: Wed Mar 27 2019 22:15:09 GMT+0000 (Coordinated Universal Time)

docker-compose run

docker

#TIL that docker-compose run doesn't map the ports if your docker-compose.yml specifies a ports key. It's by design.

Read more: https://github.com/docker/compose/issues/1259

Created at: Wed Mar 27 2019 13:15:31 GMT+0000 (Coordinated Universal Time)

Variable fonts ftw!

web,css

#TIL about variable fonts which can declare attributes that can be manipulated by the user to change how the font looks when rendered! Try them on v-fonts!

Read more: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Fonts/Variable_Fonts_Guide

Created at: Sun Mar 03 2019 20:44:23 GMT+0000 (Coordinated Universal Time)

HideShow mode for code folding in emacs

javascript,emacs

#TIL about HideShow mode that's built into emacs as of Emacs 20. It enables syntactic hide/show of code blocks & supports many langs such as JS, C, Java, Lisps, Python, etc. Use: Enable hs-minor-mode in your buffer & then hit C-c @ C-c to toggle blocks

Read more: https://www.emacswiki.org/emacs/HideShow

Created at: Fri Mar 01 2019 14:27:06 GMT+0000 (Coordinated Universal Time)

LD_PRELOAD for profit!

c

#TIL about LD_PRELOAD env var that let's one load shared objects or libs before loading the C runtime lib. In essence, you can use it to provide your own definition of functions that override those provided by other libs. E.g., provide your own malloc.

Read more: https://jvns.ca/blog/2014/11/27/ld-preload-is-super-fun-and-easy/

Created at: Tue Jan 22 2019 11:40:50 GMT+0000 (Coordinated Universal Time)

Sum types with never in Typescript

functional-programming,typescript

#TIL that a sum type that has never resolves to a type that has no never in it. For e.g. let x: string | never // type -> string. This is the trick used to implement Exclude simply as type Exclude<T, U> = T extends U ? never : T! More in the link

Read more: https://bit.ly/2CPMbPo

Created at: Sat Jan 05 2019 17:37:42 GMT+0000 (Coordinated Universal Time)

Toggling hidden items in Finder

macos

#TIL that, as of macOS Sierra, you can toggle hidden files visibility in Finder by pressing CMD + Shift + .

No more executing defaults write ... in the terminal!

Read more: https://ianlunn.co.uk/articles/quickly-showhide-hidden-files-mac-os-x-mavericks/

Created at: Fri Jan 04 2019 15:38:33 GMT+0000 (Coordinated Universal Time)

Querying for face being used by character under cursor in emacs

emacs

#TIL that you get info about the char under the cursor in emacs by using the chord C-u C-x =. The prefix arg, C-u, is what gives the details & is a neat way to find out the face you need to modify to change how something (e.g., keyword) is displayed.

Read more: https://stackoverflow.com/a/22951243/1727349

Created at: Wed Jan 02 2019 23:37:35 GMT+0000 (Coordinated Universal Time)

Custom shell bindings that work everywhere*?

terminal,readline

#TIL that you can bind custom actions (fns, macros or strings) to custom keybindings by leveraging Readline and its init file, .inputrc. For e.g: "\ev": "code .\n" will open current folder in vscode when you press alt/option+v in your shell.

Read more: https://www.gnu.org/software/bash/manual/html_node/Readline-Init-File-Syntax.html#Readline-Init-File-Syntax

Created at: Wed Jan 02 2019 22:28:41 GMT+0000 (Coordinated Universal Time)

Tired of typing out the same bit of data that you want to POST using curl?

curl,http

#TIL that one can get curl to read a file and POST its contents to the given URL by appending the file name with the @ character. For example:

curl -X POST -d @myfile.json -H 'Content-Type: application/json' https://foo.bar.in/baz

Read more: https://curl.haxx.se/docs/manpage.html#-d

Created at: Wed Jan 02 2019 22:13:38 GMT+0000 (Coordinated Universal Time)

Scroll two buffers together in emacs you say?

emacs

#TIL that you can scroll all your buffers in unison by enabling a built in minor mode called scroll-all-mode. My use case was to visually diff a file and its refactored counterpart. Invoking it again disables it & returns you to normal scroll behaviour.

Read more: https://stackoverflow.com/a/18092297

Created at: Wed Jan 02 2019 14:11:24 GMT+0000 (Coordinated Universal Time)

Express.js and named capture groups 🙅🏻‍♂️

javascript,web,regular-expressions,node

#TIL that Express.js (version 4.16.4 as of writing this) does not work with the new named regex capture groups in JS. It breaks with a confusing and weirdly un-googleable error. Not only that, you have to wrap the whole regex into a non-capturing group.

Read more: https://github.com/zeusdeux/til.mudit.xyz/blob/master/now-dev.js#L43

Created at: Thu Dec 27 2018 22:50:17 GMT+0000 (Coordinated Universal Time)

How to disable Sentry integration in dev?

javascript,node,error-reporting

#TIL learnt that to disable Sentry integration (in dev or so), you can pass anything false-y as the value for options.dsn to the Sentry.init(options) function.

ಠ_ಠ

The good thing is that this works in apparently all their clients!

Read more: https://github.com/getsentry/sentry-symfony/issues/38#issuecomment-271825703

Created at: Thu Dec 27 2018 22:37:30 GMT+0000 (Coordinated Universal Time)

Sentry nodejs package isn’t modelled to be used serverless-ly

javascript,node,error-reporting,serverless,lambda

#TIL that @sentry/node buffers exceptions your app sends to sentry.io and sends 'em over the wire async. This fails with lambdas as they cease to exist after responding. The work around is await-ing on Sentry.getCurrentHub().getClient().close(2000)

Read more: https://github.com/getsentry/sentry-javascript/issues/1449

Created at: Wed Dec 26 2018 22:43:01 GMT+0000 (Coordinated Universal Time)

HTTP2 Server Push on CDNs that support it

web,performance,http2

#TIL that one can enable HTTP2 Server Push on CDNs that support it by using the Link http header. E.g., Link: </css/custom.css>; as=style; rel=preload, </img/favicon.ico>; as=image; rel=preload.

Read more: https://www.smashingmagazine.com/2017/04/guide-http2-server-push/

Created at: Sun Dec 16 2018 16:40:21 GMT+0000 (Coordinated Universal Time)

HSTS preload list

web,security,https,hsts

#TIL about the HSTS preload list maintained by google. It prevents all browsers that respect this list from connecting to page in the list using an insecure protocol like http. Your website can qualify if it sets the Strict-Transport-Security header.

Read more: https://hstspreload.org

Created at: Sun Dec 16 2018 16:40:00 GMT+0000 (Coordinated Universal Time)

Epoch based computer time

time,software

#TIL about different epochs used by software. Specifically win32/64 epoch of January 1, 1601 (UTC). The FileTime struct holds time elapsed in 100 nanosecond intervals since January 1, 1601 (UTC). Why? "it was chosen to make the math come out nicely".

Read more: https://en.wikipedia.org/wiki/Epoch_(reference_date)#Notable_epoch_dates_in_computing

Created at: Sun Dec 16 2018 16:39:41 GMT+0000 (Coordinated Universal Time)