Skip to content

Instantly share code, notes, and snippets.

@staltz
staltz / example.js
Created March 18, 2019 20:59
Build your own RxJS
function createObservable(subscribe) {
return {
subscribe,
pipe: function(operator) {
return operator(this);
},
};
}
const numberObservable = createObservable(function(observer) {
@DavidKuennen
DavidKuennen / minimal-analytics-snippet.js
Last active October 24, 2024 18:10
Minimal Analytics Snippet
(function (context, trackingId, options) {
const history = context.history;
const doc = document;
const nav = navigator || {};
const storage = localStorage;
const encode = encodeURIComponent;
const pushState = history.pushState;
const typeException = 'exception';
const generateId = () => Math.random().toString(36);
const getId = () => {
@jakub-g
jakub-g / async-defer-module.md
Last active November 4, 2024 20:19
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)

// ==UserScript==
// @name Spotify ad skipper
// @version 1.0
// @namespace http://tampermonkey.net/
// @description Detects and skips ads on spotify
// @match https://*.spotify.com/*
// @grant none
// @run-at document-start
// @downloadURL https://gist.githubusercontent.com/Simonwep/24f8cdcd6d32d86e929004013bd660ae/raw
// @updateURL https://gist.githubusercontent.com/Simonwep/24f8cdcd6d32d86e929004013bd660ae/raw
@mindplay-dk
mindplay-dk / woohah.ts
Last active September 16, 2015 17:09
Typescript event hook and hookable boxed value classes
/// This interface defines an event listener
interface Listener<Event> {
(event: Event): void
}
/// This interface represents a hookable type
interface Hookable<Event> {
/// Attach a handler to this hookable
(handler: Listener<Event>): void
}
@mindplay-dk
mindplay-dk / modeling.md
Created February 11, 2015 17:00
Approaches to modeling

Approaches to modeling

In this short write-up, I will briefly summarize the types of modeling I have seen and attempted over the years, highlighting some of the advantages and drawbacks of each, ending with a conclusion explaining which one I prefer and why.

1. Bare Models

@mindplay-dk
mindplay-dk / README.md
Last active August 29, 2015 14:14
Replace a checkbox with a custom div for styling

jQuery plugin to replace checkboxes with <div> elements for styling.

This plugin makes no assumptions about class-names or the contents of the <div> element, it only implements the behavior - it returns the generated <div> elements for further operations with jQuery functions, so you can do for example:

$('input[type=checkbox]')
    .checkbox()            // returns set of <div> elements
    .addClass('checkbox')  // adds class="checkbox" to every <div> element

.html('✔') // inserts a unicode checkmark into every element

@mindplay-dk
mindplay-dk / error-relay.php
Last active August 29, 2015 14:08
Relay php errors to exceptions
<?php
/**
* Map php errors to the built-in ErrorException class.
*
* Respects the error_reporting() setting and the error-suppression operator.
*
* @see ErrorException
*/
@mindplay-dk
mindplay-dk / Cache.php
Last active May 6, 2017 18:20
Simplied cache interface
<?php
namespace Psr\Cache;
/**
* Cache defines a common driver interface for interacting with a cache back-end.
*/
interface Driver
{
/**
@mindplay-dk
mindplay-dk / bench.js
Created March 22, 2014 04:36
JavaScript benchmark function
// noprotect
/**
* JavaScript benchmark function
*
* Usage: console.log(bench(function(){ ... }));
*/
bench = (function() {
var