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 / make-ios-sim-shortcut.sh
Created October 23, 2013 20:35
makes a shortcut for the mac ios simulator
ln -s /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone\ Simulator.app /Applications/iPhone\ Simulator.app
@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();
@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 / 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 / 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: {
var fs = require('fs')
fs.writeFileSync(path.join(__dirname, 'public/styles/_inject.scss'), `$CDN: "${CDN}";`, 'utf8')
@positlabs
positlabs / ProductionConsole.js
Last active January 12, 2017 22:56
Disables console logging for production builds
(function(){
var noop = function noop(){};
var liveConsole = console;
var consoleMethodNames = 'assert assert clear count debug dir dirxml error group groupCollapsed groupEnd info log markTimeline profile profileEnd table time timeEnd timeStamp timeline timelineEnd trace warn'.split(' ');
var deadConsole = {};
for (var i = consoleMethodNames.length - 1; i >= 0; i--) {
deadConsole[consoleMethodNames[i]] = noop;
};
window.__debug = function (enabled){
if(enabled){
@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`).
@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 / 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,
* })