Skip to content

Instantly share code, notes, and snippets.

View davelyon's full-sized avatar

Dave Lyon davelyon

View GitHub Profile
# Base class for an Item
class LibraryItem
# Type is a depricated method, undefining it will be safe
undef_method :type
# Dynamically generates Getters/Setters for class
# get_set :name, ConstClass
def self.get_set(name, klass)
define_method(name) {
instance_variable_get("@#{name}").value
# recursively compare the keys of these hashes, making sure that two has the same keys as one
one = {:id => 1, :items => [{:name => 'one'}, {:name => 'one:one'}]}
two = {:id => 2, :items => [{:name => 'two'}, {:name => 'two:two'}]}
def check_keys(hash1, hash2)
hash1.each_key do |key|
if hash1[key].is_a? Array
return hash1[key].each_index {|sub| check_keys(hash1[key][sub], hash2[key][sub])} if hash1[key].is_a? Hash
elsif hash1[key].is_a? Hash
return check_keys(hash1[key], hash2[key])
#banal.rb
def banal(ary)
b = c = ary
unless ary.size <= 2
b = banal(ary[0..(ary.size/2)-1])
c = banal(ary[(ary.size/2)..-1])
else
if b[0] == c[0]
require 'test/unit'
class Piece
def self.beats(type)
self.instance_eval do
define_method "beats_#{type}?".intern do
true
end
end
end
"""
MIT License
----------------------------------------------------------------
Copyright (c) 2009 David Lyon
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
BinaryNode* BinaryNode::remove(char *n) {
int test = strcmp(n,name);
BinaryNode *temp;
if(test > 0) { //Name we're deleting is bigger
if(right != NULL){
right = right->remove(n);
return this;
}
}
alias gs='git status'
alias ga='git add'
alias gc='git commit -m'
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "⚡"
}
function parse_git_branch {