Skip to content

Instantly share code, notes, and snippets.

View cpetschnig's full-sized avatar

Christoph Petschnig cpetschnig

  • SINC GmbH
  • Leipzig, Germany
  • 17:46 (UTC +02:00)
View GitHub Profile
@cpetschnig
cpetschnig / gist:1570765
Created January 6, 2012 14:07
env settings
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ \1 $SYM/'
}
BLUE="\[\e[1;34m\]"
BLUE_="\[\e[0;34m\]"
BROWN_="\[\e[0;33m\]"
RESET="\[\e[0;0m\]"
SYM="$BLUE_Δ"
@cpetschnig
cpetschnig / even_more_debugging_output.rb
Created November 8, 2011 07:32
Trace the origin of your Rails logging output
class ActiveSupport::BufferedLogger
def add(severity, message = nil, progname = nil, &block)
return if @level > severity
message = (message || (block && block.call) || progname).to_s
# If a newline is necessary then create a new message ending with a newline.
# Ensures that the original message is not mutated.
message = "#{message}\n" unless message[-1] == ?\n
buffer << message
@cpetschnig
cpetschnig / gist:1286665
Created October 14, 2011 09:23
Show Term::ANSIColor effects
# Show Term::ANSIColor effects
(Term::ANSIColor.methods - Module.methods).sort.each{|x| print "#{x}: ".ljust(15); begin; puts Term::ANSIColor.send(x, 'foo bar'); rescue; puts 'error'; end }
@cpetschnig
cpetschnig / cap_deploy_clean_menu_exit.rb
Created May 5, 2011 11:31
Avoid stack trace when canceling the Capistrano menu
# Put this code in your deploy.rb, if you are annoyed by
# the stack trace when aborting the capistrano with ^C
# (under MIT License)
require 'active_support/core_ext/module'
# avoid having a whole page of stack trace when you abort the menu with `^C`
HighLine.module_eval do
def get_line_with_interrupt_catching
get_line_without_interrupt_catching
@cpetschnig
cpetschnig / .irbrc
Created April 13, 2011 09:48
IRB customization: load wirble, looksee and awesome_print; cheat bundler
require 'rubygems'
@irb_extensions = []
def require_for_irb_with_fallback_for_bundler_constraints(gem_name, load_file = nil)
load_file ||= gem_name
begin
begin
require load_file
rescue LoadError => e
@cpetschnig
cpetschnig / profiling-example.rb
Created November 16, 2010 15:51
Custom runtime evaluation/profiling
class Array
@@caller_counter = {}
def include_with_caller?(value)
key = caller[0,4].join('|')
@@caller_counter[key] = (@@caller_counter[key] || 0) + 1
include_without_caller?(value)
end
alias_method_chain :include?, :caller
def self.callers
@@caller_counter
@cpetschnig
cpetschnig / 0001-Added-config-option-order.patch
Created November 6, 2010 16:44
Patch for oggy/looksee: Added config option 'order'
From 7878ed28ba6bafbe4f90286f4b86ab35e223939e Mon Sep 17 00:00:00 2001
From: Christoph Petschnig <[email protected]>
Date: Fri, 5 Nov 2010 19:10:37 +0100
Subject: [PATCH] Added config option #order
---
lib/looksee.rb | 21 ++++++++++++++++++++-
spec/looksee_spec.rb | 10 ++++++++++
2 files changed, 30 insertions(+), 1 deletions(-)
@cpetschnig
cpetschnig / ruby-srtftime
Created September 21, 2010 09:25
Show the possible tokens of Ruby Time#strftime
#!/usr/bin/env ruby
# one line version:
# t = Time.new; puts (65.upto(90).map{|i|s = "%%#{i.chr}: %#{i.chr}"; t.strftime(s).ljust(25) + t.strftime(s.downcase)}.join("\n"))
# Output:
#
# %A: Tuesday %a: Tue
# %B: September %b: Sep
# %C: 20 %c: Tue Sep 21 08:53:35 2010
From d775b59b47c284fe43086772cffe7481b951d36a Mon Sep 17 00:00:00 2001
From: Christoph Petschnig <[email protected]>
Date: Thu, 22 Jul 2010 08:21:35 +0200
Subject: [PATCH] Added tests for start/stop log messages
---
test/daemon_spawn_test.rb | 14 ++++++++++++++
1 files changed, 14 insertions(+), 0 deletions(-)
diff --git a/test/daemon_spawn_test.rb b/test/daemon_spawn_test.rb
From e35a6eaef85051163204a1ba5c7fa4facdad6420 Mon Sep 17 00:00:00 2001
From: Christoph Petschnig <[email protected]>
Date: Wed, 21 Jul 2010 09:52:27 +0200
Subject: [PATCH 1/2] Added 'rake test'
---
Rakefile | 7 +++++++
1 files changed, 7 insertions(+), 0 deletions(-)
diff --git a/Rakefile b/Rakefile