Skip to content

Instantly share code, notes, and snippets.

@jtrim
jtrim / random_color.vim
Created February 16, 2011 15:27
Sets a random color on startup and maps :Rc to cycle random colors
function! VimRandomColor()
ruby << RUBY
colors_i_like = %w( BlackSea Jammy Lettuce Maroloccio Zmrok Baycomb Brookstream )
Vim.command("color #{colors_i_like.shuffle.pop}")
RUBY
endfunction
:command! Rc :call VimRandomColor()
:call VimRandomColor()
@jtrim
jtrim / quicksort.c
Created April 3, 2011 03:03
Implementation of quicksort in C
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#define _int uint8_t
_int *quicksort(_int *arr, int size_of_arr) {
if (size_of_arr <= 1)
return arr;
@jtrim
jtrim / quicksort.rb
Created April 3, 2011 03:04
Implementation of quicksort in ruby
def quicksort(array)
return array if array.size <= 1
less_than_pivot = []
greater_than_pivot = []
pivot_value = array.pop
array.each do |item|
less_than_pivot << item if item <= pivot_value
@jtrim
jtrim / symbolize_keys.rb
Created April 14, 2011 20:17
Methods to help turn all hash keys into symbols
class Hash
def symbolize_keys
replace( keys.inject({}) { |new_hash,key| new_hash[key.to_sym] = self[key]; new_hash } )
end
def symbolize_keys!
symbolized_hash = keys.inject({}) do |new_hash,key|
new_hash[key.to_sym] = self[key]
new_hash[key.to_sym].symbolize_keys! if new_hash[key.to_sym].respond_to? :symbolize_keys!
new_hash
@jtrim
jtrim / listcomp.erl
Created August 19, 2011 05:58
Erlang nested list comprehensions - an anagram example
-module(listcomp).
-export([perms/1]).
% generates all possible letter permutations given a string of letters
perms( [] ) -> [[]];
perms(Phrase) ->
[ [H|Rest] ||
H <- Phrase,
Rest <- perms(Phrase -- [H])].
# Gets the last gist for specified user
#
# last gist [for] <username> - Returns the last gist for specified user
module.exports = (robot) ->
robot.respond /last gist (?:for)? (.+)/i, (msg) ->
username = msg.match[1]
url = "https://api.github.com/users/#{username}/gists"
msg.http(url).get() (err, res, body) ->
gists = JSON.parse(body)
indexed = {}
def try_cached_event
unless (id = cookies[Event::IDENTITY_KEY]) && (event = Event.find_by_id(id))
cookies[Event::IDENTITY_KEY] = { expires: 1.day.ago }
return
end
redirect_to event_participants_url(event)
end
it 'creates a participant after clicking `confirm' do
load_page
click_on '10:00 am'
# Not sure why the ActiveRecord connection is becoming
# stale...probably something to do with the way capybara runs tests
# with selenium.
#
# Symptom that led to the change:
# Running this in isolation without refreshing the connection would
validClickElementCallbacks: [
(el) -> $(el)[0].tagName.match(/li/i) && $(el)[0].className.match(/day/),
(el) -> $(el)[0].tagName.match(/span/i) && $(el)[0].className.match(/remaining/),
(el) -> $(el)[0].tagName.match(/h3/i)
]
bindEvents: ->
@element.click (e) =>
return unless _.any(@validClickElementCallbacks, (fn) -> fn(e.target))
(ns bit-sandbox.core)
; helper
(defn shifted-byte [int-byte-value, shift-by]
(bit-shift-left
(bit-and int-byte-value 0xFF)
(* shift-by 8)))
; (+ meat potatoes)