Skip to content

Instantly share code, notes, and snippets.

View mpouleijn's full-sized avatar

Michel Pouleijn mpouleijn

View GitHub Profile
@mpouleijn
mpouleijn / gist:5d0d8f2a1a5e46f2875e
Last active September 4, 2015 08:32 — forked from jordelver/gist:3139365
How to write an image file to an SD card under Mac OS X (for Raspberry Pi)

Find the SD card device

In this case, the SD card is /dev/disk4. DO NOT get this wrong or you may destroy all the data on the wrong disk/card/drive.

diskutil list

/dev/disk0
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *160.0 GB   disk0

1: EFI 209.7 MB disk0s1

# code inspired from http://jainmarket.blogspot.com/2009/05/creating-custom-table-view-cell.html
class CustomCell < UITableViewCell
attr_accessor :primaryLabel
attr_accessor :secondaryLabel
def createLabels
@primaryLabel = UILabel.alloc.init
require 'router'
use Rack::CommonLogger
use Rack::ShowExceptions
use Rack::Lint
use Rack::Static, :urls => ["/static"]
run Router.new
@mpouleijn
mpouleijn / gist:2575613
Created May 2, 2012 09:48 — forked from stympy/gist:948168
Trace slow queries in Rails
class QueryTracer < ActiveSupport::LogSubscriber
ACCEPT = %r{^(app|config|lib)}.freeze
FRAMES = 5
THRESHOLD = 300 # In ms
def sql(event)
return unless event.duration > THRESHOLD
callers = Rails.
backtrace_cleaner.
@mpouleijn
mpouleijn / rvm2rbenv.txt
Created April 16, 2012 09:54 — forked from brentertz/rvm2rbenv.txt
Switch from RVM to RBENV
## Prepare ###################################################################
# Remove RVM
rvm implode
# Ensure your homebrew is working properly and up to date
brew doctor
brew update
## Install ###################################################################
@mpouleijn
mpouleijn / minitest_spec_expectations.md
Created March 16, 2012 15:52 — forked from ordinaryzelig/minitest_spec_expectations.md
How to write MiniTest::Spec expectations

I'm a fan of MiniTest::Spec. It strikes a nice balance between the simplicity of TestUnit and the readable syntax of RSpec. When I first switched from RSpec to MiniTest::Spec, one thing I was worried I would miss was the ability to add matchers. (A note in terminology: "matchers" in MiniTest::Spec refer to something completely different than "matchers" in RSpec. I won't get into it, but from now on, let's use the proper term: "expectations").

Understanding MiniTest::Expectations

Let's take a look in the code (I'm specifically referring to the gem, not the standard library that's built into Ruby 1.9):

# minitest/spec.rb

module MiniTest::Expectations
@mpouleijn
mpouleijn / datastaxCommunity.bash
Created March 6, 2012 07:57 — forked from cmaxw/datastaxCommunity.bash
DataStax Community install script
#!/bin/bash
# Use Oracle Sun Java
wget http://javadl.sun.com/webapps/download/AutoDL?BundleId=59621
mv AutoDL?BundleId=59621 jre-6u31-linux-i586.bin
sudo mkdir -p /opt/java/32
sudo mv ./jre-6u31-linux-i586.bin /opt/java/32
sudo chmod 755 /opt/java/32/jre-6u31-linux-i586.bin
cd /opt/java/32
sudo ./jre-6u31-linux-i586.bin
@mpouleijn
mpouleijn / anonymizer_source.rake
Created February 24, 2012 15:08 — forked from adarsh/anonymizer_source.rake
Code from blog post on anonymizing sensitive user data
task :env_checker do
unless Rails.env.development?
puts "Not in development environment, exiting!"
exit 1
end
end
namespace :app_name do
desc 'Anonymize user, company, and location information'
task :anonymize => [:environment, :env_checker] do
@mpouleijn
mpouleijn / slide1.rb
Created February 16, 2012 13:24
Evented Sinatra
## Eventmachine
# Non-blocking I/O event loop in Ruby
# Lots of extensions that support MySQL, AMPQ, Redis, Memcache, etc.
# Suffers from callback hell (like node.js)
# Easy to start with
require 'eventmachine'
require 'em-http-request'
EventMachine.run {
@mpouleijn
mpouleijn / etc_init.d_unicorn_example.co.uk
Created February 13, 2012 22:07 — forked from scottlowe/etc_init.d_unicorn_example.co.uk
Ruby on Rails server setup on Ubuntu 11.04 with Nginx, Unicorn, Rbenv
#! /bin/bash
### BEGIN INIT INFO
# Provides: unicorn
# Required-Start: $local_fs $remote_fs $network $syslog
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the unicorn web server
# Description: starts unicorn