Skip to content

Instantly share code, notes, and snippets.

View olivmonnier's full-sized avatar
💭
¯\_(ツ)_/¯

Olivier Monnier olivmonnier

💭
¯\_(ツ)_/¯
View GitHub Profile
@olivmonnier
olivmonnier / Sandbox.js
Created March 7, 2019 13:34 — forked from westc/Sandbox.js
A JavaScript sandbox which works by using a web worker.
(function(undefined) {
var global = this;
var FUNC_PATHS = Object.keys(console).reduce(function (carry, name) {
if ('function' === typeof console[name]) {
carry.push(['console', name]);
}
return carry;
}, [['alert']]);
function WORKER_CODE() {
(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 = () => {
@olivmonnier
olivmonnier / implicit.js
Created February 15, 2019 08:31 — forked from raganwald/implicit.js
Balanced parentheses solution with implicit state
function balanced (string) {
const iterator = string[Symbol.iterator]();
return balancedIterator(iterator) === true;
}
const CLOSE = {
'(': ')',
'[': ']',
'{': '}'
@olivmonnier
olivmonnier / sw.js
Created December 20, 2018 11:06 — forked from ireade/sw.js
Handle broken images with the service worker
self.addEventListener('install', (e) => {
e.waitUntil(
caches.open("precache").then((cache) => cache.add("/broken.png"))
);
});
function isImage(fetchRequest) {
return fetchRequest.method === "GET" && fetchRequest.destination === "image";
}
@olivmonnier
olivmonnier / native jQuery methods.js
Created December 7, 2018 12:20 — forked from jochemstoel/native jQuery methods.js
Vanilla implementations of commonly used jQuery methods.
/**
* Convenient shortcut
*/
Object.defineProperty(window, 'define', {
value: (property, ...meta) => meta.length == 2 ? Object.defineProperty(meta[0], property, meta[1]) : Object.defineProperty(window, property, meta[0]),
writable: false,
enumerable: true
})
@olivmonnier
olivmonnier / codegolf.md
Created October 4, 2018 11:44 — forked from xem/codegolf.md
JS code golfing

codegolf JS

Mini projects by Maxime Euzière (xem), subzey, Martin Kleppe (aemkei), Mathieu Henri (p01), Litterallylara, Tommy Hodgins (innovati), Veu(beke), Anders Kaare, Keith Clark, Addy Osmani, bburky, rlauck, cmoreau, maettig, thiemowmde, ilesinge, adlq, solinca, xen_the,...

(For more info and other projects, visit http://xem.github.io)

(Official Slack room: http://jsgolf.club / join us on http://register.jsgolf.club)

@olivmonnier
olivmonnier / xhr.js
Last active December 13, 2017 17:00
Intercept xhr
(function(open) {
XMLHttpRequest.prototype.open = function() {
this.addEventListener("readystatechange", function() {
console.log(this.readyState);
}, false);
open.apply(this, arguments);
};
})(XMLHttpRequest.prototype.open);
const Right = x =>
({
x,
map: f => Right(f(x)),
inspect: _ => `Right(${x})`,
isLeft: _ => false,
chain: f => f(x),
})
const Left = x =>
@olivmonnier
olivmonnier / slimdown.js
Created December 4, 2017 16:49 — forked from renehamburger/slimdown.js
slimdown.js
'use strict';
/**
* Javascript version of https://gist.github.com/jbroadway/2836900
*
* Slimdown - A very basic regex-based Markdown parser. Supports the
* following elements (and can be extended via Slimdown::add_rule()):
*
* - Headers
* - Links
@olivmonnier
olivmonnier / webworks_and_jquery.md
Created November 24, 2017 16:44 — forked from amcdnl/webworks_and_jquery.md
Web Workers and jQuery

Web workers and jQuery

Web workers are great; they provide a powerful way to run background threads on website.

I wanted to create a more convenient way to deal with them in a jQuery-esque way. This code allows you to create a web worker and returns a jQuery.Deferred extended with some of the web worker methods on the instance.

// Alias vendor prefixes to standard.
if (!window.BlobBuilder) {

window.BlobBuilder = window.WebKitBlobBuilder || window.MozBlobBuilder;