Skip to content

Instantly share code, notes, and snippets.

const cacheName = 'my-cache-1'
self.addEventListener('install', event => {
console.log('install')
});
self.addEventListener('activate', event => {
console.log('activate')
event.waitUntil(self.clients.claim())
});
/* @flow */
declare class CacheOptions {
ignoreSearch: ?bool;
ignoreMethod: ?bool;
ignoreVary: ?bool;
cacheName: ?bool;
}
declare interface Cache {
add(url: string): Promise<void>;
addAll(urls: [Request | string]): Promise<void>;
@homam
homam / index.html
Created September 16, 2016 14:31
service workers offline page
<!doctype html>
<html lang=en-GB>
<head>
<meta charset='utf-8'>
<title>The Air Horner</title>
<meta name='viewport' content='width=device-width, initial-scale=1'>
</head>
<body>
<iframe style="position: fixed; top: 0; left: 0; right: 0; bottom: 0; width:100%; height: 100%"
src="http://tv-app-web-map.herokuapp.com/"
@homam
homam / imgur-example.html
Last active September 26, 2022 06:08
html2canvas example
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.js"></script>
<form method="POST" enctype="multipart/form-data" action="https://www.google.com/save" id="myForm">
<input type="hidden" name="img_val" id="img_val" value="" />
</form>
<div id="more">
<h1 style='color: red'> hello </h1>
<iframe src="https://tags.mli.me/12751">
</iframe>
@homam
homam / Callback-monad-then-only.js
Created July 8, 2016 20:53
Callback-monad-then-only
class Callback {
constructor(f) {
// this.run = f
this.run = callback => {
try {
f(callback)
} catch (ex) {
callback(ex, null)
}
@homam
homam / index.html
Last active July 6, 2016 12:39 — forked from d3noob/.block
Sankey from csv with d3.js
<!DOCTYPE html>
<meta charset="utf-8">
<title>SANKEY Experiment</title>
<style>
.node rect {
cursor: move;
fill-opacity: .9;
shape-rendering: crispEdges;
}
class Kleisli {
// given f :: x -> Monad y, constructs a category of type:
// Cat (x ↣ y)
constructor(f) {
// this.run = f
this.run = x => f(x)
// this :: Cat (x ↣ y)
class Func {
constructor(f) {
// this.run = f
this.run = x => f(x)
// this :: Cat (x ↣ y)
// Cat (y ↣ z) -> Cat (x ↣ z)
this.pipe = g => new Func(x => g.run(this.run(x)))
// utility function that pipes Func to a normal function
class Callback {
constructor(f) {
// this.run = f
this.run = callback => {
try {
f(callback)
} catch (ex) {
callback(ex, null)
}
class Callback {
constructor(f) {
this.run = (...args) => {
f(...args)
}
this.map = g => new Callback((...args) => {
const nArgs = R.init(args)
const callback = R.last(args)