Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@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
@carlhoerberg
carlhoerberg / instructions.md
Last active January 7, 2017 22:06
How to see Netflix on a Chromecast abroad by tethering and redirecting all DNS traffic in OS X

Chromecast always uses Google's DNS servers so you can't just change DNS server on your local network, you have to redirect all DNS requests to another server. This guide will help you do so with a OS X computer and a phone.

Requirements for this guide:

  • Phone with tethering
  • OS X >=10.9
  • unblock-us.com or another DNS resolver

Steps:

  1. Tethering your computer through your phone, eg. connect to your wifi, and tether with USB.
#!/usr/bin/env ruby
require 'bunny'
require 'securerandom'
conn = Bunny.new
conn.start
class FibonacciClient
def initialize(conn, server_queue)
ch = conn.create_channel
@carlhoerberg
carlhoerberg / castle.rb
Last active March 30, 2016 12:25
Castle.io integration
require 'net/https'
require 'json'
class Castle
def self.api_key=(api_key)
@@api_key = api_key
end
# Usage
# Sinatra:
@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]
@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");
}
@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 / 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 / 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 / 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'