Skip to content

Instantly share code, notes, and snippets.

View hrstt's full-sized avatar

sato hiroyuki hrstt

View GitHub Profile
@hrstt
hrstt / .irbrc
Created June 29, 2011 02:09
.irbrc
require 'rubygems' rescue nil
require 'wirble'
require 'hirb'
require 'ap'
# load wirble
Wirble.init
Wirble.colorize
# load hirb
some_array.sort_by {|elem|
[elem[:attribute_a], elem[:attribute_b]]
end
@hrstt
hrstt / ItemList.rb
Created June 25, 2011 13:41
For Nanoc, Select specific kind items.
module ItemList
# select specific kind items
# select items by "kind" which is one of item attributes.
# result list sort by created_at
def sorted_list(kind)
@items.select {|i|
i[:kind] == kind
}.sort_by {|a|
if a[:created_at].class == Time then
a[:created_at]
@hrstt
hrstt / facebook_escape.rb
Created June 25, 2011 13:40
escape url strings for facebook api spesification.
# escape url strings for facebook api spesification.
def facebook_escape(url)
url.gsub('/', '%2F').gsub(':','%3A')
end
@hrstt
hrstt / newline_to_br.br
Created June 25, 2011 13:36
exchange line break to <br /> tag
# line break exchange to <br />
def newline_to_br(text)
text = html_escape(text.to_s)
text.gsub!(/\r\n?/, "\n")
text.gsub!(/\n\n+/, "\n")
text.gsub!(/([^\n]\n)(?=[^\n])/, '\1<br />')
end
@hrstt
hrstt / csv_to_table.rb
Created June 25, 2011 13:33
For Nanoc, csv data to html table (simple table)
module CSVUtile
## parse csv data to table tag
def csv_to_table(file_name, header = false)
csv = CSV.readlines("data/#{file_name}.csv")
table = ""
table << parse_thead(csv.shift) if header
table << parse_tbody(csv)
end