Skip to content

Instantly share code, notes, and snippets.

@doug
doug / get_type.ts
Created March 23, 2017 15:27
Dynamically get the type of a deeply nested function in typescript.
function myfunc(): number {
return 42;
}
const tmp = (false as true) && myfunc();
type MyType = typeof tmp; // MyType is correctly number
@doug
doug / pomodoro.sh
Created February 4, 2017 00:04
lazy terminal pomodoro for linux
sleep 1500 && notify-send break
const provider = Symbol();
export function provide(key: symbol, value: any, ctx?: HTMLElement) {
const node: any = ctx || document.body;
let providers = node[provider];
if (!providers) {
node[provider] = providers = {};
node.addEventListener('di-provider', (event: CustomEvent) => {
event.detail.provider = providers[event.detail.key];
event.preventDefault();
class Embree < Formula
homepage "http://embree.github.io/"
url "https://github.com/embree/embree/releases/download/v2.13.0/embree-2.13.0.x86_64.macosx.tar.gz"
sha256 "09107fa9cfb5f2a17f366d745e01e6bacaae20cd5e52dbb3aaf8579f4bbce302"
def install
lib.install Dir["lib/libembree.2.dylib"]
include.install Dir["include/*"]
system "ln", "-s", (lib/"libembree.2.dylib"), (lib/"libembree.dylib")
end
@doug
doug / mixin.ts
Last active December 4, 2016 21:55
Mixins for TypeScript
export interface Empty {}
export interface Class<T> {
new(): T;
}
export type Super = Class<Empty>;
export interface Mixin<M, S> {
<T extends S>(s: Class<T>): Class<T & M>;
function b64encode(arr) {
return btoa(String.fromCharCode.apply(null, arr));
}
function b64decode(str) {
return atob(str).split('').map(function (c) { return c.charCodeAt(0); });
}
@doug
doug / article.md
Created August 22, 2016 06:32
dumb test

Hello

This is not an article.

@doug
doug / random.js
Created October 16, 2015 00:38
Seeded random value
var seed = 1;
function random() {
var x = Math.sin(seed++) * 10000;
return x - Math.floor(x);
}
@doug
doug / dropframes.sh
Created December 16, 2014 21:47
drop every other frame of a gif
# http://graphicdesign.stackexchange.com/questions/20908/how-to-remove-every-second-frame-from-an-animated-gif
gifsicle "$1" --unoptimize $(seq -f "#%g" 0 2 $numframes) -O2 -o "$2"
@doug
doug / webcomponets.html
Created December 8, 2014 00:26
conditionally load webcomponents
<!-- Conditionally load WC polyfills -->
<script>
if ('registerElement' in document
&& 'createShadowRoot' in HTMLElement.prototype
&& 'import' in document.createElement('link')
&& 'content' in document.createElement('template')) {
// We're using a browser with native WC support!
} else {
document.write('<script src="/bower_components/webcomponentsjs/webcomponents.js"><\/script>');
}