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
%w{nokogiri open-uri fileutils date}.each(&method(:require)) | |
base = 'http://apod.nasa.gov/apod/' | |
FileUtils.mv(open(base + Nokogiri::HTML(open(base)).css('img')[0].attributes['src'].value), "apod-#{Date.today.strftime('%Y-%m-%d')}.jpg") |
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 LazyMock | |
def method_missing(*args) | |
LazyMock.new | |
end | |
def respond_to?(*args) | |
true | |
end | |
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
#!/bin/bash | |
if [ ! -z `git diff --name-only HEAD@{1}..HEAD Gemfile` ] | |
then | |
echo -e "\033[0;31m*** Gemfile change detected, running bundle install ***\033[0m" | |
bundle install | |
fi |
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 toggler(object): | |
def __init__(self, getter, setter): | |
self.getter = getter | |
self.setter = setter | |
def __enter__(self, *args, **kwargs): | |
self.setter(not self.getter()) | |
__exit__ = __enter__ |
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
#!/bin/bash | |
echo -e "======================================================================================\n" | |
echo " >>> Running pre-commit hook..." | |
dirs=`git-config --get tests.directories` | |
if [ -z "$dirs" ] | |
then | |
echo -e " >>> You have no tests.directories setting. Tests will not be run.\n >>> To enable tests on pre-commit run:\n\tgit config --add tests.directories <space separated list of test dirs>\n" | |
echo -e "======================================================================================\n" |
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 union(parent,child): | |
"""Performs a union by attaching the root node of the smaller set to the | |
root node of the larger set""" | |
if parent.set_size < child.set_size: | |
child, parent = parent, child | |
parent_head = find(parent) | |
child_head = find(child) | |
if parent_head == child_head: |
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 current_host(request): | |
url = 'http://%s' % request.META['SERVER_NAME'] | |
if request.META['SERVER_PORT'] != 80: | |
url = url + ':%s' % request.META['SERVER_PORT'] | |
return url |
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 deref_list(db, list): | |
return map(lambda(ref): db.dereference(ref), list) |