Chad Humphries

Enabling wrap in pre tags

pre {
 white-space: pre-wrap;       /* css-3 */
 white-space: -moz-pre-wrap;  /* Mozilla, since 1999 */
 white-space: -pre-wrap;      /* Opera 4-6 */
 white-space: -o-pre-wrap;    /* Opera 7 */
 word-wrap: break-word;       /* Internet Explorer 5.5+ */
}
Language CSS

Computer: Where am I right now in my rails application?

Posted by Chad Humphries 9 days ago
# This came from 20 minutes of goofing off
before_filter :where_am_i_right_now

def where_am_i_right_now
  %x{say 'processing #{params[:action].humanize} on the #{params[:controller]} controller'}
end
Language Ruby / Tagged with rails, bad

A nice simple jquery logger

jQuery.fn.log = function (msg) {
  console.log("%s: %o", msg, this);
  return this;
};
Language JavaScript / Tagged with jquery, logging

Please install my gem post haste good sir!

Posted by Chad Humphries 23 days ago
# To install most quickly instead of updating the source cache do
gem install rmagick --no-update-sources
Language Ruby / Tagged with rmagick

Manpage fix for programs installed via MacPorts on OSX

export MANPATH=/opt/local/share/man:$MANPATH
Language Shell/Scripting / Tagged with osx, git, man

Never do this please

Posted by Chad Humphries 24 days ago
# Stick this in a model, and enjoy.  Or don't.  Actually don't.  This was 
# written as a crazy experiment all about coulda, not about shoulda.
class ActiveRecord::Base
  def current_user
    ObjectSpace.each_object(ApplicationController) do |found_obj|
      return found_obj.send!(:current_user) if found_obj.respond_to?(:current_user) 
    end
  end
end
Language Ruby / Tagged with rails, ahhh

Where is this defined?

Posted by Chad Humphries 24 days ago
# The original version of this code was found on http://holgerkohnen.blogspot.com/ 
# long ago.  It has since been modified a good deal, renamed, and improved.

module Kernel

  # which { some_object.some_method() } => ::
  def where_is_this_defined(settings={}, &block)
    settings[:debug] ||= false
    settings[:educated_guess] ||= false
    
    events = []
    
    set_trace_func lambda { |event, file, line, id, binding, classname|
      events << { :event => event, :file => file, :line => line, :id => id, :binding => binding, :classname => classname }
      
      if settings[:debug]
        puts "event => #{event}"
        puts "file => #{file}"
        puts "line => #{line}"
        puts "id => #{id}"
        puts "binding => #{binding}"
        puts "classname => #{classname}"
        puts ''
      end
    }
    yield
    set_trace_func(nil)

    events.each do |event|
      next unless event[:event] == 'call' or (event[:event] == 'return' and event[:classname].included_modules.include?(ActiveRecord::Associations))
      return "#{event[:classname]} received message '#{event[:id]}', Line \##{event[:line]} of #{event[:file]}"
    end
    
    # def self.crazy_custom_finder
    #  return find(:all......)
    # end
    # return unless event == 'call' or (event == 'return' and classname.included_modules.include?(ActiveRecord::Associations))
    # which_file = "Line \##{line} of #{file}"
    if settings[:educated_guess] and events.size > 3
      event = events[-3]
      return "#{event[:classname]} received message '#{event[:id]}', Line \##{event[:line]} of #{event[:file]}"
    end
    
    return 'Unable to determine where method was defined.'
  end

end
Language Ruby / Tagged with meta

Common git bash/zsh aliases

alias g=’git’
alias gb=’git branch’
alias gba=’git branch -a’
alias gc=’git commit -v’
alias gca=’git commit -v -a’
alias gd=’git diff | mate’
alias gl=’git pull’
alias gp=’git push’
Language Shell/Scripting / Tagged with git, bash, zsh

Git Commits That Need to be Pushed

I constantly find myself wondering what the difference is between what I’ve committed to my local Git repository, and what’s been pushed up to Github. Here’s one way, I’m sure there’s others:

git cherry -v origin
Or, how about a bash alias?
alias push?='git cherry -v origin'
Language Shell/Scripting / Tagged with git

Searching for a deleted method with git

git log -S'some_string'
git whatchanged -p (after the pager comes up, type '/' and then 'some_string')
Language Shell/Scripting / Tagged with git