Skip to content

Instantly share code, notes, and snippets.

Algorithmic layouts

You are looking at the most important, and most abundant thing on the web. You can't see it, unfortunately, because it's very small… aaaaand it's invisible — so having a magnifying glass doesn't really help here. But still.

I'm talking, of course, about U+0020; not to be confused with the band U2, who are just as ubiquitous, but far less useful.

This unicode point, representing the humble space character, is between every word, in every run of text, on every page of the web. And it has a very special characteristic: it's not sticky like glue. If two words are neighbors but there's not enough room for both of them, the space will free the second word to wrap around and start a new line.

Before getting into flexible containers, viewport meta tags, and @media breakpoints this humble character is what makes the web fundamentally 'responsive'. That is: able to change the layout of its content to suit different devices, contexts, and settings. Browser text does this automa

@gaearon
gaearon / modern_js.md
Last active April 18, 2024 15:01
Modern JavaScript in React Documentation

If you haven’t worked with JavaScript in the last few years, these three points should give you enough knowledge to feel comfortable reading the React documentation:

  • We define variables with let and const statements. For the purposes of the React documentation, you can consider them equivalent to var.
  • We use the class keyword to define JavaScript classes. There are two things worth remembering about them. Firstly, unlike with objects, you don't need to put commas between class method definitions. Secondly, unlike many other languages with classes, in JavaScript the value of this in a method [depends on how it is called](https://developer.mozilla.org/en-US/docs/Web/Jav
@giannisp
giannisp / gist:ebaca117ac9e44231421f04e7796d5ca
Last active March 1, 2024 14:39
Upgrade PostgreSQL 9.6.5 to 10.0 using Homebrew (macOS)
After automatically updating Postgres to 10.0 via Homebrew, the pg_ctl start command didn't work.
The error was "The data directory was initialized by PostgreSQL version 9.6, which is not compatible with this version 10.0."
Database files have to be updated before starting the server, here are the steps that had to be followed:
# need to have both 9.6.x and latest 10.0 installed, and keep 10.0 as default
brew unlink postgresql
brew install postgresql@9.6
brew unlink postgresql@9.6
brew link postgresql
@troyfontaine
troyfontaine / 1-setup.md
Last active May 12, 2024 15:17
Signing your Git Commits on MacOS

Methods of Signing Git Commits on MacOS

Last updated March 13, 2024

This Gist explains how to sign commits using gpg in a step-by-step fashion. Previously, krypt.co was heavily mentioned, but I've only recently learned they were acquired by Akamai and no longer update their previous free products. Those mentions have been removed.

Additionally, 1Password now supports signing Git commits with SSH keys and makes it pretty easy-plus you can easily configure Git Tower to use it for both signing and ssh.

For using a GUI-based GIT tool such as Tower or Github Desktop, follow the steps here for signing your commits with GPG.

@kl0tl
kl0tl / raven.js
Created December 15, 2016 13:39
Load Raven async
(function (global, document, url) {
var calls = [];
var spy = {};
var methods = ['config', 'install', 'setUserContext', 'captureException'];
for (var i = 0, method; method = methods[i]; i += 1) {
spy[method] = (function (name) {
return function () {
calls.push([name, arguments]);
return this;
@Paul-frc
Paul-frc / flex-for-ie-10-and-safari.css
Last active October 1, 2021 09:07
the flexbox equiv. for IE10
/* ==================== */
/* container attributes */
/* ==================== */
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-ms-flex-direction: row | column | row-reverse | column-reverse;
-webkit-flex-direction: row | column | row-reverse | column-reverse;
@vasanthk
vasanthk / System Design.md
Last active May 13, 2024 08:15
System Design Cheatsheet

System Design Cheatsheet

Picking the right architecture = Picking the right battles + Managing trade-offs

Basic Steps

  1. Clarify and agree on the scope of the system
  • User cases (description of sequences of events that, taken together, lead to a system doing something useful)
    • Who is going to use it?
    • How are they going to use it?

@kangax's ES6 quiz, explained

@kangax created a new interesting quiz, this time devoted to ES6 (aka ES2015). I found this quiz very interesting and quite hard (made myself 3 mistakes on first pass).

Here we go with the explanations:

Question 1:
(function(x, f = () => x) {
#/usr/bin/env bash
rm -rf ./.pngs
rm -rf ./.gifs
mkdir .pngs
mkdir .gifs
ffmpeg -i $1 -r 10 ./.pngs/out%04d.png
sips -s format gif ./.pngs/*.png --out ./.gifs
gifsicle ./.gifs/*.gif --optimize=3 --delay=3 --loopcount --resize 720x405 --colors=255 > $1.gif
gifsicle --unoptimize $1.gif | gifsicle --dither --colors 48 --resize-fit-width 512 -O2 `seq -f "#%g" 0 2 213` -o $1.optimized.gif
rm -rf $1.gif
@iimos
iimos / xpath.js
Last active April 10, 2023 13:13
Micro function that gives xpath by element and elements by xpath.
function xpath(el) {
if (typeof el == "string") return document.evaluate(el, document, null, 0, null)
if (!el || el.nodeType != 1) return ''
if (el.id) return "//*[@id='" + el.id + "']"
var sames = [].filter.call(el.parentNode.children, function (x) { return x.tagName == el.tagName })
return xpath(el.parentNode) + '/' + el.tagName.toLowerCase() + (sames.length > 1 ? '['+([].indexOf.call(sames, el)+1)+']' : '')
}
// Usage: