Skip to content

Instantly share code, notes, and snippets.

View xwmx's full-sized avatar

William Melody xwmx

View GitHub Profile
@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
#
@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.
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 / 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)/
# first you'll want to create a gist then `git clone` the private url
# second you'll want to run this script in the gist's directory
loop do
`git commit -a -m save && git push origin master`
sleep 60 * 4
end
# get a random record from a table
Item.first(:offset => ( Item.count * rand ).to_i)
# from http://blog.davidziegler.net/post/122176962/a-python-script-to-automatically-extract-excerpts-from
from BeautifulSoup import *
import urllib2
import cookielib
import re
def cleanSoup(soup):
# get rid of javascript
subtree = soup('script')
from xml.sax.saxutils import escape
import urllib, re, os, urlparse
import HTMLParser, feedparser
from BeautifulSoup import BeautifulSoup
from pprint import pprint
import codecs
import sys
streamWriter = codecs.lookup('utf-8')[-1]
# Referring to http://blog.rubybestpractices.com/posts/gregory/011-tap-that-hash.html
# Ruby 1.9, no tap, single line
Hash[[:x, :y, :z].map { |l| [l, rand(100)]}]
# Ruby 1.9/1.8, no tap, inject, single line
[:x, :y, :z].inject({}) { |result, l| result[l] = rand(100); result}
# Ruby 1.9/1.8, no tap, each_with_object from ActiveSupport, single line
[:x, :y, :z].each_with_object({}) { |l, result| result[l] = rand(100) }
@xwmx
xwmx / #
Created August 8, 2009 15:44 — forked from rmanalan/gist:161461
script/generate plugin HelloWorld
# vendor/plugins/hello_world/init.rb
Rails.configuration.gem "sinatra"
Rails.configuration.middleware.insert_before("ActionController::Failsafe", "HelloWorld")
# vendor/plugins/hello_world/lib/hello_world.rb
# your sinatra app goes here...
require 'sinatra/base'
class HelloWorld < Sinatra::Base