Skip to content

Instantly share code, notes, and snippets.

View jasonmadigan's full-sized avatar

Jason Madigan jasonmadigan

View GitHub Profile
@jasonmadigan
jasonmadigan / fix_trailing_comma.pl
Created November 15, 2011 12:38
Fix trailing JavaScript commas
#!/usr/bin/perl
use Getopt::Long;
my $verbose;
my $overwrite;
my $renamenew;
my $append;
my $help;
#!/usr/bin/ruby
require 'socket.so'
class UDPServer
def initialize(port)
@port = port
end
def start
@socket = UDPSocket.new
@jasonmadigan
jasonmadigan / client.html
Created August 17, 2010 18:43
WebSocket Test
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="en">
<head>
<title>
Websocket Test
</title>
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js' type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
function debug(str){ $("#debug").append("<p>" + str + "<\/p>"); };
@jasonmadigan
jasonmadigan / iTunes.rb
Created October 30, 2009 16:49
Block iTunes (or other apps) from opening when Spotify is open. Gets rid of that pesky "oh you hit the play button? Better open iTunes" behaviour.
#!/usr/bin/env ruby
# Blocks iTunes from launching if Spotify is open
# Installation:
# sudo ruby -e "$(curl -fsS https://raw.github.com/gist/613045/b12123d5e25d446038e6300bf54d2121bf180c34)"
blockers = ["Spotify"]
launch = true
blocker_name = ""
@jasonmadigan
jasonmadigan / Hide folders from finder using SetFile
Created October 12, 2009 11:43
Hide folders from finder using SetFile
Use
/Developer/Tools/SetFile -a V /opt
or
chflags hidden /opt
To revert:
chflags unhidden /opt
@jasonmadigan
jasonmadigan / balance.rb
Created October 9, 2009 09:00
Firefox is slow to start, so here's a WITCard balance checker
#!/usr/bin/env ruby
# coding: utf-8
require 'rubygems'
require 'mechanize'
USERNAME = '<USERNAME>'
PASSWORD = '<PASSWORD>'
mech = Mechanize.new
@jasonmadigan
jasonmadigan / Caller
Created September 24, 2009 15:32
Caller execution stack frame in Ruby
#!/usr/bin/ruby
# Kernel#caller returns the current execution stack
class Stubby
def initialize
puts caller
end
end
@jasonmadigan
jasonmadigan / GetIP
Created September 7, 2009 16:08
Local IP lookup
#!/usr/bin/env ruby
require 'socket'
class GetIP
def self.local_ip
orig, Socket.do_not_reverse_lookup = Socket.do_not_reverse_lookup, true
UDPSocket.open do |s|
s.connect '64.233.187.99', 1 # Relax, nothing is hitting the network
s.addr.last
@jasonmadigan
jasonmadigan / thread-limit.c
Created September 3, 2009 14:08
Find thread limit
/* gcc -lpthread -o thread-limit thread-limit.c */
#include <stdio.h>
#include <unistd.h>
#include <pthread.h>
#define MAX_THREADS 10000
int i;
void run(void) {
@jasonmadigan
jasonmadigan / gist:178405
Created August 31, 2009 11:27
Find last subversion commit by a given user
#!/usr/bin/env ruby
# Give me a username and how many days back you want me to search,
# and I'll tell you when this user last made a commit to a given repository.
# Deal?
# Usage: ./last_commit.rb -b 10 -u <SVN Username> -r http://svn/trunk
require 'rubygems'
require 'activesupport'