This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'{ | |
"foo_code": 404, | |
"foo_rbody": { | |
"query": { | |
"info": { | |
"acme_no": "444444", | |
"road_runner": "123" | |
}, | |
"error": "no_lunch", | |
"message": "runner problem." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def search(house, val, houses=[]) | |
keys = house.keys | |
until keys.count == 0 | |
key = keys.pop | |
houses << house[key] if house[key].class == Hash | |
return house[key] if house[key] == val | |
end | |
return houses.empty? ? false : search(houses.pop, val, houses) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def search(hash, val, stack=[], keyring=[]) | |
stash=[] | |
keys = hash.keys | |
before = stack.length | |
until keys.length == 0 | |
key = keys.pop | |
if hash[key].class == Hash | |
keyring << key | |
stack << hash[key] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def search(hash, val, stack=[], keyring=[], stash=[]) | |
keys = hash.keys | |
puts ">" * 50 | |
puts "KEYS: #{keys}" | |
before = stack.length | |
puts "." * 20 | |
puts "BEFORE: #{before}" | |
until keys.length == 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def prepend_str_to_hash_value(hash, subhashes=[], **kwargs) | |
keys = hash.keys | |
until keys.count == 0 | |
key = keys.pop | |
hash[key] = kwargs[:str] + hash[key] if (kwargs[:keys_like] != "" && hash[key] != kwargs[:vals_unlike] && key.to_s.include?(kwargs[:keys_like].to_s) && [String, Fixnum].include?(hash[key].class)) | |
subhashes << hash[key] if hash[key].class == Hash | |
end | |
return subhashes.empty? ? true : prepend_str_to_hash_value(subhashes.pop, subhashes, **kwargs) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Associator | |
attr_reader :rails_app_dir, :associations | |
ASSOCIATION_TYPES = [ | |
"belongs_to", | |
"has_one", | |
"has_many", | |
"has_and_belongs_to_many" | |
] | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def search_dict(d, term, nests=[]): | |
def last(array): | |
return array[-1] | |
''' | |
breadth-first search a dictionary | |
''' | |
presence = None | |
nests_at_this_level = [d.get(key) for key in d.keys() if type(d.get(key)).__name__ == 'dict'] | |
lists_with_nests = [d.get(key) for key in d.keys() | |
if type(d.get(key)).__name__ == 'list' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def merge_dicts_arrs(d1, d2): | |
for k,v in d2.items(): | |
if k in d1.keys(): | |
d1[k] = d1[k] + d2[k] | |
else: | |
d1.update({k:v}) | |
return d1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
def find_venv_dependency(name): | |
if not hasattr(sys, 'real_prefix'): | |
return # venv not activated | |
venv = sys.prefix.split('/')[len(os.getcwd().split('/'))] | |
for root, dirs, files in os.walk(venv): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'formula' | |
class Vim < Formula | |
homepage 'http://www.vim.org/' | |
url 'https://vim.googlecode.com/hg/', :revision => '6c318419e331' | |
version '7.3.515' | |
def features; %w(tiny small normal big huge) end | |
def interp; %w(lua mzscheme perl python python3 tcl ruby) end |
OlderNewer