Skip to content

Instantly share code, notes, and snippets.

@EricR
EricR / gist:5505404
Last active December 16, 2015 22:09
psych yaml vs. json
require 'benchmark'
require 'psych'
require 'json'
some_data = {:user => {:name => ["Joe", "Smith"]}, :product => {:id => 2, :name => "Whatever"}, :some_long_string => "s" * 2000, :some_long_number => 1000000000 * 100000000000}
some_yaml = some_data.to_yaml
some_json = some_data.to_json
Benchmark.bm do |b|
b.report("yaml parse") { Psych.load(some_yaml) }
package main
import "fmt"
func main() {
nums := []int{1, 3, 4, 8, 9, 12, 15, 20, 25, 31}
result := filterNumbers(nums, func(x int) bool {
return x%2 == 0
})
~/1.9.3 $ chef-client
[#<Gem::Version "11.4.2">, #<Gem::Version "0">]
[#<Gem::Version "1.1.2">, #<Gem::Version "1.1.2">]
[#<Gem::Version "1.6.0">, #<Gem::Version "1.3.0">]
[#<Gem::Version "1.3.0">, #<Gem::Version "1.3.0">]
[#<Gem::Version "1.6.0">, #<Gem::Version "0">]
[#<Gem::Version "1.1.0">, #<Gem::Version "0">]
[#<Gem::Version "6.16.0">, #<Gem::Version "0.6.0">]
[#<Gem::Version "1.1.2">, #<Gem::Version "0">]
[#<Gem::Version "1.3.0">, #<Gem::Version "0">]
@EricR
EricR / fizzbuzz.go
Last active December 15, 2015 09:39
FizzBuzz using `switch`, as per exercise of "The Way to Go".
// fizzbuzz
// A program that counts from 1 to 100, replacing numbers divisible by 3 with "Fizz",
// those divisible by 5 with "Buzz", and those divisble by both 3 and 5 with "FizzBuzz".
package main
import "fmt"
import "strconv"
func main() {
require 'optparse'
options = {}
OptionParser.new do |opts|
opts.banner = "Usage: raptor [app_directory] [options]"
end.parse!
class ProjectParser
def initialize
set_project_directory
joe = Person.new
joe.name = "Joe Smith"
joe.name # returns "Joe Smith"
return @name
fred = Person.new
fred.thing # returns "I'm a person!"
class Person
def thing
"I'm a person!"
end
end
@EricR
EricR / caesar.rb
Created November 22, 2011 03:30
Caesar Cypher in Ruby
class Caesar
def self.encrypt(shift, message)
apply_algorithm(:encrypt, shift, message)
end
def self.decrypt(shift, message)
apply_algorithm(:decrypt, shift, message)
end
private