Skip to content

Instantly share code, notes, and snippets.

@ryanflorence
ryanflorence / LICENSE.txt
Created November 9, 2011 15:09 — forked from 140bytes/LICENSE.txt
140byt.es -- Click ↑↑ fork ↑↑ to play!
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@ryanflorence
ryanflorence / getCache.js
Created November 7, 2011 18:44
Cache data in the localStorage
var getCache = (function() {
var supportsLocalStorage = 'localStorage' in window;
// both functions return a promise, so no matter which function
// gets called inside getCache, you get the same API.
function getJSON(key) {
return jQuery.getJSON(key).then(function(data) {
localStorage.setItem(key, JSON.stringify(data));
}).promise();
}
@ryanflorence
ryanflorence / jshint-and-vim.md
Created November 2, 2011 18:29
Get jshint running on write (save) with VIM
  1. Download [jshint.vim][jshint]

  2. Put it in ~/.vim/plugin/jshint.vim

  3. Edit your local vimrc file (I'm on macvim with janus, so it's at ~/.gvimrc.local) and add:

    au BufWritePost *.js :JSHint
  4. Read the [vim docs][vim] and particularly [auto commands][auto] I'm a newb and the neckbeards are probably laughing at me for even posting this.

@ryanflorence
ryanflorence / gerrit
Created October 19, 2011 17:34
Open gerrit commit
#!/bin/bash
open "https://gerrit.instructure.com/#q,$(git log --grep='^Change-Id: ' -1|\
grep 'Change-Id: '|head -n 1|sed 's/Change-Id://'|sed 's/ //g'),n,z"
@ryanflorence
ryanflorence / pubsub.js
Created October 14, 2011 22:47
Simple Pub/Sub
!function () {
var channels = {};
this.subscribe = function (channel, subscription) {
if (!channels[channel]) channels[channel] = [];
channels[channel].push(subscription);
};
this.publish = function (channel) {
if (!channels[channel]) return;
@ryanflorence
ryanflorence / universal-module.js
Created September 6, 2011 18:10
Universal JavaScript Module, supports AMD (RequireJS), Node.js, and the browser.
(function (name, definition){
if (typeof define === 'function'){ // AMD
define(definition);
} else if (typeof module !== 'undefined' && module.exports) { // Node.js
module.exports = definition();
} else { // Browser
var theModule = definition(), global = this, old = global[name];
theModule.noConflict = function () {
global[name] = old;
return theModule;
@mocheng
mocheng / algorithm.php
Created February 17, 2011 06:44 — forked from ryanflorence/algorithm.php
Solution and forked from https://gist.github.com/830201
<?php
$arr = array(
'Color' => array('Red', 'Blue'),
'Size' => array('Regular', 'Large'),
'Material' => array('Metalic', 'Nylon')
);
function magic_algorithm($arr){
function cartesian_product($arrays) {
@ryanflorence
ryanflorence / natives.js
Created January 15, 2011 06:09
Experimental extending of native objects without touching prototypes
;(function(){
function typeOf(item){
if (item._family) return item._family();
return typeof item;
}
Array.prototype._family = function(){ return 'array'; };
var _ = this._ = function(obj){
@ryanflorence
ryanflorence / static_server.js
Last active March 13, 2024 08:05
Node.JS static file web server. Put it in your path to fire up servers in any directory, takes an optional port argument.
var http = require("http"),
url = require("url"),
path = require("path"),
fs = require("fs")
port = process.argv[2] || 8888;
http.createServer(function(request, response) {
var uri = url.parse(request.url).pathname
, filename = path.join(process.cwd(), uri);