Skip to content

Instantly share code, notes, and snippets.

@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: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)
{
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 / 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 / multi-em-http.rb
Created April 17, 2012 15:00
Concurrent HTTP requests with EventMachine
require 'eventmachine'
require 'em-http-request'
# Reference:
# https://github.com/igrigorik/em-http-request/wiki/Parallel-Requests
# http://rdoc.info/github/eventmachine/eventmachine/master/EventMachine/Iterator
urls = ['http://www.google.com', 'http://www.cloudamqp.com']
@carlhoerberg
carlhoerberg / Gemfile
Created May 30, 2013 07:58
Simple redirect app with Ruby Rack
source 'https://rubygems.org'
gem 'rack'
gem 'puma'
@carlhoerberg
carlhoerberg / QuerableExtensions.cs
Created August 25, 2010 15:17
Dynamic LINQ OrderBy extension method
public static class QuerableExtensions
{
public static IOrderedQueryable<T> OrderBy<T>(this IQueryable<T> source, string property, bool asc)
{
return ApplyOrder<T>(source, property, asc ? "OrderBy" : "OrderByDescending");
}
public static IOrderedQueryable<T> OrderBy<T>(this IQueryable<T> source, string property)
{
return ApplyOrder<T>(source, property, "OrderBy");
}