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
### Spawn a long run process in Sinatra ### | |
require 'sinatra' | |
get '/process' do | |
child_pid = Process.fork do # spawn a long run process | |
tryCitus.setup(config) | |
Process.exit | |
end | |
Process.detach child_pid | |
############################## |
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
# Timestamp | |
puts Time.now | |
puts Time.now.to_s | |
puts Time.now.to_i | |
puts Time.now.to_i.to_s |
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
# Replace a pattern | |
bootstrap = "ID = USER_ID" | |
id = 12345.to_s | |
new_bootstrap = bootstrap.gsub('USER_ID', id) # return a new string | |
bootstrap.gsub!('USER_ID', id) # replace in place |
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
# Reading whole file | |
bootstrap = File.read('config/bootstrap') | |
# Relative path. | |
# web_app/ | |
# app.rb | |
# db/sample.db | |
# In the app.rb | |
"#{File.expand_path(File.dirname(__FILE__))}/db/sample.db" |
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.rb | |
require 'yaml' | |
config = YAML.load_file('config/config.yml') | |
puts config['user_data'] | |
# config.yml | |
user_data: 'hello world' |
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
# Split a file into parts | |
$ split --bytes=SIZE input_file | |
# Join files together | |
$ cat file_part.* > output_file |
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
# default value | |
PHRASE_FIRST = ARGV[0] == "english" | |
open(aFile) {|f| | |
f.each_line {|word| words.push(word.chomp)} | |
} | |
def craft_names(rand_words, snippet, pattern, caps=false) |
NewerOlder