Skip to content

Instantly share code, notes, and snippets.

View rsp's full-sized avatar

Rafał Pocztarski rsp

View GitHub Profile
@rsp
rsp / better-box-model-no-box-model.md
Last active July 19, 2023 04:12
Better Box Model == No Box Model - how to solve problems with CSS3 box-sizing: border-box; https://twitter.com/pocztarski/status/489619558991675393

Better Box Model == No Box Model

The premise is that a better box model would be no box model at all, or rather no dependence on any particular box model that happens to be in use.

This proposal specifies new CSS properties that would make working with issues related to box-sizing easier and less error prone.

Problems

Gzipped benchmarks for HTML Minifier

Note: this is a temporary solution for anyone who would like to see statistics of minification+gzipping vs. just gzipping the HTML before the gzipped stats are properly integrated into the main benchmark.

How to run the benchmarks from https://github.com/rsp/html-minifier/tree/gzip-benchmark

Clone the repo:

git clone https://github.com/rsp/html-minifier.git
@rsp
rsp / lorempixel-local.md
Last active May 28, 2018 23:36
Local lorempixel

How to quickly download Lorempixel images.

You can directly use URLs like this: http://lorempixel.com/400/300/nature/1/ but they will be downloaded every time from the Lorempixum server (they are not cached). For better performance or cache control you may want to save them locally. You can use cURL with its little known syntax for its input and -o arguments to do it easily.

Save filenames like nature-400x300-5.jpg:

curl 'http://{lorempixel}.com/{400}/{300}/{nature}/[1-10]/' -o '#4-#2x#3-#5.jpg'
@rsp
rsp / sha-filesystem.md
Last active August 29, 2015 14:11
SHA filesystem idea

I want a filesystem that doesn't use c/m/atime. It would use SHA-1 (or other) hash to identify data.

Possible ways to do it:

  • hash the entire file (probably not practical unless it could use partial/incremental computations)
  • hash every block and then hash the list of hashes
  • ...

Programs like Make instead of relying on the mtime would have to keep track of which hashes the sources had for any given target and if the hashes on disk are different then rebuild but at that point no hashes would need to be computed because they would be stored in the file system.

@rsp
rsp / save-for-posterity.md
Last active August 29, 2015 14:17
Save for Posterity Bookmarklet
@rsp
rsp / io-api-of-my-dreams.md
Last active November 11, 2018 15:51
I/O API of My Dreams

I/O API of My Dreams

by Rafał Pocztarski

(This gist should be called "An asynchronous file and stream I/O API of my dreams for Node.js and a postulate to never mix concepts perfect for the events abstraction with concepts perfect for the promises abstraction, because those are non-overlapping magisteria never to be confused or interchanged" but it just doesn't sound as good.)

(See also a newer post: Promise You Call Me Back for some background.)

Let's say that I open a file for writing and everything is fine. I start writing like there was no tomorrow and then suddenly I fill the entire disk and get an error. I can handle it by truncating the file or not, or maybe deleting some other files but even though I got an error I still might be able to do something else later. The point is that after some errors I don't have to give up all my hope. The error is saying: Your stream has some problems. But it still exists.

@rsp
rsp / callback-promise.md
Last active November 11, 2018 15:17
Promise You Call Me Back

Promise You Call Me Back

by Rafał Pocztarski

One of my answers on Stack Overflow where I explain the difference between promises and traditional callbacks on the example of AJAX in jQuery - jQuery: Return data after ajax call success - had a 4th birthday few days ago and it still gets upvotes so I decided to explain few concepts that I think are important but rarely considered.

I noticed that there are many people who prefer callbacks, or promises, or events - as though they were all equivalent ways to do the same thing in a different style - but they are not. Of course they are equivalent in some sense in a way that you can do with one what you can do with the other, but there is some impedance mismatch that is often overlooked.

Using events vs. promises is not like using using curly braces vs. indentation to divide code in blocks. It's more like using functional programming vs

@rsp
rsp / package.json
Last active January 21, 2016 11:12 — forked from coryhouse/package.json
Example of pre and post scripts in package.json
{
"name": "npm-scripts-example",
"version": "1.0.0",
"description": "npm scripts example",
"scripts": {
"help-list": "echo It lists all json files",
"list": "ls *.json",
"help-time": "echo It prints current time in UTC",
"time": "date -uIs",
"help-numbers": "echo It prints numbers from 1 to 10",
@rsp
rsp / package.json
Created January 21, 2016 10:57
A proposed convention for npm scripts descriptions
{
"name": "npm-scripts-example",
"version": "1.0.0",
"description": "npm scripts example",
"scripts": {
"list?": "echo It lists all json files",
"list": "ls *.json",
"time?": "echo It prints current time in UTC",
"time": "date -uIs",
"numbers?": "echo It prints numbers from 1 to 10",
@rsp
rsp / Reducing-JavaScript-to-Absurdity.md
Last active March 15, 2016 15:12
Reducing JavaScript to Absurdity

Reductio ad absurdum