This file contains hidden or 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
# force rails const_missing to preload these classes | |
# | |
ActionController | |
ActionController::Base | |
ActiveRecord | |
ActiveRecord::Base | |
ActionView | |
ActionView::Base | |
ActionView::Template | |
ActionView::Helpers |
This file contains hidden or 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
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 |
This file contains hidden or 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
# $ 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" |
This file contains hidden or 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/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 |
This file contains hidden or 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
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: |
This file contains hidden or 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
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!!!! |
This file contains hidden or 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
# 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" } | |
} |
This file contains hidden or 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
#! /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 |
This file contains hidden or 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 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") |
This file contains hidden or 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 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."] |
OlderNewer