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 / LazyPromise.js
Last active May 19, 2017 23:27
LazyPromise is a cachey promise creator that returns a function. It's good for lazily running things only once.
/*
LazyPromise is a cachey promise creator that returns a function.
It's good for lazily running things only once.
Promise creation is deferred until the first call.
Construct using same signature as a regular Promise (except it doesn't require `new`).
var fs = require('fs')
fs.writeFileSync(path.join(__dirname, 'public/styles/_inject.scss'), `$CDN: "${CDN}";`, 'utf8')
@positlabs
positlabs / component-template.js
Created October 21, 2016 01:36
Boilerplate for xtag components
// http://x-tags.org/docs
const ComponentBase = require('./component-base')
xtag.register('x-boilerplate', {
prototype: ComponentBase.prototype,
lifecycle: {
@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,
@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 / 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 / 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 / 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 / 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 / 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;