Skip to content

Instantly share code, notes, and snippets.

@danchoi
danchoi / barebones gmail notifier
Created January 20, 2009 03:58
A lightweight command-line Gmail notifier. Fill in your gmail username and password and run the script from the command line. It polls your gmail account and shows the latest messages in a terminal window.
require 'rubygems'
require 'net/imap'
require 'tmail'
require 'parsedate'
# NOTE: Set these values before you run the script
# Your gmail username
USERNAME = "YOUR_USERNAME"
# Your gmail password
@danchoi
danchoi / autoasciidoc
Created January 25, 2009 21:17
autoasciidoc
#!/usr/bin/env ruby
# autoasciidoc
# Author: Daniel Choi [email protected]
# License: GPLv3
#
# This program is a wrapper for asciidoc which watches the source text file for
# any changes, which automatically triggers a regeneration of the asciidoc
# output.
#
# Usage:
@danchoi
danchoi / yelp locations
Created January 28, 2009 04:09
yelp neighborhoods to yaml
#!/usr/bin/env ruby
require 'rubygems'
require 'hpricot'
require 'open-uri'
url = "http://www.yelp.com/developers/documentation/neighborhood_list"
doc = open(url) {|f| Hpricot(f.read)}
def nest(li_elem)
next_sibling = li_elem.next_sibling
if next_sibling && next_sibling.name == "ul"
#!/usr/bin/env ruby
url = ARGV.shift
puts "fetching #{url}"
target = "news.txt" # this file collects all the content
`lynx -dump -nomargins -nonumbers "#{url}" >> #{target}`
puts "done"
class Feed < ActiveRecord::Base
has_many :items, :order => "published_at desc", :dependent => :delete_all
has_many :feed_errors
# This is problematic because on update, the feed_url can be changed. It can
# be changed to the feed_url of another feed. TODO Figure out a way to
# automatically merge two feeds in this case.
# validates_uniqueness_of :feed_url
validates_presence_of :feed_url
[{"assignment":{"start_date":"2010-11-15T21:05:00Z","image_file_name":null,"created_at":"2010-11-15T21:05:42Z","title":"test title","image_file_size":null,"assignee_id":1,"updated_at":"2010-11-15T21:05:42Z","max_length":"","responses_count":0,"response_asset_validations":{},"image_content_type":null,"account_id":1,"response_asset_types":["text"],"id":11,"creator_id":4,"description":"test","image_expiring_url":null,"image_updated_at":null,"end_date":"2010-11-15T21:09:00Z","state":"open"}},{"assignment":{"start_date":"2010-11-15T18:45:00Z","image_file_name":null,"created_at":"2010-11-15T18:47:36Z","title":"","image_file_size":null,"assignee_id":1,"updated_at":"2010-11-16T18:54:01Z","max_length":"","responses_count":0,"response_asset_validations":{"audio":{"length":"60"},"text":{"length":"600"},"video":{"length":"120"},"image":{"height":"","width":""}},"image_content_type":null,"account_id":1,"response_asset_types":["audio","image"],"id":10,"creator_id":4,"description":"","image_expiring_url":null,"image_updated
@danchoi
danchoi / boston.sh
Created April 20, 2011 12:50
Weather forecast for Boston
#!/bin/bash
# Shows the weather forecast for Boston, MA
curl -s 'http://weather.noaa.gov/pub/data/forecasts/state/ma/maz007.txt' |
sed -n '/^TAB/,+11p; /BOSTON/,+3p'
@danchoi
danchoi / gist:931727
Created April 20, 2011 15:49
Monkeypatch to preserve tagging order of acts-as-taggable-on
module ActsAsTaggableOn::Taggable
module Ownership
module InstanceMethods
def save_owned_tags
tagging_contexts.each do |context|
cached_owned_tag_list_on(context).each do |owner, tag_list|
orig_tag_list = tag_list
tag_list = ActsAsTaggableOn::Tag.find_or_create_all_with_like_by_name(tag_list.uniq)
@danchoi
danchoi / rails_admin.rb
Created May 2, 2011 02:34
rails_admin patch for may bug
module RailsAdmin
class History < ActiveRecord::Base
set_table_name :rails_admin_histories
IGNORED_ATTRS = Set[:id, :created_at, :created_on, :deleted_at, :updated_at, :updated_on, :deleted_on]
scope :most_recent, lambda {|table|
where("#{retrieve_connection.quote_column_name(:table)} = ?", table).order("updated_at")
}
@danchoi
danchoi / macvol
Created August 4, 2011 02:13
macvol - set your Mac's volume from the command line
#!/bin/bash
# This simple script sets the volume on your Mac. Put it on your PATH.
#
# Usage: macvol [volume level]
#
# Without an argument, it returns the current volume level. With an argument,
# it will set the volume level. The volume level may range from 0 to 100.
#
# I use this script to set the volume of my Mac Mini remotely from another