Skip to content

Instantly share code, notes, and snippets.

$ 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
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',
@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'
@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 / 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 / gist:1146796
Created August 15, 2011 13:50
Optional validation
[HttpPost]
public ActionResult Create(int id, Projekt model)
{
var p = db.Get<Projekt>(id);
if (p.Typ1Validering)
if (string.IsNullOrEmpty(model.Field))
ModelState.AddModelError("Field", "Fältet får inte vara tomt");
if (ModelState.IsValid)
{
@carlhoerberg
carlhoerberg / Rakefile.rb
Created May 17, 2011 19:33
How to do automatic backup with Heroku PGBackups and Heroku Cron. http://carlhoerberg.com/automatic-backup-of-heroku-database-to-s3
require 'aws/s3'
require 'heroku'
require 'heroku/command'
require 'heroku/command/auth'
require 'heroku/command/pgbackups'
task :cron do
class Heroku::Auth
def self.client
Heroku::Client.new ENV['heroku_login'], ENV['heroku_passwd']
@carlhoerberg
carlhoerberg / gist:976228
Created May 17, 2011 09:59
How to list DataMapper enum options
class Entity
include DataMapper::Resource
property :enum_property, Enum[:a, :b, :c]
end
Entity.enum_property.options[:flags] #=> [:a, :b, :c]
# or
Entity.enum_property.flag_option.values #=> [:a, :b, :c]
public class AutocompleteController : Controller
{
private readonly IRepository db;
public AutocompleteController(IRepository db)
{
this.db = db;
}
public JsonResult Users(string term)
{
@carlhoerberg
carlhoerberg / Global.asax.cs
Created April 5, 2011 07:12
Replace log4net replacement for Elmah
protected void Application_Error(object sender, EventArgs e)
{
var error = Server.GetLastError();
var log = LogManager.GetLogger(GetType());
var msg = string.Format("\r\nPath: {0}\r\nMethod: {4}\r\nUser: {1}\r\nForm: {2}\r\nReferer: {3}",
Request.Url,
User.Identity.Name,
Request.Form,
Request.UrlReferrer,
Request.HttpMethod);