Skip to content

Instantly share code, notes, and snippets.

@Saajan
Saajan / service-workers.md
Created January 27, 2025 14:04 — forked from Rich-Harris/service-workers.md
Stuff I wish I'd known sooner about service workers

Stuff I wish I'd known sooner about service workers

I recently had several days of extremely frustrating experiences with service workers. Here are a few things I've since learned which would have made my life much easier but which isn't particularly obvious from most of the blog posts and videos I've seen.

I'll add to this list over time – suggested additions welcome in the comments or via twitter.com/rich_harris.

Use Canary for development instead of Chrome stable

Chrome 51 has some pretty wild behaviour related to console.log in service workers. Canary doesn't, and it has a load of really good service worker related stuff in devtools.

@Saajan
Saajan / install_pyenv_mac_zsh.rst
Created August 4, 2022 21:57 — forked from josemarimanio/install_pyenv_mac_zsh.rst
Installing pyenv on macOS for Zsh using Homebrew

ZIP

zip -r directory.zip directory

ZIP WITHOUT ROOT FOLDER cd directory;zip -r ../directory.zip .

disk space in partition

@Saajan
Saajan / Docker.md
Last active April 23, 2021 18:51
Docker Documentation

To connect to Postgres you could use a database tool like DBeaver or from the command line, running this command:

$ docker ps -f "name=postgres"

-f: Filter output based on conditions provided

To get the CONTAINER_ID of the running container, and execute

$ docker exec -it /bin/bash

@Saajan
Saajan / SSH in Ubuntu
Last active August 27, 2015 09:02
Ubuntu Tool install
ls -al ~/.ssh
# Lists the files in your .ssh directory, if they exist
#With Terminal still open, copy and paste the text below. Make sure you substitute in your GitHub email address.
! ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
# Creates a new ssh key, using the provided email as a label
# Generating public/private rsa key pair.
# We strongly suggest keeping the default settings as they are, so when you're prompted to "Enter a file in which to save the key", just press Enter to continue.

How to Setup Node and Express on Amazon Web Services EC2

  1. Make an account on Amazon Web Services http://aws.amazon.com/

  2. Create a vanilla Ubuntu micro EC2 instance

  3. Security Open HTTP, HTTPS, Port 8080, and Port 9000

forEach is the "loop through them all" function, but ES5 defined several other useful "work your way through the array and do things" functions, including:

  • every-- (stops looping the first time the iterator returns false or something falsey)
  • some-- (stops looping the first time the iterator returns true or something truthy)
  • filter-- (creates a new array including elements where the filter function returns true and omitting the ones where it returns false)
  • map --(creates a new array from the values returned by the iterator function)
  • reduce-- (builds up a value by repeated calling the iterator, passing in previous values;see the spec for the details; useful for summing the contents of an array and many other things)
  • reduceRight-- (like reduce, but works in descending rather than ascending order)
@Saajan
Saajan / ArrayToObject.js
Last active August 29, 2015 14:25
Array to object
function toObject(arr) {
var obj = {};
for (var i = 0; i < arr.length; ++i)
obj[i] = arr[i];
return obj;
}
@Saajan
Saajan / iterator-timeout-closure.js
Last active August 30, 2021 19:22
The setTimeout makes it so that the iterator has gone to the full value of N by the time the setTimeout fires, so all statements print the same value. The fix? Use closures/self executing function to capture the value when the setTimeout is first set so that it maintains the correct corresponding value. Just use a bind...
for (var j = 0; j < 10; j++) {
setTimeout(function (index) {
console.log(index);
}.bind(null, j), 0);
}
for (let j = 0; j < 10; j++) {
setTimeout(function () {
console.log(j);
@Saajan
Saajan / Browser Detection .js
Last active August 29, 2015 14:25
Browser Detection
var userAgent = navigator.userAgent.toLowerCase(),
browser = '',
version = 0;
$.browser.chrome = /chrome/.test(navigator.userAgent.toLowerCase());
// Is this a version of IE?
if ($.browser.msie) {
userAgent = $.browser.version;
userAgent = userAgent.substring(0,userAgent.indexOf('.'));