Skip to content

Instantly share code, notes, and snippets.

View kirbysayshi's full-sized avatar

Drew Petersen kirbysayshi

View GitHub Profile
@kirbysayshi
kirbysayshi / lbp-serialization.js
Created January 2, 2018 23:54
Not the best JS (whoa global scope!) but I think this proves out the core ideas. Probably some bugs still.
// JS Implementation of https://yave.handmade.network/blogs/p/2723-how_media_molecule_does_serialization
// We have to make several changes due to JS's dynamic nature, and lack of type
// information, outlined below.
// The rules:
// 1) Every class/valuetype needs a `serialize_TYPENAME(version, serializer, datum)`
// function. This gets around JS not having function overloading as well as the
// implicit type annotation that function overloading (in the original C example)
@kirbysayshi
kirbysayshi / index.js
Last active November 8, 2017 00:38
requirebin sketch
function swiper (root, onUp, onRight, onDown, onLeft) {
const touches = [];
root.addEventListener('touchstart', stash, false);
root.addEventListener('touchmove', stash, false);
root.addEventListener('touchcancel', function () { touches.length = 0; }, false);
root.addEventListener('touchend', compute, false);
// same order at dots below
const cbs = [onUp, onRight, onDown, onLeft];
@kirbysayshi
kirbysayshi / boid.js
Last active September 20, 2017 18:29
Common code to support a tutorial on fixed-time steps and game loops.
/**
* A verlet integration circle, a simple physics entity.
*/
function Boid(x, y, radius) {
this.cpos = { x: x, y: y }
this.ppos = { x: x, y: y }
this.acel = { x: 0, y: 0 }
this.radius = radius;
}
@kirbysayshi
kirbysayshi / example.js
Created May 19, 2011 19:24
Detect if Flash is blocked (On-Demand) in Chrome
flashAvail({ waitFor: 10000 })
.done( function(result){
if(result.flashBlocked === false){
// do whatever you need flash for
} else {
// flash is installed but blocked. present messaging
alert('Oops!',
'It appears that Flash is being blocked. \
Flash is required for Grill Circle and Facebook. \
Please enable it and refresh the page.');
@kirbysayshi
kirbysayshi / LICENSE
Created August 6, 2011 05:35 — forked from kriskowal/LICENSE
Nano-promises
Copyright 2011 Kristopher Michael Kowal. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
@kirbysayshi
kirbysayshi / output.sh
Created December 20, 2011 23:46
debugging ssh pubkeys
drew$ ssh -vvv HOSTNAME.COM
OpenSSH_5.6p1, OpenSSL 0.9.8r 8 Feb 2011
debug1: Reading configuration data /Users/drew/.ssh/config
debug1: Applying options for *HOSTNAME.COM
debug1: Reading configuration data /etc/ssh_config
debug1: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to HOSTNAME.COM [XXX.XXX.XXX.XXX] port 22.
debug1: Connection established.
debug3: Not a RSA1 key file /Users/drew/.ssh/id_rsa_bt.
@kirbysayshi
kirbysayshi / meyerish.css
Created June 14, 2011 19:12
Various css resets in one location
/*********** Resets */
div, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6,
pre, form, fieldset, input, textarea, p, blockquote, th, td { margin: 0; padding: 0; }
fieldset, img { border: 0; }
table { border-collapse: collapse; border-spacing: 0; }
ol, ul { list-style: none; }
address, caption, cite, code, dfn, em, strong, th, var { font-weight: normal; font-style: normal; }
caption, th { text-align: left; }
h1, h2, h3, h4, h5, h6 { font-weight: normal; font-size: 100%;}
q:before, q:after { content: ''; }
@kirbysayshi
kirbysayshi / index.js
Created September 23, 2016 04:19
requirebin sketch
function swiper (root,
onUp, onRight, onDown, onLeft,
onTap, onHoldStart, onHoldEnd,
tapEpsilon
) {
tapEpsilon = tapEpsilon || 5;
let holdRef = null;
let hasFiredHold = false;
@kirbysayshi
kirbysayshi / index.js
Created September 8, 2016 01:31
requirebin sketch
var assert = require('assert');
function update(root, path, value) {
//let id = 0;
// shallow clone the root because changing a child necessarily
// forces a new root copy?
let parent = Array.isArray(root)
? Array.from(root)
: Object.assign({}, root);
@kirbysayshi
kirbysayshi / README.markdown
Created June 13, 2011 04:40
quick nodejs script to combine, possibly minify, scripts, as well as precompile templates:

This is a quick example of taking a config file (example.js), and running jscombine.js. It will bundle up regular scripts as well as templates (hard coded to use doT). Compiled templates are automatically added to a "templates" property on the given namespace (ns key in the example file), keyed by a slightly transformed version of their filename.