Skip to content

Instantly share code, notes, and snippets.

@wvanbergen
wvanbergen / Decoding speed
Created October 5, 2010 08:56
Chunky PNG performance: same benchmarks on Ruby 1.8.7, but added 'require "oily_png"' for a speed boost
---------------------------------------------
ChunkyPNG (0.10.2) decoding benchmark (n=20)
---------------------------------------------
ChunkyPNG OilyPNG
PNG - no filtering ( 1.056832) ( 0.078345)
PNG - UP filtering ( 3.327986) ( 0.078387)
PNG - PAETH filtering ( 7.499367) ( 0.089143)
From RGBA pixelstream ( 0.032571) ( 0.035790)
@wvanbergen
wvanbergen / convert_innodb_to_per_table_idb.rb
Created August 22, 2010 11:52
Convert InnoDB tables to use a separate idb files instead of the shared, giant ibdata1.
#!/usr/bin/env ruby
# Converts an InnoDB database that uses a shared InnoDB tablespace file (e.g. ibdata1) to use
# a separate file per table.
#
# - First change your my.cnf file to use separate files by adding "innodb_file_per_table" to
# the [mysqld] section. (This is safe: MySQL will revert to the giant file if it cannot find
# the per table file.)
# - Restart the MySQL server
# - cd to the directory of your database (cd /opt/mysql/data/mydb)
@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 / 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 / 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 / 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 / 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 / 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'
---------------------------------------------
ChunkyPNG (0.10.0) encoding benchmark (n=10)
---------------------------------------------
Autodetect (indexed) 0.860000 0.000000 0.860000 ( 0.856220)
:no_compression 0.490000 0.000000 0.490000 ( 0.488724)
:fast_rgba 0.140000 0.000000 0.140000 ( 0.143066)
:fast_rgb 0.140000 0.000000 0.140000 ( 0.143170)
:good_compression 0.470000 0.010000 0.480000 ( 0.476883)
:best_compression 1.880000 0.000000 1.880000 ( 1.877189)
~ $ request-log-analyzer production.log # Analyze production.log
--format custom_file_format.rb # Use custom file format
--reject account_type free # Ignore requests from free accounts
--select locale en-US # Only look at en-US locale requests
--output HTML --file report.html # Generate an HTML report as report.html