Skip to content

Instantly share code, notes, and snippets.

@jakub-g
jakub-g / async-defer-module.md
Last active July 15, 2024 12:12
async scripts, defer scripts, module scripts: explainer, comparison, and gotchas

<script> async, defer, async defer, module, nomodule, src, inline - the cheat sheet

With the addition of ES modules, there's now no fewer than 24 ways to load your JS code: (inline|not inline) x (defer|no defer) x (async|no async) x (type=text/javascript | type=module | nomodule) -- and each of them is subtly different.

This document is a comparison of various ways the <script> tags in HTML are processed depending on the attributes set.

If you ever wondered when to use inline <script async type="module"> and when <script nomodule defer src="...">, you're in the good place!

Note that this article is about <script>s inserted in the HTML; the behavior of <script>s inserted at runtime is slightly different - see Deep dive into the murky waters of script loading by Jake Archibald (2013)

@flockonus
flockonus / customEmojiCount.js
Last active December 29, 2023 17:20
Count your emojis from Slack usage!
'use strict';
/**
npm i bluebird slack-node
CREATE YOUR TOKEN: https://api.slack.com/docs/oauth-test-tokens?team_id=T024G49EC&action=reissue&sudo=1
npm package: https://www.npmjs.com/package/slack-node
user.list: https://api.slack.com/methods/users.list
@ruudud
ruudud / ghpr
Last active August 6, 2018 09:44
GitHub Pull Request Applier
#!/bin/bash
# Motivation:
# http://blog.spreedly.com/2014/06/24/merge-pull-request-considered-harmful/
#
# This script aids in the process of getting a linear Git history when using
# GitHub Pull Requests.
# A special GitHub remote ref is added, which is fetched and used to create a
# patch of changes to be applied with `git am`. The PR is then closed.
#
# INSTALL
@jontg
jontg / gist:9745186
Last active February 25, 2016 10:08
Zero Downtime
#!/bin/bash
# Source files so we can announce stuff
. /mnt/apps/scripts/setenv.sh
. /mnt/apps/scripts/hipchat_notify.sh
if [ $(pidof -x deploy_if_new.sh | wc -w) -gt 2 ]; then
echo "$(date +"%Y-%m-%d %H:%M:%S %Z") Cowardly exiting as deploy_if_new is already running"
exit -1
fi
@wandernauta
wandernauta / sp
Last active July 10, 2024 07:57
sp is a command-line client for Spotify's dbus interface. Play, pause, skip and search tracks from the comfort of your command line.
#!/usr/bin/env bash
#
# This is sp, the command-line Spotify controller. It talks to a running
# instance of the Spotify Linux client over dbus, providing an interface not
# unlike mpc.
#
# Put differently, it allows you to control Spotify without leaving the comfort
# of your command line, and without a custom client or Premium subscription.
#
@matburt
matburt / i3plug.py
Created August 10, 2012 02:51
To be used with the i3 window manager (and i3-py). Takes a command 'save' or 'restore'. When 'save' is used it will store the monitor that each workspace is assigned to. When 'restore' is used it will restore those workspaces to the monitor that it was
import os
import i3
import sys
import pickle
def showHelp():
print(sys.argv[0] + " <save|restore>")
def get_visible_workspace():
for workspace in i3.get_workspaces():
@nateps
nateps / gist:1172490
Created August 26, 2011 01:38
Hide the address bar in a fullscreen iPhone or Android web app
<!DOCTYPE html>
<meta charset=utf-8>
<meta name=viewport content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name=apple-mobile-web-app-capable content=yes>
<meta name=apple-mobile-web-app-status-bar-style content=black>
<title>Test fullscreen</title>
<style>
html, body {
margin: 0;
padding: 0;
@pjkelly
pjkelly / installer.sh
Created August 11, 2011 18:59
Installing PHPUnit via Pear on Ubuntu Lucid
# Uninstall any pre-existing packaged
# versions of phpunit
sudo apt-get remove phpunit
# Install pear via apt-get
sudo apt-get install php-pear
# Update existing pear channels
sudo pear channel-update pear.php.net
@michiel
michiel / cors-nginx.conf
Created July 5, 2011 10:41
Wide-open CORS config for nginx
#
# Wide-open CORS config for nginx
#
location / {
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
#
@mikeyk
mikeyk / redis_session_backend.py
Created April 8, 2011 18:01
A redis backend for Django Sessions, tested on Django 1.3+
from django.contrib.sessions.backends.base import SessionBase, CreateError
from django.conf import settings
from django.utils.encoding import force_unicode
import redis
class SessionStore(SessionBase):
""" Redis store for sessions"""
def __init__(self, session_key=None):
self.redis = redis.Redis(