Skip to content

Instantly share code, notes, and snippets.

View sstur's full-sized avatar

Simon Sturmer sstur

View GitHub Profile
type Listener<T extends Array<unknown>> = (...args: T) => void;
export class EventEmitter<
E extends Record<string, Array<unknown>> = Record<never, []>
> {
private listenerMap: { [K in keyof E]?: Set<Listener<E[K]>> } = {};
on<K extends keyof E>(key: K, listener: Listener<E[K]>) {
return this.addListener(key, listener);
}
@mikelambert
mikelambert / ProportionalImage.js
Created April 13, 2016 12:24
Renders an Image that stays proportionally sized to its original dimensions.
var ProportionalImage = React.createClass({
getInitialState() {
return {
style: {}
};
},
propTypes: {
originalWidth: React.PropTypes.number.isRequired,
@rstacruz
rstacruz / Readme.md
Last active December 23, 2015 08:09
timewriter.js readme

timewriter

Minimal time logs tracker. Runs on Node.js. Features:

  • Friction-free time logging. Just type t shopping in the grocery to start a task.

  • Everything in the terminal. It's a Node.js command-line app that runs anywhere Node can. (even Windows!)

@topliceanu
topliceanu / micro-mustache.js
Created December 30, 2011 04:22
John Resig's Micro Template with changed tags from <%=, %> into more mustache-esque {{= and }}
// Simple JavaScript Templating
// John Resig - http://ejohn.org/ - MIT Licensed
(function(){
var cache = {};
this.tmpl = function tmpl(str, data){
// Figure out if we're getting a template, or if we need to
// load the template - and be sure to cache the result.
var fn = !/\W/.test(str) ?
cache[str] = cache[str] ||
@micahasmith
micahasmith / ckeditor-selection-wrap-with-rangy.js
Created November 11, 2011 20:08
Wrap a selection in CKEditor with Rangy
/**
* allows you to wrap or insert an html tag over a selection/range using rangy
* @param iframe the CKEditor iframe html element
* @param tagName string representation of the tag, such as 'a' for anchor
* @param withNodeFunc function to allow outside modification of the element before injecting/wrapping
*/
function wrapOrInsert(iframe, tagName, withNodeFunc) {
var iframedoc = iframe.contentDocument || iframe.contentWindow.document,
tag = iframedoc.createElement(tagName),
selection = rangy.getIframeSelection(iframe),