Skip to content

Instantly share code, notes, and snippets.

@wvanbergen
wvanbergen / shell session
Created November 29, 2010 16:32
Wasn't bundler supposed to resolve issues like these?
$ bundle install
[ ... ]
Your bundle is complete! It was installed into /Users/willem/.rvm/gems/ruby-1.9.2-p0
$ rails s
/Users/willem/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb:238:in `activate': can't activate i18n (~> 0.4.1, runtime) for ["mail-2.2.10", "actionmailer-3.0.3", "rails-3.0.3"], already activated i18n-0.5.0 for ["activemodel-3.0.3", "actionpack-3.0.3", "rails-3.0.3"] (Gem::LoadError)
from /Users/willem/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb:254:in `block in activate'
from /Users/willem/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb:253:in `each'
from /Users/willem/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb:253:in `activate'
@wvanbergen
wvanbergen / transfer
Created July 28, 2011 21:12
Script to transfer a database table quickly without temporary files
#!/bin/sh
# Modify the source and target variables, and run:
# $./transfer table_name
# Note that this will only run on the same machine as the target MySQL server machine.
SOURCE_MYSQL_HOST=
SOURCE_MYSQL_PORT=
SOURCE_MYSQL_USERNAME=
@wvanbergen
wvanbergen / message_verifier.coffee
Created September 15, 2011 20:37
MessageVerifier implementation for node.js
crypto = require 'crypto'
MessageVerifier =
serializer: JSON.stringify
deserializer: JSON.parse
generate: (data, secret, algorithm) ->
algorithm ?= 'sha1'
base64 = (new Buffer(MessageVerifier.serializer(data))).toString('base64')
@wvanbergen
wvanbergen / inventory_serials.rb
Created November 16, 2011 05:13
Get the computer and display serial numbers for your Mac
require 'yaml'
data = YAML.load(`system_profiler SPHardwareDataType SPDisplaysDataType`)
puts "Computer serial number: " + data['Hardware']['Hardware Overview']['Serial Number (system)']
data['Graphics/Displays'].each do |video_card, properties|
if properties['Displays']
properties['Displays'].each do |display_name, properties|
puts "#{display_name}: #{properties['Display Serial Number']}" if display_name =~ /Cinema/
@wvanbergen
wvanbergen / png_properties.rb
Created May 24, 2012 08:14
Extract properties from PNG file.
require 'chunky_png'
filename = 'image.png'
img = ChunkyPNG::Datastream.from_file(filename)
# The header chunk contains the information you are looking for
p img.header_chunk
# => #<ChunkyPNG::Chunk::Header:0x007fb3858a50f8 @type="IHDR", @width=8, @height=8, @depth=8, @color=3, @compression=0, @filtering=0, @interlace=1>
puts img.header_chunk.depth # bit depth per color channel, e.g. 8 (i.e. 24 bits for RGB, 32 bits for RGBA)
@wvanbergen
wvanbergen / gist:3510208
Created August 29, 2012 10:38
Travis build exception
1Using worker: ruby3.worker.travis-ci.org:ruby-3
2
3
4
5
6I'm sorry but an error occured within Travis while running your build.
7
8We are continuosly working on test run stability, please email support@travis-ci.org if this error persists.
9
10Below is the stacktrace of the error:
@wvanbergen
wvanbergen / bitwise.rb
Last active August 29, 2015 13:56
0xabc to 0xaabbcc using bitwise operators
# There must be a nicer way than this
((x & 0xf00) << 12 | (x & 0xf00) << 8) |
((x & 0x0f0) << 8 | (x & 0x0f0) << 4) |
((x & 0x00f) << 4 | (x & 0x00f))
@wvanbergen
wvanbergen / Makefile
Last active August 29, 2015 14:19
Makefile to install and run the confluent inc platform for CI purposes.
.PHONY: confluent/kafka/* confluent/zookeeper/* confluent/registry/* confluent/start confluent/stop
# Confluent platform tasks
confluent/start: confluent/rest/start
confluent/stop: confluent/rest/stop confluent/registry/stop confluent/kafka/stop confluent/zookeeper/stop
# Download & extract tasks
____ ____ ____ _______
| | | _/
| | | \o/ _/
| | | | _/
| | ==> | /\/
| o | | _/
| |- | | _/
|_/\_| |____/