Skip to content

Instantly share code, notes, and snippets.

@chuckha
chuckha / lightsout_example.js
Created February 18, 2012 01:26
javascript string and integer addition/concatenation
// The first three are strings, the last is a number
"1" + "2" = "12";
"1" + 2 = "12";
1 + "2" = "12";
1 + 2 = 3;
// These are all numbers
"1" - 2 = -1;
"1" - "2" = -1;
1 - "2" = -1;
@chuckha
chuckha / license_generator.vim
Created April 3, 2012 19:18
License Generator for SBO projects
function! LicenseGenerator()
let date = strftime("%c")
call search("# encoding: utf-8")
return "# Created by Chuck Ha on " . date . "\n# Copyright (c) 2012 Safari Books Online, LLC. All rights reserved.\n\n"
endfun
nmap <silent> ,li "=LicenseGenerator()<CR>p
@chuckha
chuckha / license_generator.vim
Created April 4, 2012 13:15 — forked from meirish/license_generator.vim
License Generator for SBO projects
function! LicenseGenerator()
let date = strftime("%c")
if &ft == "javascript"
return "/*jslint bitwise: true, browser: true, eqeqeq: true, immed: true, newcap: true, regexp: true, nomen: false, onevar: false, undef: true, plusplus: false, white: true, indent: 2 */\n/*global confirm define interpolate gettext console */\n\n// Created by Matthew Irish (mirish@safaribooksonline.com) on " . date . "\n/*! Copyright (c) 2012 Safari Books Online, LLC. All rights reserved.*/\n\n"
endif
if &ft == "python"
return "# encoding: utf-8\n\n# Created by Chuck Ha (chuck@safaribooksonline.com) on" . date . "\n# Copyright (c) 2012 Safari Books Online, LLC. All rights reserved.\n\n"
endif
endfun
@chuckha
chuckha / base.rb
Created August 15, 2012 14:19
base role for safarilabs
name "base"
description "A base role for all safarilab nodes"
run_list(
# Add recipes or roles here
"recipe[build_essential]"
)
@chuckha
chuckha / fizzbuzz.erl
Created September 21, 2012 14:07
Erlang fizzbuzz
-module(fizzbuzz).
-export([fizzbuzz/1]).
-define(MOD_THREE, "fizz").
-define(MOD_FIVE, "buzz").
% Helper function to map fizzbuzz across a sequence of numbers
fizzbuzz(To) ->
lists:map(fun nt/1, lists:seq(1, To)).
@chuckha
chuckha / install_package.sh
Created December 4, 2012 17:07
install a python package
#!/bin/bash
rm -rf dist
rm -rf build
rm -rf *.egg-info
python setup.py install
@chuckha
chuckha / node.py
Created August 1, 2013 14:31
An empty node object for a linked list with full test coverage.
class Node(object):
"""A node to be used for a linked list"""
def __init__(self, data):
"""Create a new Node instance
>>> head = Node(4)
>>> print(head.next)
None
>>> head.data
(function(module, $) {
module.thingy = function () {};
}(window.module = window.module || {}, jQuery));
@chuckha
chuckha / main.go
Created September 26, 2013 19:47
Code for a blog post
func GenerateAllPics() {
// Set the number of processors Go can use
runtime.GOMAXPROCS(runtime.NumCPU())
// Make all the channels we need
rows := make(chan []string)
throttle := make(chan struct{}, 10)
doneChan := make(chan int)
// Start reading the CSV
go MustReadRowAtATime("data/training.csv", rows)
// Populate the throttle so that the workers can start working
@chuckha
chuckha / dec_to_dms.rb
Last active December 24, 2015 10:29
lat/lon to dms
def lat_sign(dec)
dec >= 0 ? 'N' : 'S'
end
def lon_sign(dec)
dec >= 0 ? 'E' : 'W'
end
def lat_to_dms(dec)
"#{dec_to_dms dec} #{lat_sign dec}"
end