Skip to content

Instantly share code, notes, and snippets.

View kogent's full-sized avatar

Mark Carey kogent

View GitHub Profile
@kogent
kogent / .autotest
Created December 3, 2008 18:58 — forked from nicksieger/.autotest
# -*- ruby -*-
module AutoGrowl
def self.pt(msg)
msg.gsub %r{\\e\[[0-9]+m?}, ''
end
def self.growl(title, msg, pri = 0)
system "/usr/local/bin/growlnotify -n autotest --image /Applications/Mail.app/Contents/Resources/Caution.tiff -p #{pri} -m #{pt msg.inspect} #{pt title.inspect}" unless RUBY_PLATFORM =~ /java/
end
# Simple example of using ShadowFacter with RSpec to verify system configuration
# http://twitter.com/bradleyktaylor | http://railsmachine.com
#
# run with 'spec -c installed_test.rb'
require 'shadow_facter'
def installed_fact(n)
name = n
fact(name) { exec("#{name.to_s} --version") ? true : false }
@kogent
kogent / httpdump
Created June 22, 2009 04:18 — forked from peterc/httpdump
# Monitor HTTP requests being made from your machine with a one-liner..
# Replace "en1" below with your network interface's name (usually en0 or en1)
sudo tcpdump -i en1 -n -s 0 -w - | grep -a -o -E "Host\: .*|GET \/.*"
# OR.. to be able to use as "httpdump" from anywhere, drop this into ~/.bash_profile:
# (again replace "en1" with correct network interface name)
alias httpdump="sudo tcpdump -i en1 -n -s 0 -w - | grep -a -o -E "Host\: .*|GET \/.*""
# All the above tested only on OS X.
# This is a useful little pattern for working with gems without
# explicitly requiring rubygems in your code.
#
# The approach taken is to require a library and catch any LoadError
# that might get thrown. In the rescue clause we require rubygems.
#
# The require method is nice in that it will return true if the code
# was loaded, and it returns false if the code was _already_ loaded.
# If the require of rubygems returns true, we will retry our original
# require. It will either succeed this time (since we now have rubygems
@kogent
kogent / bench.rb
Created July 2, 2009 04:45 — forked from lifo/bench.rb
require 'rubygems'
require 'curb'
require "net/http"
require 'benchmark'
# http://0.0.0.0:8080
#
# class HomeController < ApplicationController
# def index
# sleep 3
@kogent
kogent / 0what.md
Created August 24, 2009 03:55 — forked from defunkt/0what.md

Poor Man's Deploy

  • Start a Sinatra server on port 4000
  • GET / to that server triggers a git pull and mod_rails restart
  • Hit port 4000 locally after pushing

Why?

@kogent
kogent / debug.rb
Created December 8, 2009 20:33 — 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
raise ArgumentError unless pid > 0
Process.kill(0,pid)
rescue TypeError, ArgumentError
raise 'pid required'
@kogent
kogent / mini.rb
Created February 24, 2010 19:19 — forked from defunkt/mini.rb
##
# test/spec/mini 5
# http://gist.github.com/307649
# [email protected]
#
def context(*args, &block)
return super unless (name = args.first) && block
require 'test/unit'
klass = Class.new(defined?(ActiveSupport::TestCase) ? ActiveSupport::TestCase : Test::Unit::TestCase) do
def self.test(name, &block)
@kogent
kogent / url_dsl.rb
Created February 24, 2010 19:40 — forked from defunkt/url_dsl.rb
require 'open-uri'
# url dsl -- the ultimate url dsl!
#
# You just can't beat this:
#
# $ irb -r url_dsl
# >> include URLDSL
# => Object
# >> http://github.com/defunkt.json
@kogent
kogent / TextMate gemspec snippet.png
Created April 5, 2010 19:21 — forked from mislav/TextMate gemspec snippet.png
TextMate snippet to quickly populate a fresh gemspec
TextMate gemspec snippet.png