Skip to content

Instantly share code, notes, and snippets.

View kenmazaika's full-sized avatar

ken mazaika kenmazaika

View GitHub Profile
@kenmazaika
kenmazaika / pass_binding_variable.rb
Created April 5, 2012 16:07
passing variable from current binding to sub binding
1.9.3p0 :128 > b.eval('var_context = nil; lambda {|a| var_context = a }').call("OMGOMG")
=> "OMGOMG"
1.9.3p0 :129 > var_context
NameError: undefined local variable or method `var_context' for main:Object
from (irb):129
from /Users/kmazaika/.rvm/rubies/ruby-1.9.3-p0/bin/irb:16:in `<main>'
1.9.3p0 :130 > b.eval('var_context')
=> "OMGOMG"

All About ActiveSupport Notifications rollout gem -

  • conditionally only add new stuff to devs

  • debugging that is not useful to generic customers can apply to.

  • logsubscriber, can use for event notificaions that you care about.

  • log rage gem. combined logging. detaches existing log subscribers are attaches new ones.

  • harness.

  • search rails code for instrument method.

case class c() extends Mockito {
val m = mock[akka.http.Get]
}
@kenmazaika
kenmazaika / connection.rb
Created May 10, 2012 17:47
connection.rb
class ActiveResource::Connection
# Creates new Net::HTTP instance for communication with
# remote service and resources.
def http
http = Net::HTTP.new(@site.host, @site.port)
http.use_ssl = @site.is_a?(URI::HTTPS)
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
http.read_timeout = @timeout if @timeout
#Here's the addition that allows you to see the output
@kenmazaika
kenmazaika / gist:3124697
Created July 16, 2012 20:03
monit-wrapper.sh
#!/bin/sh
{
echo "MONIT-WRAPPER date"
date
echo "MONIT-WRAPPER env"
env
echo "MONIT-WRAPPER $@"
$@
R=$?
echo "MONIT-WRAPPER exit code $R"
@kenmazaika
kenmazaika / test_fast.rake
Created August 28, 2012 01:57
Parallel Test Helper Tasks
# This code taken from code written by Jack Thorne.
namespace :test do
desc "test the same tests with rake using parallel (can also run :units and :functionals)"
task :fast => :environment do
ENV['test']
ENV['TEST_ENV_NUMBER']='2'
begin
ActiveRecord::Base.establish_connection Rails.configuration.database_configuration['test']
ActiveRecord::Base.connection.instance_values["config"][:database]
This file has been truncated, but you can view the full file.
@kenmazaika
kenmazaika / gist:3855298
Created October 8, 2012 22:07
hurrray.sql
SELECT * FROM message_logs JOIN message_acks ON(message_logs.id = message_acks.message_log_id) LEFT OUTER JOIN message_logs message_logs_not_latest ON(message_logs_not_latest.publisher_id = message_logs.publisher_id AND message_logs_not_latest.created_at > message_logs.created_at) JOIN receivers ON(receivers.id = message_acks.receiver_id) WHERE message_logs_not_latest.id IS NULL AND message_acks.status='failure' AND receivers.name='ad_server' AND message_logs.publisher_id IS NOT NULL;
@kenmazaika
kenmazaika / status.rb
Created October 12, 2012 00:40
status
class Kitten < Struct.new(:mood)
[:happy, :sad, :angry, :dizzy, :silly, :hungry, :lazy].each do |feeling|
define_method "#{feeling}?" do
self.mood == feeling
end
end
end
#1.9.3p0 :008 > kitteh = Kitten.new(:lazy)
# => #<struct Kitten mood=:lazy>
@kenmazaika
kenmazaika / kittens.rb
Created October 12, 2012 00:51
kittens
class Integer
def kittens
self.times do
puts "Kittens"
end
end
end
# 1.9.3p0 :032 > 2.kittens
# Kittens