Skip to content

Instantly share code, notes, and snippets.

Ramaze::Cache.options.session = Ramaze::Cache::MemCache.using(
compression: false,
username: ENV['MEMCACHE_USERNAME'],
password: ENV['MEMCACHE_PASSWORD'],
servers: ENV['MEMCACHE_SERVERS'].split(','),
)
@manveru
manveru / xgrep.rb
Created December 10, 2011 10:59
Grepping XML using XPath
#!/usr/bin/env ruby
# Usage:
# xgrep.rb '//load[@module]/@module' autoload_configs/modules.conf.xml
require 'nokogiri'
xpath = ARGV[0]
files = ARGV[1..-1]
@manveru
manveru / burnbit.coffee
Created November 2, 2011 09:43
burnbit button maker
callbackData = []
styles = {normal: "burnbit_normal", compact: "burnbit_compact"}
hasClass = (tag, name) ->
tag.className.match(new RegExp("(\\s|^)" + name + "(\\s|$)"))
addClass = (tag, name) ->
tag.className += " #{name}" unless hasClass(tag, name)
fillDetails = (tag, seeds, peers) ->
@manveru
manveru / setup_gitconfig.rb
Created October 31, 2011 21:25 — forked from eykanal/setup_gitconfig.rb
Create basic .gitconfig file
#!/usr/bin/ruby
def ask(question, retries = 3)
fail "Failed to get user input" if retries <= 0
print question
if got = gets
got.strip
else
@manveru
manveru / backup.rb
Created August 31, 2011 09:02
Storing product activity from net-a-porter
require 'sqlite3'
sdb = SQLite3::Database.new('net-a-porter.sqlite3')
ddb = SQLite3::Database.new('net-a-porter-backup.sqlite3')
b = SQLite3::Backup.new(ddb, 'main', sdb, 'main')
begin
b.step(1)
end while b.remaining > 0
@manveru
manveru / bigdecimal.coffee
Created July 23, 2011 21:05
simple BigDecimal in CoffeeScript
class BigDecimal
constructor: (number, @precision) ->
@number = @gobble(number)
plus: (other) ->
@bd @number + @gobble(other)
minus: (other) ->
@bd @number - @gobble(other)
@manveru
manveru / track.rb
Created June 27, 2011 13:12
tracking changes over time, simple example
require 'open-uri'
require 'yaml/store'
require 'nokogiri'
doc = Nokogiri(open('http://namebit.org'))
current = doc.at('#blocks_found').text.to_i
YAML::Store.new('namebit.yaml').transaction do |store|
if previous = store[:previous]
case current <=> previous
require 'tempfile'
def check_authorized_keys(keyfile)
valid = false
File.foreach(keyfile).map do |line|
if line =~ /^ssh/
Tempfile.open('key') do |keyfile|
keyfile.write(line)
keyfile.flush
@result = %x[echo #{keyfile.path} | ssh-keygen -l 2>&1]
Rubinius Crash Report #rbxcrashreport
Error: signal SIGABRT
[[Backtrace]]
rbx[0x48737f]
/lib/libc.so.6(+0x34780)[0x7fb0dbc69780]
/lib/libc.so.6(gsignal+0x35)[0x7fb0dbc69705]
/lib/libc.so.6(abort+0x17b)[0x7fb0dbc6ab7b]
rbx[0x48d75a]
require 'json'
require 'time'
data = select_from_db.to_a
out = {
:item => data.map{|key, value| value.inspect },
:axisx => [
data.first.first,
data[data.size / 2].first,