Skip to content

Instantly share code, notes, and snippets.

View mattyoho's full-sized avatar

Matt Yoho mattyoho

  • San Francisco, CA, USA
View GitHub Profile
@mattyoho
mattyoho / MVC_what_now.rb
Created July 8, 2009 03:33
Access Rails routes from outside of controllers/views. Most rules have exceptions, folks.
class CanHazRoutes
include ActionController::UrlWriter
host = case ENV['RAILS_ENV']
when "production"
"prod.com"
when "staging"
"stage.com"
when "development"
"app.local"
trials = []
10000.times{ trials << rand(6) }
trials.uniq.map do |u|
trials.select { |t| t.equal? u }.size
end.collect do |c|
c.to_f / trials.size
end
#!/bin/sh
REPO=$1
git clone $REPO
cd `basename $REPO .git`
for BRANCH in `git branch -r`; do
git co --track \
-b remote/$BRANCH \
$BRANCH
done
#!/usr/bin/env ruby
puts "looking for the gems to upgrade..."
gem_info = Struct.new(:name, :version)
to_reinstall = []
Dir.glob('/Library/Ruby/Gems/**/*.bundle').map do |path|
path =~ /.*1.8\/gems\/(.*)-(.*?)\/.*/
name, version = $1, $2
bundle_info = `file path`
to_reinstall << gem_info.new(name, version) unless bundle_info =~ /bundle x86_64/
end
irb(main):054:0> class Cat
irb(main):055:1> def eigen
irb(main):056:2> class << self
irb(main):057:3> self
irb(main):058:3> end
irb(main):059:2> end
irb(main):060:1> end
=> nil
irb(main):061:0> c1 = Cat.new
=> #<Cat:0x1017562d0>
[user@host ~]$ cat /proc/7128/cmdline
/usr/java/java/bin/java-Djava.awt.headless=true-Xms128M-Xmx256M-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager-Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties-Djava.endorsed.dirs=/usr/local/tomcat/common/endorsed-classpath:/usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/commons-logging-api.jar-Dcatalina.base=/usr/local/tomcat-Dcatalina.home=/usr/local/tomcat-Djava.io.tmpdir=/usr/local/tomcat/temporg.apache.catalina.startup.Bootstrapstart
@mattyoho
mattyoho / gist:195512
Created September 28, 2009 15:34
Capistrano patch for issue introduced by Github migration.
We couldn’t find that file to show.
@mattyoho
mattyoho / debug.rb
Created October 14, 2009 09:56 — forked from tmm1/debug.rb
# collect information about a running process
# ruby debug.rb <pid>
begin
raise ArgumentError unless pid = ARGV[0]
pid = pid.to_i
Process.kill(0,pid)
rescue TypeError, ArgumentError
raise 'pid required'
rescue Errno::ESRCH
module Inline
include Haml::Filters::Base
def self.[](key)
@@data[key.to_s] rescue nil
end
def render(str)
@@data = Hash[*str.split(/^\s*@@\s*(\w+)\s*\n/m)[1..-1]]
return nil
# include this in application controller
module Authentication
protected
# Inclusion hook to make #current_user and #signed_in?
# available as ActionView helper methods.
def self.included(base)
base.send :helper_method, :current_user, :signed_in?, :authorized? if base.respond_to? :helper_method
end
# Returns true or false if the user is signed in.