Skip to content

Instantly share code, notes, and snippets.

cloudips-create.rb
6: c.flag [:i, "count"]
9: c.flag [:n, :name]
12: c.flag [:t, :'port-translators']
cloudips-update.rb
6: c.flag [:r, "reverse-dns"]
12: c.flag [:n, :name]
15: c.flag [:t, :'port-translators']
loop do
begin
puts "Whoa"
sleep(2)
rescue Exception => e
puts "wtf"
end
end
@gnufied
gnufied / after_commit_patch.rb
Created July 30, 2012 08:07
after_commit_patch.rb
#WARNING do not load this file in environments other than test
module AfterCommitPatch
def transaction(options = {})
rolled_back = false
return_value = nil
begin
return_value = super
rescue ActiveRecord::Rollback => e
puts e.message
puts e.backtrace
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
#!/usr/bin/env bash
apt-add-repository -y ppa:brightbox/ruby-ng
apt-get -y update
apt-get -y install build-essential
apt-get -y install zlib1g-dev libssl-dev libreadline-gplv2-dev libyaml-dev
apt-get -y install ruby1.9.3 ruby-switch
ruby-switch --set ruby1.9.1
gem install chef ruby-shadow --no-ri --no-rdoc
class User < ActiveRecord::Base
attr_accessible :email, :first_name, :last_name, :username
before_validation :lol, :on => :create
before_validation :yay, :on => :create
before_validation :yay, :on => :update
def lol
puts "Running lol"
end
class Leaky
def wow
locations = [1,2,3]
locs = Hash.new(0)
locations.each do |x|
number = 10
p number
end
p number
end
#!c:\ruby\bin\rubyw.exe
require 'mpgapi4r.rb' #path to mpgapi4r.rb
p = ReqMod::Purchase.new
p.order_id = "prodtest2"
p.cust_id = "test"
p.amount = "0.00"
p.crypt_type = "7"
p.pan = "4514011602554956"
@gnufied
gnufied / chain_should_receive.rb
Created May 28, 2012 09:16
How to chain method expectations in rspec-2
class Object
def should_chain_receive(*args,&block)
if block_given?
ChainReceive.new(self,args,block)
else
ChainReceive.new(self,args)
end
end
end
class Object
def should_chain_receive(*args,&block)
current_object = self
args[0..-2].each do |argument|
temp = Object.new()
current_object.should_receive(argument).and_return(temp)
current_object = temp
end
result = yield
current_object.should_receive(args.last).and_return result