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
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 |
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
# 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 |
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
# escape url strings for facebook api spesification. | |
def facebook_escape(url) | |
url.gsub('/', '%2F').gsub(':','%3A') | |
end |
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
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] |
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
some_array.sort_by {|elem| | |
[elem[:attribute_a], elem[:attribute_b]] | |
end |
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' rescue nil | |
require 'wirble' | |
require 'hirb' | |
require 'ap' | |
# load wirble | |
Wirble.init | |
Wirble.colorize | |
# load hirb |
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
x = { "one" => "one", "two" => "two", "three" => "three"} | |
y = x.reject {|key,value| key == "three" } | |
y == { "one" => "one", "two" => "two"} |
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
a = [1,2,3,4,5,6,4,5] | |
a.inject(Hash.new 0) {|h,v| h[v]+= 1;h}.select {|h,v| v >= 2}.keys #=> [4,5] |
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
==> Cloning https://github.com/stevedekorte/io.git | |
Updating /Users/hsato/Library/Caches/Homebrew/io--git | |
git remote set-url origin https://github.com/stevedekorte/io.git | |
git fetch origin | |
git reset --hard | |
HEAD is now at c83f98e Merge pull request #129 from jcowgar/master | |
git checkout-index -a -f --prefix=/private/tmp/homebrew-io-HEAD-VDm0/ | |
==> Downloading patches | |
==> Patching | |
/usr/bin/patch -f -p1 -i 001-homebrew.diff |
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
hash = Hash.new{|h,k| h[k] = []} | |
hash[:test] << "Hello" #=> {:test => ["Hello"]} |
OlderNewer