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
# download, from_repo, and commit_state methods swiped from | |
# http://github.com/Sutto/rails-template/blob/07b044072f3fb0b40aea27b713ca61515250f5ec/rails_template.rb | |
require 'open-uri' | |
def download(from, to = from.split("/").last) | |
#run "curl -s -L #{from} > #{to}" | |
file to, open(from).read | |
rescue | |
puts "Can't get #{from} - Internet down?" |
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
/* | |
* CodePress regular expressions for HTML syntax highlighting | |
*/ | |
// HTML | |
Language.syntax = [ | |
{ input : /(<[^!]*?>)/g, output : '<b>$1</b>' }, // all tags | |
{ input : /(<a .*?>|<\/a>)/g, output : '<a>$1</a>' }, // links | |
{ input : /(<img .*?>)/g, output : '<big>$1</big>' }, // images | |
{ input : /(<\/?(button|textarea|form|input|select|option|label).*?>)/g, output : '<u>$1</u>' }, // forms |
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
# autotest your engine plugins together with your rails app | |
# put this .autotest file in your rails root | |
# see http://code.whatcould.com/2009/02/09/gentlemen-test-your-engines.html for details | |
# until/unless my changes are pulled into the main streams, | |
# there are a couple requirements: | |
# my autotest fork, http://github.com/whatcould/zentest/tree/master | |
# and for better fixture handling, my engines fork, http://github.com/whatcould/engines/tree/master | |
Autotest.add_hook :initialize do |at| |
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
# -------------------------------------------------- | |
require 'rubygems' | |
def run(cmd) | |
puts(cmd) | |
system(cmd) | |
end | |
def run_all_tests | |
# see Rakefile for the definition of the test:all task |
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 | |
yum install httpd-devel openssl-devel zlib-devel gcc gcc-c++ curl-devel expat-devel gettext-devel mysql-server mysql-devel curl make | |
mkdir /usr/local/src | |
cd /usr/local/src | |
curl -O ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7-p249.tar.gz | |
tar xzvf ruby-1.8.7-p249.tar.gz | |
cd ruby-1.8.7-p249 | |
./configure --enable-shared --enable-pthread | |
make |
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
require 'rubygems' | |
require 'nokogiri' | |
require 'open-uri' | |
# Get a Nokogiri::HTML:Document for the page we’re interested in... | |
doc = Nokogiri::HTML(open('http://www.facebook.com/ChickfilA?v=wall','User-Agent' => 'Mozilla/5.0 (...) Firefox/3.0.6')) | |
# Do funky things with it using Nokogiri::XML::Node methods... |
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
require 'rubygems' | |
require 'nokogiri' | |
require 'open-uri' | |
# Get a Nokogiri::HTML:Document for the page we’re interested in... | |
client = "FOOOOOOOOO" | |
doc = Nokogiri::HTML(open("http://www.facebook.com/#{client}?v=wall",'User-Agent' => 'Mozilla/5.0 (...) Firefox/3.0.6')) | |
#### |
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
!function() { | |
var doc = document, | |
htm = doc.documentElement, | |
lct = null, // last click target | |
nearest = function(elm, tag) { | |
while (elm && elm.nodeName != tag) { | |
elm = elm.parentNode; | |
} | |
return elm; | |
}; |
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 User < ActiveRecord::Base | |
named_scope :active, :conditions => {:active => true} | |
named_scope :inactive, :conditions => {:active => false} | |
named_scope :recent, lambda { { :conditions => ['created_at > ?', 1.week.ago] } } | |
end | |
# Standard usage | |
User.active # same as User.find(:all, :conditions => {:active => true}) | |
User.inactive # same as User.find(:all, :conditions => {:active => false}) | |
User.recent # same as User.find(:all, :conditions => ['created_at > ?', 1.week.ago]) |
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 tip(msg); puts; puts msg; puts "-"*100; end | |
# | |
# 30 Ruby 1.9 Tips, Tricks & Features: | |
# http://www.igvita.com/2011/02/03/new-ruby-19-features-tips-tricks/ | |
# | |
tip "Upgrading to Ruby 1.9 is simple: rvm install 1.9.2 && rvm --default 1.9.2" | |
tip "Ruby 1.9 supports named captures in regular expressions!" |
OlderNewer