Skip to content

Instantly share code, notes, and snippets.

View dragonfax's full-sized avatar

Jason Stillwell dragonfax

View GitHub Profile
@dragonfax
dragonfax / gist:4711339
Created February 5, 2013 01:29
need a quick network graph in git? how about "git ig" alias to make it happen. Thanks Jaime (@ober)
~/.gitconfig: lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative
@dragonfax
dragonfax / tip.md
Created February 5, 2013 22:23
List all the methods of an object (that aren't stock methods). Useful in irb.

Use instance.methods - Object.methods to list only the non-stock methods implemented by the instances class.

> e = Exception.new
 => #<Exception: Exception> 


> e.methods 
 => [:exception, :==, :to_s, :message, :inspect, :backtrace, :set_backtrace, :nil?, :===, :=~, :!~, :eql?, :hash, :<=>, :class, :singleton_class, :clone, :dup, :initialize_dup, :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, :instance_variables, :instance_variable_get, :instance_variable_set, :instance_variable_defined?, :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for, :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__] 
@dragonfax
dragonfax / gist:4950705
Last active December 13, 2015 17:48
just like grep, but only print the actual matched text, not all of the text from the matching lines.

replace 'blah' with your regex

find ./ -type f -print | xargs perl -ne 'print $1,"\n" if m{(blah)}'

@dragonfax
dragonfax / local.markdown
Created February 27, 2013 22:44
give ruby its own version of perl's local() scoping, or "temporary-only values for existing variables."
@dragonfax
dragonfax / pry.md
Created March 8, 2013 01:03
nesting pry, event inside a block

Nesting pry works beautifully. Kudos to the pry team.

Nesting pry: (note the 2 exit statements needed)

Hershwild:~ jstillwell$ pry
[1] pry(main)> binding.pry
[1] pry(main)> exit
=&gt; nil
@dragonfax
dragonfax / script.markdown
Created March 12, 2013 21:00
Boilerplate for a script that runs from anywhere without installing it as a gem.

To enable a script to

  • from its project directory
  • run from anywhere on the system.
  • from inside or outside its project directory
  • with its own lib directory
  • with a Gemfile (bundler)
  • with symlinks to it from various places like /usr/local/bin
  • with a garuanteed ruby version
  • with rvm, but without having to run rvm use each session.
@dragonfax
dragonfax / gist:5198198
Created March 19, 2013 17:29
Just to piss off some Rube's (rubyists)
class NilPointerException < Exception
end
@dragonfax
dragonfax / banner_rotate.rb
Created May 1, 2013 22:12
quick ruby one liner to rotate banner'ed text
rotated = []
y = 0
`banner -w 30 W T F`.split("\n").each { |line|
x = 0
line.each_char { |char|
rotated[x] ||= []
rotated[x][y] = char
x += 1
}
y += 1
@dragonfax
dragonfax / gist:5801540
Created June 17, 2013 23:50
Throw a checked exception with no fucks given (no declaring the checked exception).
class NoFucks {
public NoFucks () throws Exception {
throw new Exception();
}
}
...
try {
NoFucks.class.newInstance();
} catch(InstantiationException e) {
} catch(IllegalAccessException e) {
@dragonfax
dragonfax / gist:5847823
Last active December 18, 2015 21:29
make pre-commit a global default for all of your repos.
mkdir ~/.git_template
mkdir ~/.git_template/hooks
cp $(gem contents pre-commit | grep pre-commit-hook) ~/.git_template/hooks/pre-commit
git config --global init.templatedir '~/.git_template'
# also, to implement in any pre-existing repos, just execute 'git init' in them.