Skip to content

Instantly share code, notes, and snippets.

View scheduler.ts
// We have two types of work, A, B. We schedule A to be done very frequently!
// It doesn't take a lot of time (maybe a ms or two), but B can take a decent
// amount of time (maybe 10ms+).
// Write a scheduler that can perform tasks A and B as often as possible, BUT
// does not result in any frame skipping (do not lock the main thread for very
// long).
if (typeof requestAnimationFrame === "undefined") {

You want to logically group fields together based on their auth strategy.

You can define a type that groups your service fields together:

type Services {
  updateUser(name: String!): User
  activateUser(active: Boolean!): User
kesne / index.js
Last active Dec 16, 2017
View index.js
import BetterWorker from 'better-worker';
const bgSort = new BetterWorker((threads) => {
return threads.sort((threadA, threadB) => {
return > ? 1 : -1;
// Using the worker-ified function:
kesne /
Last active Apr 20, 2017


There's no standardized, cross-platform, developer-friendly way to detect what environment you're running code in. The JS community has generally centered around reading process.env.NODE_ENV, but this property feels out of place in browser code, and requires a lot of typing at every usage (it's too easy to get wrong or flip the condition backwards). Some people set up __DEV__ to transpile down to process.env.NODE_ENV !== 'production' for a better developer experience.

Enter global.env

A new property, hung on the global object. This spec is to satisfy node, browser, and native.

What is it?

View DefaultWithNamespace.noclass.js
import { registerExtension } from './extensionManager';
function createNamespacingMiddleware(reducerKey, reducerNamespace) {
return () => next => (action) => {
const namespacedAction = action;
namespacedAction.meta = {
withNamespace: {
View play.c
/* play.c */
#include "mp2.h"
/***************************************************************** shuffle *****************************************************************************************/
void shuffle(int cards[][12], int num_cards[], int drawnDeck[])
kesne / app.js
Created Jan 11, 2014
Fact.JS Demo
View app.js
//Create app view:
fact.view('app', {
//called on render of the view:
render: function(elem){
//Set up the fact.js router with the app view. We could make this call anywhere, such as after the render, but it's easy here because we have reference to the just-created element (elem).
//The element that we want the router to apply to. In this case, it's the outlet
element: elem.$('.outlet'),
//Routes that we specify:
kesne / accordion.js
Last active Dec 17, 2015
Device Details Compatibility Layer
View accordion.js
// Create a new YUI instance and populate it with the required modules.
YUI().use('node', 'event', function (Y) {
// Node is available and ready for use. Add implementation
// code here.
var allPanels = Y.all('.accordeonContainer > .accordeonContent').hide();
var panelHeaders = Y.all('.accordeonContainer > h2');
panelHeaders.on('click', function(e) {
//Get the parent node:
package net.keenstudios.orient;
import org.apache.cordova.api.PluginResult;
import org.json.JSONArray;
import android.content.Intent;
import android.os.Environment;
import com.phonegap.api.Plugin;
kesne / transition.js
Created May 27, 2012
Comprehensive overview of adding book transitions.
View transition.js
//Name of the transition:
name: "everything",
//Using this will set up the step function, automatically transitioning between values.
//If you don't set this as true, you're expected to provide your own step function.
auto: true,
//Set it up to use next/back animations.
directional: true,
//Set the easing function. The default is enyo.easing.quadInOut. You can also define your own easing function here.
easing: enyo.easing.quadInOut,