Skip to content

Instantly share code, notes, and snippets.

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>";
@nickjacob
nickjacob / multipleOpen.py
Created February 14, 2013 20:43
open multiple files in with statement
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)
@nickjacob
nickjacob / picotemplate.js
Last active December 11, 2015 17:58
logic-less, compiled client-side templates in 5 lines of javascript
/**
* 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) {
@nickjacob
nickjacob / api_wrapper.rb
Last active December 11, 2015 04:28
I know this has been done before, but here's my metaprogramming solution to wrapping a RESTful API.
###
# API Client for "MyApi"
###
require 'httparty'
require 'yaml'
module MyApi
class Config
attr_accessor :base_url, :page_size, :key
@nickjacob
nickjacob / switchy.js
Created November 6, 2012 07:50
Javascript is the perfect language for dispatch tables
/* 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?
@nickjacob
nickjacob / _url.js
Created November 1, 2012 16:05
url parsing "plugin" in response to this: https://github.com/websanova/js-url
/**
* 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;
@nickjacob
nickjacob / back_to_rockets.vim
Created October 22, 2012 23:40
vim regexp to convert 1.9 hash syntax to 1.8
:%s/\s\([_a-z]*\):\s/:\1 => /gi
@nickjacob
nickjacob / x86_orgasm.s
Created October 22, 2012 01:54
Orgasm on 32-bit x86 Arch
# Lusty Data
# A Computer Orgasm
# @author nickjacob
#
.excitement
movl $1, %eax
.rising
cmpl $0, %eax
je .climax
@nickjacob
nickjacob / template.js
Created September 20, 2012 01:12
Basic Javascript Template
/**
* This is my own idea of how I wish all javascript files looked. I don't think it's probably the "best" way (is there a *best* way?), but I like it
* and I think everyone should have some kind of style.
*/
// name the IIFE for debugging/organization if you want to use a concatenation build tool
;(function this_module(window,undefined){
var _public = {}, _private = {}; // if only it were real!!! Fun fact -- "public" is reserved!
@nickjacob
nickjacob / lilball.js
Created August 22, 2012 02:18
I wrote this for something else because I realized I was using jQuery just for Ajax bc I was too lazy to learn the actual DOM API for XHR.. This is Smaller.
/***
* lil' ball
* this isn't even a library. I just realized that I'd been using jQuery *only* because
* I needed an easy way to do ajax. So I finally got my sh** together an just wrote smtng.
*
* author: @nickjacob
***/
;(function(window,undefined){
window._o_ = window._o_ || {};