Skip to content

Instantly share code, notes, and snippets.

View ouyangzhiping's full-sized avatar

Zhiping Yang ouyangzhiping

View GitHub Profile
@ouyangzhiping
ouyangzhiping / move logic to model
Created February 25, 2012 04:45 — forked from darrenterhune/move logic to model
csv import example in model
# controller
def proc_csv
import = Import.find(params[:id])
if import.load_csv
flash[:notice] = "woo"
redirect_to some_url
else
flash[:error] = "ohoh"
end
end
@forresty
forresty / railscasts_download.rb
Created February 21, 2012 03:39
Download all railscasts videos
#!/usr/bin/env ruby
require "nokogiri"
require "open-uri"
def download(url, output_file)
exit unless system("wget -c #{url} --load-cookies=cookies.txt -O #{output_file}")
end
def download_pages
@dongyuwei
dongyuwei / gitcoder.rb
Created January 17, 2012 08:50
find the website/blog of github top coder
require 'rubygems'
require 'nokogiri'
require 'net/http'
require 'openssl'
require 'open-uri'
class Net::HTTP
alias_method :origConnect, :connect
def connect
@samqiu
samqiu / railscasts.rb
Last active August 2, 2025 18:42
Download free Railscast video
#!/usr/bin/ruby
require 'rss'
# Usage
# $ ./railscasts.rb http://railscasts.com/subscriptions/YOURRAILSCASTRSS/\/
# episodes.rss
# OR
# $ ./railscasts.rb
p 'Downloading rss index'
@azinazadi
azinazadi / rails_cheatsheet.md
Created November 17, 2011 11:21 — forked from taktran/rails_cheatsheet.md
Rails cheatsheet

An incomplete cheatsheet for rails 3. Things are added as they are required.

Active Record validations

# http://guides.rubyonrails.org/active_record_validations_callbacks.html

class SomeClass < ActiveRecord::Base

  # length
@pithyless
pithyless / gist:1208841
Created September 10, 2011 21:49
Install Python 2.7 (homebrew + pip + virtualenv) on Mac OS X Lion

Install Python

$ brew install readline sqlite gdbm
$ brew install python --universal --framework
$ python --version
Python 2.7

Symlinks...

@ouyangzhiping
ouyangzhiping / nginx.sh
Created September 6, 2011 08:47 — forked from marshluca/nginx.sh
/etc/init.d/nginx
# /etc/init.d/nginx
#! /bin/sh
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
@ouyangzhiping
ouyangzhiping / .bash_login
Created July 11, 2011 15:58
My .bash_login file with git+brew support+textmate
# PATH ------------------------------------------------------------
export PATH="/usr/local/bin:/usr/local/Cellar/ruby/1.9.2-p180/bin/:/usr/local/sbin:~/bin/:$PATH"
# Add Bash Completion ---------------------------------------------
if [ -f `brew --prefix`/etc/bash_completion ]; then
. `brew --prefix`/etc/bash_completion
fi
# Add Bash Completion support for Brew ----------------------------
source `brew --prefix`/Library/Contributions/brew_bash_completion.sh
00:58 /p/tmp> jruby bm.rb
Rehearsal ------------------------------------------------
inject(fold) 2.898000 0.000000 2.898000 ( 2.821000)
Hash+map 2.412000 0.000000 2.412000 ( 2.412000)
--------------------------------------- total: 5.310000sec
user system total real
inject(fold) 2.477000 0.000000 2.477000 ( 2.477000)
Hash+map 2.292000 0.000000 2.292000 ( 2.292000)
<html>
<head>
<script language="javascript" type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script language="javascript" type="text/javascript" src="http://localhost/arbor/lib/arbor.js" ></script>
<script language="javascript" type="text/javascript" src="http://localhost/arbor/demos/_/graphics.js" ></script>
<script language="javascript" type="text/javascript" src="http://localhost/arbor/demos/halfviz/src/renderer.js" ></script>
</head>
<body>
<canvas id="viewport" width="800" height="600"></canvas>
<script language="javascript" type="text/javascript">