Skip to content

Instantly share code, notes, and snippets.

@carlhoerberg
carlhoerberg / urlrewriter.rb
Created August 30, 2011 21:30
A sprockets processor which rewrites the relative urls in a css when concatenating css files
require 'sprockets'
require 'pathname'
require 'uri'
module Sprockets
class UrlRewriter < Processor
def evaluate(context, locals)
rel = Pathname.new(context.logical_path).parent
data.gsub /url\(['"]?([^\s)]+\.[a-z]+)(\?\d+)?['"]?\)/ do |url|
return url if URI.parse($1).absolute?
@carlhoerberg
carlhoerberg / make_password.sh
Created October 26, 2011 16:12
Make a random password
#!/bin/bash
LANG='C'
cat /dev/urandom|tr -dc "a-zA-Z0-9"|fold -w 64|head
@carlhoerberg
carlhoerberg / .profile
Created December 14, 2011 11:13
Bootstrap a torquebox server
#....
export TORQUEBOX_HOME=/opt/torquebox-current
export JBOSS_HOME=$TORQUEBOX_HOME/jboss
export JRUBY_HOME=$TORQUEBOX_HOME/jruby
export PATH=$JRUBY_HOME/bin:$PATH
export JRUBY_OPTS='--1.9 -J-Xmx64m'
export JAVA_OPTS='-Xmx256m -Xms32m'
require 'rack'
require 'json'
require 'torquebox-messaging'
class EventStream
def self.call(env)
path = Rack::Utils.unescape env["PATH_INFO"]
[200, {
'Content-Type' => 'text/event-stream',
'X-Accel-Buffering' => 'no',
$ jruby -e "require 'uglifier'; Uglifier.compile File.read 'jquery-1.7.1.js'"
java(25487,0x10f18a000) malloc: *** error for object 0x7f9604a05300: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Abort trap: 6
@carlhoerberg
carlhoerberg / nginx.conf
Created January 19, 2012 21:49
Nginx config template
user www-data;
pid /var/run/nginx.pid;
worker_processes 1;
events {
worker_connections 1024; # increase if you have lots of clients
accept_mutex off; # "on" if nginx worker_processes > 1
use epoll; # enable for Linux 2.6+
}
@carlhoerberg
carlhoerberg / app.rb
Created January 26, 2012 20:55
Webrick ssl example
require 'sinatra/base'
require 'openssl'
require 'webrick'
require 'webrick/https'
class App1 < Sinatra::Base
get '/' do
'app1'
end
end
@carlhoerberg
carlhoerberg / gist:1689407
Created January 27, 2012 15:52
github push error
cloudpostgres (monitor)$ git push
Counting objects: 33, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (18/18), done.
Writing objects: 100% (18/18), 2.26 KiB, done.
Total 18 (delta 13), reused 0 (delta 0)
remote: /data/github/current/lib/github/config/resque.rb:27: undefined method `constantize' for "GitHub::Jobs::TransformUserIntoOrg":String (NoMethodError)
remote: from /data/github/current/lib/github/config/resque.rb:26:in `each'
remote: from /data/github/current/lib/github/config/resque.rb:26
remote: from /data/github/current/lib/rock_queue.rb:9:in `require'
@carlhoerberg
carlhoerberg / dm_bug.rb
Created February 1, 2012 21:27
Adding a hash to a DM collection makes two items
require 'dm-core'
DataMapper.setup(:default, 'in_memory::')
class A
include DataMapper::Resource
property :id, Serial
property :jada, String
has n, :bs
end
@carlhoerberg
carlhoerberg / Rails.txt
Created March 31, 2012 11:53
Heroku JRuby Server benchmark
# https://github.com/carlhoerberg/heroku-jruby-example/tree/puma
$ siege -b -c 100 -t 60S http://jruby-puma.herokuapp.com/
Transactions: 42918 hits
Availability: 100.00 %
Elapsed time: 60.18 secs
Data transferred: 3.40 MB
Response time: 0.14 secs
Transaction rate: 713.16 trans/sec
Throughput: 0.06 MB/sec
Concurrency: 98.90