This file contains hidden or 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
#!/bin/bash | |
# | |
# This script will mount /Users in the boot2docker VM using NFS (instead of the | |
# default vboxsf). It's probably not a good idea to run it while there are | |
# Docker containers running in boot2docker. | |
# | |
# Usage: sudo ./boot2docker-use-nfs.sh | |
# |
This file contains hidden or 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 'rspec' | |
class BankAccount | |
attr_reader :balance | |
def initialize(initial_value = nil) | |
@balance = initial_value || 0 | |
end | |
def deposit(amount) | |
@balance += amount | |
end |
This file contains hidden or 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
# Trying to grasp fibers and EM! | |
# Using this example: http://www.slideshare.net/kbal11/ruby-19-fibers (slide 54) | |
# Fiber#resume(*params) => when first called, it passes all params as block params to | |
# Fiber.new | |
# In the next calls of resumes, *params is the return value of any Fiber.yield | |
# Fiber.yield stops execution of current fiber | |
# So, in the run-loop from EM, the fiber stops execution and gives up control |
This file contains hidden or 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
ObjectSpace.each_object(ActiveRecord::ConnectionAdapters::Transaction).map do |a| | |
[a.object_id, a.class, a] | |
end | |
ObjectSpace.each_object(ActiveRecord::ConnectionAdapters::Mysql2Adapter).map do |a| | |
[a.object_id, a.class, a] | |
end | |
ObjectSpace.each_object(ActiveRecord::ConnectionAdapters::Mysql2Adapter).map do |a| | |
[a.object_id, a.open_transactions] |
This file contains hidden or 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
-- Copyright (c) 2009, Ionut Gabriel Stan. All rights reserved. | |
-- | |
-- Redistribution and use in source and binary forms, with or without modification, | |
-- are permitted provided that the following conditions are met: | |
-- | |
-- * Redistributions of source code must retain the above copyright notice, | |
-- this list of conditions and the following disclaimer. | |
-- | |
-- * Redistributions in binary form must reproduce the above copyright notice, | |
-- this list of conditions and the following disclaimer in the documentation |
This file contains hidden or 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
hashify = ->(str, memo = []){ str =~ /\./ ? (r = str.split(/\./,2); {r[0] => hashify[r[1],memo << r[0]]}) : {str => [memo << str].join('.')} } | |
# hashify['a.b.c.d'] => | |
# {"a"=>{"b"=>{"c"=>{"d"=>"a.b.c.d"}}}} |
This file contains hidden or 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 MysqlQuery | |
def initialize | |
@query = "" | |
end | |
end |
This file contains hidden or 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
1.upto(100).each do |number| | |
if number % 3 != 0 && number % 5 != 0 | |
puts "#{number}: #{number}" | |
else | |
puts "#{number}: #{number % 3 == 0 ? 'Fizz' : '' }#{number % 5 == 0 ? 'Buzz' : ''}" | |
end | |
end |
This file contains hidden or 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
# wicked pdf | |
module WickedPdfHelper | |
def render(options = nil, *args, &block) | |
if options.is_a?(Hash) && options.has_key?(:pdf) | |
puts 'do pdf stuff' | |
end | |
super | |
end | |
end |
This file contains hidden or 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
test_string = 'Informação' | |
Encoding.aliases.values.uniq.each do |encoding| | |
begin | |
puts "In #{encoding}: #{test_string.clone.force_encoding(encoding)}" | |
rescue | |
puts "Barfed for #{encoding}" | |
end | |
end |