Skip to content

Instantly share code, notes, and snippets.

View xwmx's full-sized avatar

William Melody xwmx

View GitHub Profile
@xwmx
xwmx / urlmonitor
Created April 29, 2009 15:12 — forked from peterc/urlmonitor
# urlmonitor - print out the URLs requested system wide on the main network interface
# Accept a network interface name as an optional argument
iface = ARGV.first
# No interface specified? Try to guess which one is king..
unless iface
`ifconfig -l`.split.each do |iface|
next if iface =~ /^lo/
break if `ifconfig #{iface}` =~ /inet (0|1|2)/
module BreadcrumbsHelper
def breadcrumbs(*args, &block)
yield(BreadcrumbBuilder.new(self))
end
class BreadcrumbBuilder
include ActionView::Helpers::TagHelper
include ActionView::Helpers::CaptureHelper
def initialize(controller)
@xwmx
xwmx / httpdump
Created April 4, 2009 03:14 — 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.
@xwmx
xwmx / gist:60808
Created February 9, 2009 14:47 — forked from wmoxam/gist:37525
#!/usr/bin/env ruby
#
# Be sure to configure this node in the plugin configuration
# Memory stats must be run by root
# Ex:
# [passenger_memory]
# user root
# env.memory_stats_command path_to_passenger-memory-stats
#
# syntax_helper.rb
module SyntaxHelper
WhiteListHelper.tags.merge(UV_SYNTAX_TAGS)
def colorize_code(body, options = {})
options = {:line_numbers => false, :theme => DEFAULT_SYNTAX_STYLE}.merge(options)
r = RedCloth.new(body || '')
output = r.gsub(/<code[\.|\:]([\w\-]+)>(.*?)<\/code[\.|\:]?\1?>/m) do
lang, text = $1, $2
html = "<notextile>" + code((text || ''), {:syntax => (lang if UV_SYNTAXES.include?(lang))}.merge(options)) + "</notextile>"
##
# Calendar helper with proper events
# http://www.cuppadev.co.uk/webdev/making-a-real-calendar-in-rails/
#
# (C) 2009 James S Urquhart (jamesu at gmail dot com)
# Derived from calendar_helper
# (C) Jeremy Voorhis, Geoffrey Grosenbach, Jarkko Laine, Tom Armitage, Bryan Larsen
# Licensed under MIT. http://www.opensource.org/licenses/mit-license.php
##
def log_test
if Rails::logger
# When I run tests in rake or autotest I see the same log message multiple times per test for some reason.
# This guard prevents that.
unless @already_logged_this_test
Rails::logger.info "\n\nStarting #{@method_name}\n#{'-' * (9 + @method_name.length)}\n"
end
@already_logged_this_test = true
end
end
def assert_layout(expected=nil, message=nil)
clean_backtrace do
layout = @response.layout ? @response.layout.split('/').last : false
msg = build_message(message, "expecting <?> but rendering with <?>", expected, layout)
assert_block(msg) do
if expected.nil?
@response.layout
else
expected == layout
end
@xwmx
xwmx / gist:45283
Created January 9, 2009 21:11
ActionMailer Monkeypatching
class ActionMailer::Base
helper ActionView::Helpers::UrlHelper
def generic_mailer(options)
@recipients = options[:recipients] || (Settings.mailer_to_address if Settings.table_exists?)
@from = options[:from] || (Settings.mailer_from_address if Settings.table_exists?)
@cc = options[:cc] || ""
@bcc = options[:bcc] || ""
@subject = options[:subject] || ""
@xwmx
xwmx / gist:45282
Created January 9, 2009 21:08
ActiveRecord Monkeypatching
class << ActiveRecord::Base
def paged_find_tagged_with(tags, args = {})
tags.nil? ? paginate(args) : paginate_tagged_with(tags, args)
end
def concerned_with(*concerns)
concerns.each do |concern|
require_dependency "#{name.underscore}/#{concern}"
end