Skip to content

Instantly share code, notes, and snippets.

View ngty's full-sized avatar

Ng Tze Yang ngty

  • RankAbove Ltd
  • Singapore
View GitHub Profile
class Someone
class << self
def say
$stdin.each_line do |line|
$stdout << "someone says '#{line}' @ #{Time.now}"
end
end
end
end
# instead of Time.now (or watever class methods of Time), we use:
LocalTime.now
module RailsBestPractices
module Macros
def self.included(base)
# Calling of "include RailsBestPractices::Macros" will make all macros available as
# class methods within describe { ... }
base.extend(ClassMethods)
end
module ClassMethods
unless ENV['RAILS_ENV'] == 'production'
module Resque
class << self
alias_method :orig_enqueue, :enqueue
def Resque.enqueue(*args) ; end
end
end
end
@ngty
ngty / power_xpath_for_matching_table_by_th_and_td
Created May 21, 2010 01:52
Single xpath for table cell matching
# This script shows how a single xpath can be used for matching a specific row in an html
# table, taking into account the the header text <th/> and cell text <td/>. It is able to
# handle case-sensitivity & nested inner text.
#
# Pls note that in order to test out case-sensitivity, u need to tweak IS_CASE_SENSITIVE &
# the html string.
#
# BTW, let me know how the generated xpath can be more elegant than it currently is.
#
require 'rubygems'
class LocalTime
@@zone = Time.zone
class << self
def method_missing(method, *args)
args.empty? ? @@zone.send(method) : @@zone.send(method, *args)
end
end
end
{:gdb_debug=>true}
=> Hijacking...> (no debugging symbols found)
> Attaching to program: /usr/bin/ruby1.8, process 9433
> Reading symbols from /usr/lib/libruby1.8.so.1.8...(no debugging symbols found)...done.
> Loaded symbols for /usr/lib/libruby1.8.so.1.8
> Reading symbols from /lib/libpthread.so.0...(no debugging symbols found)...done.
> [Thread debugging using libthread_db enabled]
> [New Thread 0x7fea191b16f0 (LWP 9433)]
> [New Thread 0x7fea14f2f950 (LWP 9852)]
> Loaded symbols for /lib/libpthread.so.0
module Steam
module Matchers
module HtmlUnit
class HasContent #:nodoc:
# nothing interesting, the original content remains
end
###
# Directly extracted from Webrat::Matchers::HaveXpath with minor edits to avoid
# calling webrat stuff
ActionMailer::Base.class_eval do
DELIVERIES_CACHE_PATH =⋅
File.join(RAILS_ROOT,'tmp','cache','action_mailer_acceptance_deliveries.cache')
def perform_delivery_acceptance(mail)
deliveries << mail
File.open(DELIVERIES_CACHE_PATH,'w') do |f|
Marshal.dump(deliveries, f)
end
#!/usr/bin/ruby
`cat ~/.bash_aliases | egrep '^alias' | sed 's/alias//'`.split("\n").each do |line|
parts = line.strip.split(/=/)
name, cmd = parts[0], parts[1].gsub(/('|")/,'')
file = '/home/%s/.config/fish/functions/%s.fish' % [`whoami`.strip, name]
content = [ 'function %s' % name, ' %s $argv;' % cmd, 'end' ].join("\n")
File.open(file, 'w+'){|io| io.write(content) }
end