Skip to content

Instantly share code, notes, and snippets.

Jasper wellcaffeinated

Block or report user

Report or block wellcaffeinated

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@wellcaffeinated
wellcaffeinated / RXJS Observable from mongoose (mongodb) cursor.js
Created May 30, 2018
Rx.Observable that can sequentially pull data from a mongoose (mongodb) cursor with fine control over concurrency
View RXJS Observable from mongoose (mongodb) cursor.js
const Rx = require( 'rxjs/Rx' );
// This took me way too long to figure out. Hope this helps someone.
// <3 Well Caffeinated
function fromCursor( cursor ){
return new Rx.Observable((obs) => {
// is the connection closed
var closed = false
// get the next document
@wellcaffeinated
wellcaffeinated / fully canceled
Created Feb 26, 2018
Intellitix sent data examples
View fully canceled
{
"source": "51",
"orderid": "5a7b92a6a28ee8467bc2dd2b",
"status": "canceled",
"miscfields": {
"25": "Piper",
"26": "Wendy",
"51": "wendy.piper@blah.com"
},
"tickets": [
@wellcaffeinated
wellcaffeinated / renderer-pixi.js
Created Jan 8, 2014
Very rough implementation of a pixi.js renderer for PhysicsJS. Only supports circles right now.
View renderer-pixi.js
Physics.renderer('pixi', 'canvas', function( parent ){
return {
init: function( options ){
// create an new instance of a pixi stage
this.stage = new PIXI.Stage(0xffffff);
// create a renderer instance.
this.renderer = PIXI.autoDetectRenderer(options.width, options.height);
@wellcaffeinated
wellcaffeinated / strategies-1.js
Created Dec 6, 2013
PhysicsJS collision monitoring strategies
View strategies-1.js
// If you want to subscribe to collision pairs
// emit an event for each collision pair
world.subscribe('collisions:detected', function( data ){
var c;
for (var i = 0, l = data.collisions.length; i < l; i++){
c = data.collisions[ i ];
world.publish({
topic: 'collision-pair',
bodyA: c.bodyA,
bodyB: c.bodyB
@wellcaffeinated
wellcaffeinated / math-utils.js
Created Nov 19, 2013
Very crude approximation to gaussian random number. It's fast, but it's NOT accurate.
View math-utils.js
// VERY crude approximation to a gaussian random number.. but fast
var gauss = function gauss( mean, stddev ){
var r = 2 * (Math.random() + Math.random() + Math.random()) - 3;
return r * stddev + mean;
};
@wellcaffeinated
wellcaffeinated / complex-expression.js
Created Nov 15, 2013
Complex expression parser (uses scratchpad.js)
View complex-expression.js
!function(){
var orderOfOps = ['+', '-', '*', '/'];
var rules = {
'+' : 'add',
'-' : 'subtract',
'*' : 'multiply',
'/' : 'divide'
};
@wellcaffeinated
wellcaffeinated / raf.js
Created Nov 15, 2013
requestAnimationFrame polyfill
View raf.js
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
// requestAnimationFrame polyfill by Erik Moller
// fixes from Paul Irish and Tino Zijdel
(function(window) {
var lastTime = 0;
var vendors = ['ms', 'moz', 'webkit', 'o'];
for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
@wellcaffeinated
wellcaffeinated / asm-helpers.js
Last active Dec 22, 2016
Helper module for creating collections of objects that store their properties inside typed arrays. Useful for managing objects that will be used by asm.js modules. Code by Jasper Palfree (http://wellcaffeinated.net) License: MIT See comments for usage examples. See this blog post for explanation: http://wellcaffeinated.net/articles/2013/04/16/pl…
View asm-helpers.js
/**
* asm-helpers.js
* A simple helper module for managing memory allocation of
* collections of objects, particularly for use in asm.js code
*
* Copyright (c) 2013 Jasper Palfree <jasper@wellcaffeinated.net>
* Licensed MIT
*/
(function (root, factory) {
if (typeof exports === 'object') {
View fake-nth-child-mixin.scss
// Fake the :nth-child(#) selector shim for ie8
// @author Jasper Palfree <http://wellcaffeinated.net>
// finders props to Graham Losee
// ---------------------------------------------------
// limited functionality, only works for
// strictly numeric $n values and child
// elements must be of the same type.
// $sel is the type of selector.
// $extend is the class (or selector)
// to @extend from.
View simple-templating.js
/**
* Very simple find/replace template.
*
* Optional filter function that is used on tags with three curlies. Ex: `{{{this_param_will_be_filtered}}}`
*
* @function {mixin} Application.template
* @param {string} t templateable string
* @param {object} d data object
* @... {string} yourKey containing value to replace
* @param {function(value)} filter a filter function that is passed members of `d` that are templated by triple curlys
You can’t perform that action at this time.