Skip to content

Instantly share code, notes, and snippets.

View mloberg's full-sized avatar
🐚
call me on my #!/bin/sh phone

Matt Loberg mloberg

🐚
call me on my #!/bin/sh phone
View GitHub Profile
@mloberg
mloberg / gist:3099019
Created July 12, 2012 15:59
Simple Load Test
#!/bin/sh
REQUEST="http://example.com"
NUM_REQ=100
CONCURENT=10
# Set up parallel processes (http://mlo.io/blog/2012/06/13/parallel-processes-in-bash.html)
mkfifo pipe
exec 3<>pipe
rm -rf pipe
@mloberg
mloberg / gist:3084643
Created July 10, 2012 16:51
Find and cd to projects.
#!/usr/bin/env bash
# Add or source this from .bash_profile/.bashrc
# usage: project project_name
PROJECT_DIR="~/Code"
project() {
PROJECTS=( $(find $PROJECT_DIR -type d -iname "$1") )
if [[ "${#PROJECTS[@]}" -gt 1 ]]; then
@mloberg
mloberg / bot.js
Created June 22, 2012 17:26
NodeJS - Werebot
var irc = require('irc'),
werewolf = require('./game');
var client = new irc.Client('server', 'Werebot', {
channels: [ '#channel' ],
autoConnect: false
});
client.connect();
client.addListener('registered', function(msg) {
@mloberg
mloberg / gist:2937062
Created June 15, 2012 15:33
Replace local links in markdown ([[link]]) with normal links ([link](link)).
#!/bin/sh
PREFIX=wiki
FILES=$(find . -type f -iname '*.md' -o -iname '*.markdown')
if [[ "$1" == "revert" ]]; then
# To Parse back to normal local [[links]]
for file in $FILES; do
sed -e 's/\[\(.*\)\](\/$PREFIX\/\(.*\))/[[\1]]/g' $file > $file.tmp
mv $file.tmp $file
@mloberg
mloberg / gist:2852153
Created June 1, 2012 13:28
MySQL Slow Query Log Analyzer
#!/usr/bin/php
<?php
/**
* The Analyzer class.
*/
class Analyzer {
private $fp;
@mloberg
mloberg / libcurl.fb-changes.diff
Created April 13, 2012 20:24
HipHop PHP libcurl Patch for Curl 2.25
Index: include/curl/multi.h
===================================================================
RCS file: /cvsroot/curl/curl/include/curl/multi.h,v
retrieving revision 1.45
diff -u -r1.45 multi.h
--- curl-old/include/curl/multi.h 20 May 2008 10:21:50 -0000 1.45
+++ curl-new/include/curl/multi.h 29 Jan 2010 23:45:18 -0000
@@ -135,6 +135,19 @@
int *max_fd);
@mloberg
mloberg / irc.rb
Created April 9, 2012 17:56
Ruby IRC
require "socket"
class IRC
def initialize(info)
@server = info[:server]
@port = info[:port] || 6667
@password = info[:password]
@nick = info[:nick]
@channel = info[:channel]
@mloberg
mloberg / gist:1663355
Created January 23, 2012 14:16
onImagesLoad
// MooTools
var onImagesLoad = function(callback){
var images = 0,
check;
$$("img").each(function(item, key){
images++;
var img = new Image();
img.onload = function(){
images--;
};
@mloberg
mloberg / gist:1628239
Created January 17, 2012 19:11
Responsive Grid
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
@mloberg
mloberg / upload.rb
Created December 16, 2011 14:18
qq.FileUploader Ruby
directory = './tmp/'
# ajax upload
if params[:qqfile].class == String
name = params[:qqfile]
string_io = request.body
data_bytes = string_io.read
path = File.join(directory, name)
File.open(path, "w") do |f|
f.write(data_bytes)
end