Skip to content

Instantly share code, notes, and snippets.

View positlabs's full-sized avatar
🌶️
Focusing

Josh Beckwith positlabs

🌶️
Focusing
View GitHub Profile
@positlabs
positlabs / Events.js
Last active June 1, 2017 22:10
Event broadcasting that follows the on / off / trigger pattern
/**
Event broadcasting that follows the on / off / trigger pattern
@arg obj: optional object to extend with events. NOTE: this event system only listens to events sent with .trigger.
dom events will not be listened for. To avoid confusion, you probably shouldn't use this on dom elements.
var e = new Events();
e.on("eventname", callbackFunc); // add event listener
e.off("eventname", callbackFunc); // rm event listener
@positlabs
positlabs / HashRouter.js
Last active December 29, 2015 09:29
hash router
/**
@HashRouter: Singleton hash router object.
// define onroute function
HashRouter.onroute = function(hash){}
// start the router
HashRouter.start();
define(function (require, exports, module) {
/**
*
* simple stagger function
*
* TODO: add option for a timing function... will require changing @arg interval to duration
*
* */
return function (targets, interval, action, delay) {
@positlabs
positlabs / rateLimit.js
Created January 10, 2014 18:51
limit the rate of firing for a function
function rateLimit(func, time){
var callback = func,
waitTimeout,
waiting = false,
context = this;
var rtn = function(){
if(waiting) return;
waiting = true;
var args = arguments;
@positlabs
positlabs / block.sh
Created May 13, 2014 06:03
get bitcoin blockchain download status
#!/bin/bash
while true ; do
clear
echo "Press enter to break loop. Script will loop every 3 seconds"
echo "If loop freezes press CTRL+C"
echo ""
echo -e " \033[31mdownloaded\e[0m/\033[32mavailable\e[0m"
echo -e " \033[31m"`bitcoind getblockcount 2>&1`"\e[0m"/"\033[32m"`wget -O - http://blockchain.info/q/getblockcount 2>/dev/null`"\e[0m"
read -t 3 -n 3 && break
done
@positlabs
positlabs / BaseShader.shader
Created June 18, 2014 21:06
Shader template for unity materials
Shader "Custom/BaseShader" {
Properties {
_MainTex ("MainTexture", 2D) = "white" {}
_PlateTex ("PlateTexture", 2D) = "white" {}
}
SubShader {
Pass{
CGPROGRAM
#pragma vertex vert
@positlabs
positlabs / gist:7ac2ea02ead7daf1da4d
Last active September 2, 2015 22:37
Filmstrip sprite example
$frame.css({
backgroundImage: 'url("' + imgPath + '")',
backgroundSize: numFrames*100 + '% ' + '100%'
});
var tl = new TimelineMax.to($frame, numFrames/frameRate, {
backgroundPosition: -(numFrames-1)*100+ '% 0',
ease: SteppedEase.config(numFrames-1),
delay: startDelay,
});
@positlabs
positlabs / CuePoints.js
Last active December 22, 2015 21:57
Respond to cuepoints during video playback
/*
// mapping cues to methods
var cuepointMethods = {
"1": function(){},
"2.82": function(){},
"3.31": function(){}
};
// instantiate with <video>, and an array of cuepoint times => [1, 2.82, 3.31]
@positlabs
positlabs / TextSplit.js
Last active August 10, 2018 00:17
Super simple replacement for GSAP's SplitText. Not as robust, but it's editable.
/**
* splitText - function to split words into html elements based on words and characters
* @param html text to split
* @param options optional parameters
* @example splitText('some text', {
* wordClass: 'word',
* charClass: 'char',
* chars: true,
* })
@positlabs
positlabs / component-base.js
Created October 21, 2016 01:31
Component base with some convenience methods
/*
http://x-tags.org/docs
usage:
const ComponentBase = require('./component-base')
xtag.register('x-foo', {
prototype: ComponentBase.prototype,