Skip to content

Instantly share code, notes, and snippets.

@nhunzaker
nhunzaker / init.el
Last active December 10, 2015 19:18
Export .zshrc paths into Emacs
;; Load .zshrc (of course I am very interested in a better method)
(let ((path (shell-command-to-string ". ~/.zshrc; echo -n $PATH")))
(setenv "PATH" path)
(setq exec-path
(append
(split-string-and-unquote path ":")
exec-path)))
@nhunzaker
nhunzaker / match.js
Created October 28, 2012 18:04
Fun with .match
var fs = require('fs');
var assert = require("assert");
// Example 1 ----------------------------------------- //
var myDomain = "www.nhunzaker.com/this_article";
assert( myDomain.match("nhunzaker.com") );
@nhunzaker
nhunzaker / viewport.js
Created October 23, 2012 19:29
Viewports in Phantom.js
// Viewport
//
// phantom.js viewport.js http://google.com 400
var args = require("system").args;
var url = args[1];
var width = args[2];
var height = args[3];
@nhunzaker
nhunzaker / reporter.js
Created October 18, 2012 14:49
A simple PhantomJS v1.6+ Mocha Reporter
(function() {
var color = Mocha.reporters.Base.color;
function log() {
var args = Array.apply(null, arguments);
if (window.callPhantom) {
window.callPhantom({ message: args.join(" ") });
@nhunzaker
nhunzaker / set_grid.js
Created October 5, 2012 14:43
Set grid items
function set_grid ($items) {
$items.removeClass("omega").each(function() {
var slot = $(this).index() + 1;
if ( slot % 3 === 0) {
$(this).addClass("omega");
}
@nhunzaker
nhunzaker / persons.c
Created September 18, 2012 13:42
Explorations in C
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
// A simple struct, we'll use "PersonStruct"
// for clarity
struct PersonStruct
{
char *name;
int age;
@nhunzaker
nhunzaker / Gemfile
Created September 4, 2012 18:10
Blueprint on Rails
source 'https://rubygems.org'
gem 'rails', '3.2.8'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sqlite3'
@nhunzaker
nhunzaker / gist:3515363
Created August 29, 2012 16:37
How to change Underscore templateSettings using Ender
// Ender stores underscore under "_". So we do....
$._.templateSettings = {
interpolate: /\<\@\=(.+?)\@\>/gim,
evaluate: /\<\@(.+?)\@\>/gim
};
@nhunzaker
nhunzaker / animationLoop
Created August 27, 2012 00:07
JS: requestAnimationFrame Loop Pattern
/*
TIME BASED ANIMATION:
---------------------
To keep things moving at a constant time-based rate instead of varying
frame-based, multiply your movement by APP.deltaTime
BAD: 100 pixels per frame (BOO... movement is tied to framerate)
var velocity = 100;
BETTER: 100 pixels per second (Horray! Framerate independence!)
var preCanvas = document.createElement("canvas"),
preContext = preCanvas.getContext("2d");
preContext.fillRect(0,0,150,150);
preContext.save()
var canvas = document.getElementById("otherCanvas"),
context = canvas.getContext('2d')
context.drawImage(preCanvas, 0, 0);