Skip to content

Instantly share code, notes, and snippets.

View knzai's full-sized avatar

Kenzi Connor knzai

View GitHub Profile
#http://github.com/ahoward/open4 is an alternative that handles pid and exit status
#http://github.com/ahoward/session a more fleshed our shell utility
require 'open3'
Open3.popen3("dc") do |stdin, stdout, stderr|
t = Thread.new(stderr) do |terr|
while (line = terr.gets)
puts "stderr: #{line}"
end
end
class Wizard
# class << self
# self.class_eval do
# define_method :convene_council do
# puts "The council is in session!"
# end
# end
# end
def self.metaclass
@knzai
knzai / HelloWorld.java
Created February 16, 2010 07:37
Call a custom .jar from jruby
public class HelloWorld {
public String hello() {
return "Hello cruel world";
}
}
## require in config/environment.rb before init starts
#require 'config/add_explicit_path_to_config_gem'
#Rails::Initializer.run do |config|
#config.gem 'my_gem', :version => '0.0.1', :explicit_path => "#{RAILS_ROOT}/vendor/local_gemfiles/my_gem-0.0.1.gem" #or
#config.gem 'my_gem', :version => '0.0.1', :explicit_path => "http://github.com/myname/myrepo/raw/master/mygem.gem" #or
module Rails
class GemDependency < Gem::Dependency
def initialize(name, options = {})
require 'rubygems' unless Object.const_defined?(:Gem)
#a variation of this:http://ozmm.org/posts/z_cache_bang.html
#def rankings
# @rankings ||= rankings!
#end
#def rankings!
# # compute expensive rankings
#end
def rankings
#initializers/authorization.rb
class AR::Base
def editable_by(user)
user.owns?(self) || user.is_admin?
end
def destroyable_by(user)
editable_by(user)
end
#initializers/authorization.rb
class AR::Base
def editable_by(user)
user.owns?(self) || user.is_admin?
end
def destroyable_by(user)
editable_by(user)
end
irb(main):001:0> :my_new_symbol.to_i
=> 16073
irb(main):002:0> 16073.to_sym
=> :my_new_symbol
irb(main):001:0> Symbol.all_symbols.length
=> 1709
irb(main):002:0> def my_new_method
irb(main):003:1> end
// DR1.0 :: domReady
// *****************************************************
// DOM scripting by brothercake -- http://www.brothercake.com/
// GNU Lesser General Public License -- http://www.gnu.org/licenses/lgpl.html
//******************************************************
//DOM-ready watcher
function domReady()
@knzai
knzai / a_ too_much_in_the_parent_the_wrong_way.rb
Created October 30, 2009 20:49
An example of differing ways of abstracting initialization into the parent
class AbstractScraper
def initialize(username, password)
@agent = WWW::Mechanize.new
@agent.user_agent_alias = "Windows Mozilla"
@agent.keep_alive = false
login(username, password)
end
end
class NormalAScraper < AbstractScraper