Skip to content

Instantly share code, notes, and snippets.

View benatkin's full-sized avatar

Benjamin Atkin benatkin

View GitHub Profile
How I installed and ran node.js on Ubuntu Karmic Koala Desktop 64-bit:
1. $ sudo aptitude install scons
2. $ sudo aptitude install build-essential
3. Downloaded the node.js tarball from here (also tried the git repo - both worked!)
http://nodejs.org/#download
4. untar'ed it
5. changed to the directory
6. $ ./configure --prefix=/usr/local
7. $ make
-b, --ignore-space-change
Ignore changes in amount of whitespace. This ignores whitespace at
line end, and considers all other sequences of one or more
whitespace characters to be equivalent.
# Returns the different values of a field in a django model.
# Because I didn't want to check the docs and needed a way that didn't retrieve lots of records from the database.
# It was fun to code and uses a couple of Python tricks.
def field_values(cls, field):
values = []
exclude_args = {field + '__in': values}
while True:
try:
obj = cls.objects.exclude(**exclude_args)[0]
values.append(getattr(obj, field))
#!/usr/bin/env ruby -rubygems
# frenzy - a script for adding/removing /etc/hosts site-blocking entries
require 'main'
require 'yaml'
SITES_TEMPLATE = <<EOF.strip
blocked_sites:
- *.reddit.com
- www.reddit.com
require 'rubygems'
require 'appscript'
puts Appscript.app('Finder').desktop.window.bounds.get()[2..-1].join('x') # prints 1440x900
(setq kitfiles-dir "~/github/walter/aquamacs-emacs-starter-kit")
(add-to-list 'load-path kitfiles-dir)
(require 'init)
// This makes a call to an API, through JSON. In a single place I could change the url design, whether it's https or not, the authentication method, the serialization format, and more. Additionally, since initialization and sending happen outside of this method, the request can be touched up before or after sending it.
- (void) prepareRequest:(ASIHTTPRequest *)request withController:(NSString *)controller andAction:(NSString *)action andParams:(NSDictionary *)params;
defaults write com.apple.dock persistent-apps -array-add '{tile-data={}; tile-type="spacer-tile";}'
defaults write com.apple.dock persistent-apps -array-add '{tile-data={}; tile-type="spacer-tile";}'
defaults write com.apple.dock persistent-apps -array-add '{tile-data={}; tile-type="spacer-tile";}'
defaults write com.apple.dock persistent-apps -array-add '{tile-data={}; tile-type="spacer-tile";}'
defaults write com.apple.dock persistent-apps -array-add '{tile-data={}; tile-type="spacer-tile";}'
defaults write com.apple.dock persistent-apps -array-add '{tile-data={}; tile-type="spacer-tile";}'
defaults write com.apple.dock persistent-apps -array-add '{tile-data={}; tile-type="spacer-tile";}'
defaults write com.apple.dock persistent-apps -array-add '{tile-data={}; tile-type="spacer-tile";}'
defaults write com.apple.dock persistent-apps -array-add '{tile-data={}; tile-type="spacer-tile";}'
defaults write com.apple.dock persistent-apps -array-add '{tile-data={}; tile-type="spacer-tile";}'
# I noticed that github's 404 page splits words, for example http://github.com/bitternessflavoraroma
# I wondered how I might do it myself. This is slow, but it works with my simple example on my machine.
$words = File.new('/usr/share/dict/words').readlines.map { |s| s.strip }.reject { |s| s.length < 2 }
$answers = []
def split_words(str, words=[])
$answers << words if str == ''
$words.each do |word|
split_words(str.sub(word, ''), words.clone << word) if str.start_with?(word)
end