Skip to content

Instantly share code, notes, and snippets.

@rociiu
rociiu / resume.rb
Created February 21, 2011 23:32 — forked from bnadlerjr/resume.rb
require "erb"
require "ostruct"
require "optparse"
options = {}
OptionParser.new do |opts|
opts.banner = <<-DESC
Usage:
ruby resume.rb [options]
<!-- layout file -->
<% if current_user %>
Welcome <%= current_user.username %>. Not you? <%= link_to "Log out", logout_path %>
<% else %>
<%= link_to "Sign up", signup_path %> or <%= link_to "log in", login_path %>.
<% end %>
for i in {0..99}; do
wget `printf "http://downloads.cloudmade.com/north_america/north_america.osm.bz2.part.%02d" ${i};`
done
require 'rubygems'
require 'OSM'
require 'OSM/StreamParser'
require 'OSM/Database'
class CustomCallback < OSM::Callbacks
def node(node)
@node = node
@rociiu
rociiu / gist:758469
Created December 29, 2010 12:05 — forked from xdite/gist:758319

Rails 開發注意要點

About Ruby Syntax

  • 編輯器設定 soft tab (space=2),以 2 格空白符號做為程式內縮距離(不分語言)。
  • 函式如果只有一個參數,就不強制打()
  • 函式如果有二個以上的參數,通通都要有 ()
    • (避免發生奇怪的paser bug跟保持專案一致性)
  • 字串限定用雙引號包覆
  • 善用 "#{str1} #{str3} " 等字串改寫技巧取代不需要的字串加法。
@rociiu
rociiu / kruskals.rb
Created December 28, 2010 09:12 — forked from jamis/kruskals.rb
# --------------------------------------------------------------------
# An implementation of Kruskal's algorithm for generating mazes.
# Fairly expensive, memory-wise, as it requires memory proportional
# to the size of the entire maze, and it's not the fastest of the
# algorithms (what with all the set and edge management is has to
# do). Also, the mazes it generates tend to have a lot of very short
# dead-ends, giving the maze a kind of "spiky" look.
# --------------------------------------------------------------------
# --------------------------------------------------------------------
require 'net/http'
http = Hash.new{|h,k| h[k] = Net::HTTP.get_response(URI(k)).body }
http['http://www.google.com'] # makes a request
http['http://www.google.com'] # returns cached value
# Recursive backtracking algorithm for maze generation. Requires that
# the entire maze be stored in memory, but is quite fast, easy to
# learn and implement, and (with a few tweaks) gives fairly good mazes.
# Can also be customized in a variety of ways.
DIRS = (N, S, E, W = 1, 2, 4, 8)
DX = { E => 1, W => -1, N => 0, S => 0 }
DY = { E => 0, W => 0, N => -1, S => 1 }
OPPOSITE = { E => W, W => E, N => S, S => N }
@rociiu
rociiu / ellers.rb
Created December 24, 2010 06:12 — forked from jamis/ellers.rb
# Eller's algorithm for maze generation. Novel in that it only requires memory
# proportional to the size of a single row; this means you can generate
# "bottomless" mazes with it, that just keep going and going and going, using
# constant memory!
class State
attr_reader :width
def initialize(width, next_set=-1)
@width = width