Skip to content

Instantly share code, notes, and snippets.

View johnl's full-sized avatar

John Leach johnl

View GitHub Profile
@johnl
johnl / cloud-init-growpart-config
Created March 24, 2014 15:46
Cloud-init conifg to disable partition growing
#cloud-config
growpart:
mode: off
@johnl
johnl / screenshot.sh
Last active August 29, 2015 14:14
Screenshot taker/uploader
#!/bin/bash
# Takes a screenshot, uploads via scp, puts url on the clipboard
# Edit the code to set the scp destination and url format
#
# Bind it to a gnome keyboard shortcut for speedy screen sharing
#
# Ridiculously this needs bash, gnome-screenshot, xclip, scp, notify-send, sha256sum AND Ruby
set -e
@johnl
johnl / gist:4c7e51b8bc20ee4bf07e
Created June 2, 2015 12:17
Hacky patch to unicorn to log process ram use after each request
class Unicorn::HttpServer
alias process_client_orig process_client
undef_method :process_client
def process_client(client)
process_client_orig(client)
rss = `ps -o rss= -p #{Process.pid}`.chomp.to_i / 1024
puts "Unicorn #{Process.pid}, #{request.env['REQUEST_METHOD']} #{request.env['REQUEST_PATH']} using #{rss}M"
end
end
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"