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
# For multi-line blocks, use do. E.g.: | |
users.each do |user| | |
user.name = "foo" | |
user.save | |
end | |
# For single-line blocks, use {} | |
users.each {|user| user.destroy } |
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
class Matrix | |
IndexOverflow = Class.new(StandardError) | |
attr_reader :dims, :nrows, :ncols | |
def initialize(mm, nn) | |
@dims = [mm, nn] | |
@nrows = mm | |
@ncols = nn |
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' | |
require 'sinatra/base' | |
require 'eventmachine' | |
require 'logger' | |
$logger = Logger.new(File.join(File.dirname(__FILE__), "development.log")) | |
module TestEM | |
def self.start | |
if defined?(PhusionPassenger) |
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
(`·. )\ )`·. )`·. | |
) `·. .·´( .·´ ( (`·. )`·._.·´( )`·. /( .·´ ( /( .·´ ( | |
.·´( .·´:..::(,(::-- ' '\:·´ \::`·._)`·. )\.·´::... .::) .·´ ./ )\ ) `·._):::. ) )\ ) `·._):::. ) | |
);; :-- ' ' _\ .·´( )::. ..:::).·´;· -- ´ ´\::.`·.(::...:(' )\ .·´ .:`·.(:;; -- ' '\:. :(.·´) )\ )\ .·´ .:`·.(:;; -- ' '\:. :(.·´) )\ | |
.·´/\ ,..:´:::'/ ):..\(;;::-- ´ ´ '\:::::::...::) .·´ (,): -- ' ' \....:::`·.( ( .·´ (,): -- ' ' \....:::`·.( ( | |
)/:::'\...:/I I::::::::/ '(::...:/\ |
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
begin | |
raise "THIS IS WEIRD?" | |
rescue ex | |
puts "EX = #{ex.message}" | |
end | |
# => undefined local variable or method `ex' for main:Object (NameError) |
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
#!/usr/bin/ruby | |
binwidth = ARGV[0].to_f | |
filename = ARGV[1] | |
rand_file_name = "rand_file-#{(rand*1000000).to_i}.data" | |
nums = File.open(filename, "r") {|f| f.readlines}.collect {|n| n.to_f } | |
binned_data = {} | |
nums.each do |n| |
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' | |
require 'redis' | |
require 'redis/distributed' | |
redis = Redis::Distributed.new(['redis://localhost:6379', 'redis://localhost:6380']) | |
(1..10_000).each do |i| | |
key = "rand_#{rand}" | |
val = rand(1000) |
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
[false, true].each do |reseed_rand| | |
puts "*" * 100 | |
puts "Force reseed of the random number generator? #{reseed_rand}" | |
2.times { | |
fork { | |
srand if reseed_rand | |
puts sprintf(" Process ID: %5d, child of %5d: 3 Randoms: %.5f, %.5f, %.5f", Process.pid, Process.ppid, rand, rand, rand) | |
} | |
} |
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
--------------- objects --------------- ------ pages ------ ----- memory ----- | |
load-in swap-out swapped delta used delta used delta | |
28 0 3742556 -43 10977293 -117 3.45G +101.54K | |
28 0 3742517 -39 10977207 -86 3.45G +56.30K | |
37 0 3742473 -44 10977107 -100 3.45G +65.12K | |
29 0 3742433 -40 10976982 -125 3.45G +116.73K | |
31 0 3742391 -42 10976850 -132 3.45G +78.88K | |
30 0 3742351 -40 10976779 -71 3.45G +50.25K | |
29 0 3742315 -36 10976673 -106 3.45G +426.68K | |
30 0 3742271 -44 10976552 -121 3.45G +183.50K |
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
daemonize yes | |
pidfile /var/run/redis.pid | |
port 6379 | |
timeout 30 | |
loglevel notice | |
logfile /var/log/redis/redis-server.log | |
databases 16 | |
################################ SNAPSHOTTING ################################# | |
save 300 1000 |