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) |
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
# 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
# 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
# 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
# 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
### 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
# Note: | |
# RVM does not control the system Ruby or its gems. Only Rubies and gems installed by RVM are under it's control! | |
# Install RVM | |
$ gpg --keyserver hkp://keys.gnupg.net --recv-keys D39DC0E3 | |
$ \curl -sSL https://get.rvm.io | bash -s stable --ruby | |
$ source /home/ubuntu/.rvm/scripts/rvm | |
# Install a Ruby version | |
$ rvm install ruby-1.9.3 |
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
# Get path of directory in which the script is stored | |
DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd ) | |
echo $DIR | |
# Use content of a file as argument | |
kill -9 $(<./thin.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
// Logging | |
import ( | |
"log" | |
"time" | |
) | |
func response(rw http.ResponseWriter, r *http.Request) { | |
rw.Write([]byte("Hello world!")) | |
log.Printf(time.Now().String(), r.Method, r.URL.String()) | |
} |
OlderNewer