This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* URL Parsing "Library"/function | |
* https://github.com/websanova/js-url <-- this is unnecessarily complex | |
*/ | |
;(function _url(window,undefined){ | |
function Url(url){ | |
this.elem = window.document.createElement('a'); | |
this.elem.href = url || window.location; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Why would you ever need a switch statement in javascript? */ | |
var switchy = { | |
1: function(x){ return x*x; }, | |
pizza: function(x){ return x*x*X } | |
}; | |
var bar = switchy[foo](10); | |
// what if you could extend it with regex? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### | |
# API Client for "MyApi" | |
### | |
require 'httparty' | |
require 'yaml' | |
module MyApi | |
class Config | |
attr_accessor :base_url, :page_size, :key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* PicoTemplate | |
* syntax (there is barely any) | |
* | |
* <a href="{{ url }}">{{ movie.title }}</a> | |
* NO LOGIC! | |
**/ | |
function __deep(obj, prop) { | |
var parts = prop.split('.'), i = -1, l = parts.length; | |
while(++i < l) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from contextlib import contextmanager | |
@contextmanager | |
def files(*ff): | |
fi = [ open(*f) if len(f) == 2 else open(f) for f in ff ] | |
yield(fi) | |
map(close,fi) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript:(function(){ | |
var body = window.document.body, | |
hh = body.scrollTop, | |
interval = null, | |
style_div = "font-family:helvetica;border-radius:5px;border:1px solid #222;border-bottom: 2px solid #111;padding:10px;position:fixed;top:20px;left:20px;background:#555", | |
style_link = "padding: 5px;background:#222;color:#eee;text-decoration:none;margin:5px;", | |
tpl = "<div id='stoppy' style='" + style_div + "'><a style='" + style_link + "' href='#' id='start-btn'>start</a> \ | |
<a style='" + style_link + "' href='#' id='stop-btn'>stop</a>"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inputRe = /input|select|textarea/i # some browsers do uppercase tagNames; also faster than 3 strcmp | |
cache = {} | |
elByName = (el) -> | |
cache[el.name] ?= document.getElementsByName el.name | |
document.addEventListener 'load', (e) -> | |
document.addEventListener 'change', (e) -> | |
target = e.target | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__deep = (obj, prop) -> | |
for p in prop.split '.' | |
if not (p in obj and obj = obj[p]) | |
return undefined | |
obj() if typeof obj is 'function' else obj | |
getEscape = (tpl) -> | |
qq = "\'" if '"' in tpl else "\"" | |
(str) -> qq + str + qq | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Script Template | |
# @author nickjacob | |
require 'pp' | |
def print_json json | |
pp json | |
end | |
def perform argv | |
while line = gets.chomp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// inefficient because you call append multiple times | |
// this causes a reflow on each call (https://developer.mozilla.org/en-US/docs/Notes_on_HTML_Reflow) | |
$('#my-el').append('<div>hi</div>').append('<div>two</div>').append('<div>three</div>'); | |
// you could just make 1 string of HTML | |
var to_append = '<div>hi</div><div>two</div><div>three</div>'; | |
$('#my-el').append(to_append); | |
// or you can use documentFragment; | |
// documentFragment is a container for DOM elements that, when you eventually attach it to the DOM, disappears so |