Skip to content

Instantly share code, notes, and snippets.

View michaeldv's full-sized avatar

Michael Dvorkin michaeldv

  • Cupertino, California
View GitHub Profile
# force rails const_missing to preload these classes
#
ActionController
ActionController::Base
ActiveRecord
ActiveRecord::Base
ActionView
ActionView::Base
ActionView::Template
ActionView::Helpers
@michaeldv
michaeldv / FIRST
Created May 27, 2009 04:10 — forked from nakajima/FIRST
Here's an example of a few different ways to call a method on a Ruby object.
If you're a beginner, try running the code above to watch it in action.
If you're not a beginner, go ahead and tear me a new one for whichever techniques I forgot ;)
- Pat
# $ tweet Hi mom!
#
# Put this in ~/.bashrc or wherever.
# If it doesn't work, make sure your ~/.netrc is right
#
# (Thanks to @anildigital for curl-fu)
function tweet {
curl -n -d status="$*" http://twitter.com/statuses/update.xml &> /dev/null
echo "tweet'd"
#!/bin/sh
## install imagemagick on snow leopard: by kain, improved by mislav
## http://www.icoretech.org/2009/08/install-imagemagick-in-leopard-snow-leopard/
# working on 64bit kernel mode
set -e
PREFIX=/usr/local
wget http://sourceforge.net/projects/freetype/files/freetype2/2.3.9/freetype-2.3.9.tar.gz/download -O- | tar xz
@michaeldv
michaeldv / gist:180578
Created September 3, 2009 22:24 — forked from mtodd/gist:180398
Surround a heredoc with quotes and you can continue the code on the same line:
render :status => 404, :text => <<-'EOH' and return unless setup
article not found<br/>
I, as a server, have failed<br/>
https?
EOH
Quotes also give you more freedom/creativity with the terminal ID:
1. Create a text backup of your data form the live server. This will ask for a password.
mysqldump -u your_user -p your_redmine_database > backup_sql_file.sql
2. Transfer the backup_sql_file.sql to your new server.
3. Once there, drop the existing database on the new server and import your database to the empty database on the new server.
!!!! Triple check this is on the new server and not your live one!!!!
@michaeldv
michaeldv / gist:188101
Created September 16, 2009 15:24 — forked from pccl/gist:187933
# Tasks can fall through the gaps when matching on '='
# e.g. for a task where due_at = 2009-09-16 23:00:00, and where Time.now = 2009-09-16,
# it would not match due_today or due_tomorrow, hence would not appear in Fat Free.
named_scope :due_today, lambda { { :conditions => [ "due_at = ?", Time.zone.now.midnight.utc ], :order => "id DESC" } }
named_scope :due_tomorrow, lambda { { :conditions => [ "due_at = ?", Time.zone.now.midnight.tomorrow.utc ], :order => "id DESC" } }
# By specifying a range of dates, tasks would always match with one of the bucket dates.
named_scope :due_today, lambda {
{ :conditions => [ "due_at >= ? AND due_at < ?", Time.zone.now.midnight.utc, Time.zone.now.midnight.tomorrow.utc ], :order => "id DESC" }
}
#! /usr/bin/env ruby
Main {
Home = File.expand_path(ENV["HOME"] || ENV["USERPROFILE"] || "~")
Basedir = File.join(Home, "mp3")
Threads = 8
description <<-txt
mp3scrape will scour any url for it's mp3 content - the script mirrors,
never downloading the same file twice. it does not, however, crawl a
class GitProductive
attr_accessor :directory, :lines, :commits
def initialize(directory = Dir.pwd)
raise "#{directory} is not a git repository" unless Dir.entries(directory).include?(".git")
@directory = directory
@lines, @commits = 0, 0
end
def check!(duration = "1 days")
@michaeldv
michaeldv / snippet.rb
Created February 17, 2010 07:44 — forked from auser/snippet.rb
def mode(arr=[])
hsh = arr.inject(Hash.new(1)) { |hash, item| hash[item] += 1; hash }
max = hsh.values.max
hsh.inject([]) { |arr, item| arr << item[0] if item[1] >= max; arr}
end
p mode %w(a b a a b c dd e e e) # ["e", "a"]
p mode %w(a b a a b c dd e e) # ["a"]
p mode %w(snowboarding is more than fun. super fun.) # ["fun."]