Skip to content

Instantly share code, notes, and snippets.

@anewusername1
anewusername1 / gist:567271
Created September 6, 2010 17:09
It's a start on making a select box thing much like jquery.multselect
(function($) {
$.widget("ui.singleselect", {
options: {
// sortable: true,
// searchable: true,
animated: 'fast',
show: 'slideDown',
hide: 'slideUp'
},
@anewusername1
anewusername1 / gist:837894
Created February 21, 2011 23:15
Justin Shakespear's nifty translation tool for twitter
javascript:(function(){var%20d=document;var%20s=d.createElement('script');s.text="KOBJ_config={'a877x1:kynetx_app_version':'dev','rids':['a877x1']};";d.body.appendChild(s);var%20l=d.createElement('script');l.src='http://init.kobj.net/js/shared/kobj-static.js';d.body.appendChild(l);})()
@anewusername1
anewusername1 / array_sorts.rb
Created February 24, 2011 15:18
Array sorting
class Array
def natural_sort
just_letters = self.select{|el| el =~ /^[a-zA-Z]+$/}
numbers = self - just_letters
just_letters.sort + numbers.sort{|x,y| x.gsub(/[a-zA-Z]+/, '').to_i <=> y.gsub(/[a-zA-Z]+/, '').to_i}
end
end
@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}
@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 / 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 / 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 / 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 / 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')