Skip to content

Instantly share code, notes, and snippets.

View kalley's full-sized avatar

Kalley Powell kalley

  • OneSignal
  • Houston, TX
View GitHub Profile
// Using lodash so we can use isPlainObject
var
_ = require('lodash'),
Marionette = require('backbone.marionette');
var _constructor = Marionette.View.prototype.constructor;
Marionette.View = Marionette.View.extend({
constructor: function (attributes, options) {
var self = this;
@kalley
kalley / jquery.localCompress.js
Last active December 18, 2015 11:39
plugin to facilitate using lz-string (http://pieroxy.net/blog/pages/lz-string/index.html) to compress values before adding them to localStorage using a webworker (technically, you could use anything you want, since the url for the worker gets passed in per instance). Also added "exists" method to check if a key exists in localStorage already. Ad…
// jquery.localCompress
// get, set return promises
(function($, localStorage) {
$.localCompress = function(workerURL) {
var initWorker = function(onmessage, type, value) {
var worker = new Worker(workerURL);
worker.onmessage = onmessage;
worker.postMessage({
@kalley
kalley / grunt-contrib-concat.process.js
Created June 5, 2013 21:54
grunt-contrib-concat process option to "require" files and add the source name about the block.
grunt.initConfig({
concat: {
options: {
process: function(src, filepath) {
var matches = src.match(/require\(["'].*?['"]\);?/g);
if ( matches ) {
matches.forEach(function(match) {
var path = filepath.substr(0, filepath.lastIndexOf('/') + 1) + match.match(/["'](.*?)['"]/)[1];
var fileSrc = grunt.file.read(path);
src = src.replace(match, '// Source: ' + path + '\n' + fileSrc);
@kalley
kalley / flexbox.less
Last active December 17, 2015 16:30
Flexbox LESS mixins. Covers old syntax, IE10 syntax, and modern syntax. TODO: make variations configurable. Also, possibly change the defaults to other than the CSS defaults.
// flexbox
.flex-display(@inline:false) {
@box-display: ~`"@{inline}" === 'inline' ? 'box-inline' : 'box'`;
@flex-display: ~`"@{inline}" === 'inline' ? 'inline-flex' : 'flex'`;
display: ~"-webkit-@{box-display}";
display: ~"-moz-@{box-display}";
display: ~"-ms-@{flex-display}box";
display: ~"-webkit-@{flex-display}";
@kalley
kalley / passport-oauth-api.js
Created May 21, 2013 19:52
Using a passport.js OAuth provider and using its oauth instance to access the API. (I wish there was a better way, but alas, there is not).
// Uses passport-bitbucket
var strategy = new BitbucketStrategy({
consumerKey: BITBUCKET_CONSUMER_KEY,
consumerSecret: BITBUCKET_CONSUMER_SECRET,
callbackURL: "http://127.0.0.1:3000/auth/bitbucket/callback"
},
function(token, tokenSecret, profile, done) {
// asynchronous verification, for effect...
process.nextTick(function () {
api.setTokens(token, tokenSecret);
@kalley
kalley / jquery.teletype.js
Created April 26, 2013 15:19
jquery.teletype.js - teletype plugin. Relies on lettering.js. If you have big blocks of text, this can get CPU intensive.
// jquery.teletype
// depends on lettering.js
(function($) {
var Teletype = function(el, options) {
this.el = el;
this.opts = $.extend({}, $.fn.teletype.defaults, options);
this.containers = $(el).find(this.opts.selector);
this.init();
@kalley
kalley / jquery.event.press.js
Last active December 15, 2015 06:19
creates a "press" event that uses clicks for mouses and touchend for touch devices. Current dependencies: jQuery and Modernizr for touch support detection
// jquery.event.press
(function($, Modernizr) {
"use strict";
var touchEnabled = Modernizr && Modernizr.touch;
if ( touchEnabled ) {
// Lift touch properties using fixHooks, inspired by jquery.panzoom, with checks
var touchHook = { props: [ "touches", "targetTouches", "changedTouches", "pageX", "pageY" ] };
$.each([ "touchstart", "touchmove", "touchend" ], function( i, name ) {
var existingHook = $.event.fixHooks[ name ];
if ( ! existingHook ) {
@kalley
kalley / jquery.placeholders.js
Created January 3, 2013 19:49
Add placeholders when necessary and make them act like placeholders. Use CSS to style .placeholder
if ( ! Modernizr.placeholder ) {
(function($) {
$(document).find('input[placeholder]').each(function() {
var el = $(this).on('keyup blur change', function() {
placeholder[this.value.length > 0 ? 'hide' : 'show']();
});
var css = {};
var offset = el.position();
css.left = offset.left + parseFloat(el.css('padding-left')) + parseFloat(el.css('margin-left'));
css.top = offset.top + parseFloat(el.css('padding-top')) + parseFloat(el.css('margin-top'));
var fs = require('fs');
var spawn = require('child_process').spawn;
var summary = [];
var errors = [];
var app = {
toProcess: 0,,
processed: 0,
readdir: function(err, files) {
// Easily find all labels, or a filtered set of labels for the element
;(function($) {
$.fn.findLabels = function(filterSelector) {
filterSelector = filterSelector || '';
return $(document).find('label[for="'+this[0].id+'"]'+filterSelector);
};