Skip to content

Instantly share code, notes, and snippets.

@bmulvihill
bmulvihill / serializeObject.coffee
Created February 6, 2014 19:35
CoffeeScript to add serializeObject to JQuery, converts HTML form to JSON, modified from http://jsfiddle.net/davidhong/gP9bh/
$.fn.serializeObject = ->
o = Object.create(null)
elementMapper = (element) ->
element.name = $.camelCase(element.name)
return element
appendToResult = (i, element) ->
node = o[element.name]
if ('undefined' != typeof node && node != null)
o[element.name] = if node.push then node.push(element.value) else [node, element.value]
else
@bmulvihill
bmulvihill / dls.rb
Created August 30, 2014 22:03
Algorithm Design Manual 6-22
#!/usr/bin/env ruby
# Depth Limited Search
# Find the minimum cost/path on a graph given a start node, end node and set distance to travel
graph = {'A'=>[['B',6], ['C',1], ['E',2]],
'B'=> [['A',6], ['D',2], ['F',4]],
'C'=> [['A',1], ['G',3], ['E',2]],
'D'=> [['B',2]],
'E'=> [['A',2],['F',4], ['C',2]],
'F'=> [['B',1], ['E',4]],

Keybase proof

I hereby claim:

  • I am bmulvihill on github.
  • I am mangohabanero (https://keybase.io/mangohabanero) on keybase.
  • I have a public key whose fingerprint is 27C6 1202 F986 6E95 2A8B 383D 04C8 ED8C 2524 5398

To claim this, I am signing this object:

@bmulvihill
bmulvihill / cacheable.rb
Created February 10, 2016 19:33
cached methods
module Cacheable
def store
Rails.cache
end
def cache(*attributes)
attributes.each do |attribute|
if attribute.is_a?(Hash)
wrap(attribute.keys.first, attribute[attribute.keys.first])
@bmulvihill
bmulvihill / linked_list.c
Last active March 18, 2016 13:45
Practicing Ruby C Extension - Linked List using Memory Pool
#include "ruby.h"
static VALUE cLinkedList;
typedef struct rb_node {
VALUE data;
struct rb_node *next;
} Node;
typedef struct rb_linked_list {