Skip to content

Instantly share code, notes, and snippets.

// 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).
// MOCK TO MAKE NODE WORK:
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
kesne / index.js
Last active December 16, 2017 20:37
better-worker
import BetterWorker from 'better-worker';
const bgSort = new BetterWorker((threads) => {
return threads.sort((threadA, threadB) => {
return threadA.id > threadB.id ? 1 : -1;
});
});
// Using the worker-ified function:
@kesne
kesne / README.md
Last active April 20, 2017 00:00
global.env

Why?

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?

import { registerExtension } from './extensionManager';
function createNamespacingMiddleware(reducerKey, reducerNamespace) {
return () => next => (action) => {
const namespacedAction = action;
namespacedAction.meta = {
...action.meta,
withNamespace: {
reducerKey,
@kesne
kesne / app.js
Created January 11, 2014 05:03
Fact.JS Demo
//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).
fact.router({
//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
kesne / accordion.js
Last active December 17, 2015 22:19
Device Details Compatibility Layer
// 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.content.pm.ActivityInfo;
import android.net.Uri;
import android.os.Environment;
import com.phonegap.api.Plugin;
@kesne
kesne / transition.js
Created May 27, 2012 04:18
Comprehensive overview of adding book transitions.
enyo.Book.transition({
//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,
@kesne
kesne / slade.js
Created May 27, 2012 01:15
Villo Books "Slade" Transition
enyo.Book.transition({
name: "slade",
auto: true,
directional: true,
transition: {
duration: 500,
next: {
visible: {
opacity: 1,
transform: {