File.open("/usr/local/widgets/data").each do |line|
puts line if line =~ /blue/
end
logfile = File.new("/tmp/log", "w")
logfile.close
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
error = catch(:error) do | |
throw :error, "params uuid required" if uuid.blank? | |
throw :error, "params lang required" unless params.include?("lang") | |
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
File.expand_path(File.dirname(__FILE__)) | |
# If you want to require some files in different directory, in ruby 1.9, you may want to use: | |
require_relative "../xxxlib" |
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
# Ruby build-in | |
require 'benchmark' | |
puts Benchmark.measure { "a"*1_000_000 } # and Benchmark.bm, Benchmark.bmbm | |
# handcrafted | |
def performance | |
t1 = Time.now.to_f | |
yield | |
t2 = Time.now.to_f | |
return t2 - t1 |
I posted this gist a few years ago as a quick memo for myself. I never expect this little gist to rank up in top 3 search result and getting so many helpful feedbacks. Since it gets viewed quite often, I decided to revise this post so that it may be a little more helpful. Thank you again for the feedback!
require "json"
class MyJSON
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
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | |
<meta content="" name="description"> | |
<meta content="" name="keywords"> | |
<meta content="" property="og:image"> | |
<meta content="" property="og:url"> | |
<meta content="" property="og:site_name"> | |
<meta content="" property="og:title"> | |
<meta content="" property="og:type"> |
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
config.time_zone = 'Taipei' # For ActiveRecord (Still UTC in database) | |
ENV['TZ'] = 'Asia/Taipei' # For ruby |
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
str.gsub(/<\/?[^>]*>/, "") |
OlderNewer