Skip to content

Instantly share code, notes, and snippets.

@anewusername1
anewusername1 / growlme.pl
Created September 27, 2011 19:07
irssi growl notification
use strict;
use vars qw($VERSION %IRSSI);
use Irssi;
$VERSION = '0.0.1';
%IRSSI = (
authors => 'Tracey Eubanks',
contact => '[email protected]',
name => 'growlme',
description => "Send growl notifications when you receive a pm or you're mentioned in a channel",
@anewusername1
anewusername1 / findIndexByCol.js
Created August 26, 2011 16:46
array index searching
// search through a two dimensional array
Array.prototype.findIndexByCol = function(value,cIdx){
for (var i=0; i < this.length; i++) {
// use === to check for Matches. ie., identical (===), ;
if (this[i][cIdx] == value) {
//alert(this[i][cIdx]+"===="+value);
return i;
}
}
return null;
@anewusername1
anewusername1 / rabbit_initializer.rb
Created August 17, 2011 22:02
subscriber code example
EM.schedule do
user_subscription = Subscriptions::User.new
Ragnar.exchange(:topic, 'events') do |x|
x.queue_prefix = :service_name
x.subscribe('user.delete', &user_subscription.method(:user_delete))
x.subscribe('user.login', &user_subscription.method(:user_login))
end
@anewusername1
anewusername1 / publisher.rb
Created August 17, 2011 15:24
Multicast pub/sub using rabbitmq, amqp, and bunny
require 'bunny'
b_con = Bunny.new(host: 'localhost', port: 5672, logging: true)
b_con.start
b_q = b_con.queue('events')
b_ex = b_con.exchange('events', type: :topic)
b_ex.publish('message!!', key: 'usermanager.user.login')
@anewusername1
anewusername1 / breakdown.rb
Created June 27, 2011 16:02
line commit breakdown
class Breakdown
def gather_files(start_dir)
files = []
Dir["#{start_dir}/*"].each do |file|
if(File.directory?(file))
files += gather_files(file)
else
files << file
end
end
@anewusername1
anewusername1 / unfickle1.rb
Created June 17, 2011 15:11
Unfickle Blog Post
class SomeClass
SOMECONSTANT = 'somevalue'
...
end
@anewusername1
anewusername1 / unfickle1.rb
Created June 17, 2011 15:11
Unfickle Blog Post
class SomeClass
SOMECONSTANT = 'somevalue'
...
end
@anewusername1
anewusername1 / interactive.rb
Created June 14, 2011 20:58
interactive editor
# Giles Bowkett, Greg Brown, and several audience members from Giles' Ruby East presentation.
require 'tempfile'
class InteractiveEditor
DEBIAN_SENSIBLE_EDITOR = '/usr/bin/sensible-editor'
MACOSX_OPEN_CMD = 'open'
XDG_OPEN = '/usr/bin/xdg-open'
def self.sensible_editor
return ENV['VISUAL'] if ENV['VISUAL']
return ENV['EDITOR'] if ENV['EDITOR']
@anewusername1
anewusername1 / gist:971219
Created May 13, 2011 20:02
Exporting / Importing a database in PostGres
pg_dump <database_name> > database_name.pgdump
cat database_name.pgdump | psql -d database_name
@anewusername1
anewusername1 / gist:965327
Created May 10, 2011 20:32
Convert hash symbols to strings
my_hash.inject({}){|memo,(k,v)| memo[k.to_s] = v; memo}