Skip to content

Instantly share code, notes, and snippets.

View johnl's full-sized avatar

John Leach johnl

View GitHub Profile
ForumPost.transaction do
(0..WpComment.approved.count / 100).each do |offset|
WpComment.approved.find(:all, :limit => 100, :offset => offset * 100 ).each do |wpc|
ForumPost.create_from_wp_comment(wpc)
end
end
end
require 'socket'
tmp_cache_dir = [Socket.gethostname, Process.pid, Time.now.to_i, rand(0xffff)].to_s
page_cache_tree = File.join(ApplicationController.page_cache_directory, 'entries')
FileUtils.mv(page_cache_tree, page_cache_tree + tmp_cache_dir)
FileUtils.rm_rf(page_cache_tree + '-' + tmp_cache_dir)
@johnl
johnl / www-smtp-gateway.rb
Created May 29, 2010 22:44
smtp to www gateway. Tested with Postfix. Inspired by rms.
#!/usr/bin/ruby
#
# smtp to www gateway. Tested with Postfix. Inspired by rms.
#
# Pipe to this command from your .forward file (or in my case, an alias extension,
# so .forward-webgateway). For every http or https url found in the message
# (headers and body), it will send an email back to you with the output of a text
# web browser visiting.
#
# * Requires elinks and the mail command
@johnl
johnl / node-receive-upload.js
Created July 11, 2010 09:52
Script to test streaming of request body in nodejs
// Script to test streaming of request body
// test with: curl --data-binary @somebigfile http://localhost:8124
//
var http = require('http');
http.createServer(function (req, res) {
console.log('New request');
var total = 0;
req.addListener('data', function (chunk) {
total += chunk.length;
console.log('Data chunk received ' + chunk.length / 1024 + 'k');
@johnl
johnl / rainbows-sha1.ru
Created August 11, 2010 22:33
little test app to generate SHA1 hashes for HTTP uploads on the fly, without storing them on disk. Uses Rainbows and Revactor
#
# This little test app generates SHA1 hashes for HTTP uploads on the
# fly, without storing them on disk.
# By John Leach <john@johnleach.co.uk> (with help from Eric Wong)
#
# Start the server like this:
#
# rainbows -c rainbows.conf.rb rainbows-sha1.ru
#
# I've been testing this with Revactor, which requires Ruby 1.9
root@srv-kve94:~/hirb# gem -v
1.3.5
root@srv-kve94:~/hirb# rake generate
(in /home/ubuntu/hirb)
# -*- encoding: utf-8 -*-
Gem::Specification.new do |s|
s.name = %q{hirb}
s.version = "0.3.4"
def method_in_deploy
puts "METHOD IN DEPLOY"
end
task :task_in_deploy do
puts "TASK IN DEPLOY"
end
task :do_before do
puts "BEFORE"
@johnl
johnl / gist:1483785
Created December 16, 2011 00:38
xargs examples
# Remove all the sound related kernel modules
lsmod | grep snd | awk '{print $1}' | sudo xargs rmmod
# Find the ISPs of everyone who logged into your server
grep -o -E "Accepted publickey for .*" /var/log/auth.log | awk '{print $6}' | xargs -n1 whois | grep org-name
# Download all the Zed Shaw sessions and play them one after another
curl -s zedshaw.com/sessions/ | grep -o -P "http://zedshaw.music.s3.amazonaws.com/.*?.ogg" | xargs curl -s | ogg123 -
# Download all the Zed Shaw sessions, 6 *concurrently at a time* and play them *concurrently* creating a crazy mashup
@johnl
johnl / passenger-nginx-testing
Created March 27, 2012 21:25
Commands to install the Brightbox nginx passenger packages on Ubuntu
sudo apt-add-repository ppa:brightbox/passenger-nginx-testing
sudo apt-get update
sudo apt-get install nginx-full
# please report your results at http://forum.brightbox.com/ or to support@brightbox.co.uk Thanks!
# http://brightbox.com
@johnl
johnl / powerdns.conf
Created June 8, 2012 17:29
xip.io implementation with powerdns_pipe in ruby
launch=pipe
pipe-command=/path/to/xipio-pipe.rb
pipe-timeout=200
pipe-regex=^.*.ip.ipq.co;.*$