Skip to content

Instantly share code, notes, and snippets.

Working from home

Bert Goethals Bertg

Working from home
View GitHub Profile
View performace.rb
def random_bytes
100_000 + rand(128849018880)
require 'benchmark/ips'
file_sizes = { random_bytes }
MEGA_BYTE = 1048576.0
Benchmark.ips do |x|
Bertg / digg_benchmark.rb
Created Jul 8, 2015
Speed test for two digg implementations
View digg_benchmark.rb
module Digg
class Digger
attr_reader :path
def initialize(*path)
@path = path
Bertg / spawn_methods.rb
Created Jan 10, 2014
This version of spawn methods removes the dangerous behaviour where rails 3.2 (after 3.2.13) clobbers conditions.
View spawn_methods.rb
raise "Remove patch after rails 3.2" if Rails.version =~ /\A4/
# copy of lib/active_record/relation/spawn_methods.rb
# Because updating to this version 3.2.16 might change the behaviour of some of our queries,
# we took a copy of this class and remove the behaviour where
module ActiveRecord
module SpawnMethods
def merge(r)
return self unless r
return to_a & r if r.is_a?(Array)
Bertg / Suggestion
Created Aug 13, 2012
I18n Interpolation
View Suggestion
# I18n Interpolation plan
## Introduction
### Inline pluralisation
These propositions different interpolations indicators are used. `%{}'` and `%<{}>` are 2 of them. In this discussion we should focus on the content of these tags. What type of indicators we would be using is more of a compatibility and/or performance question.
#### Value interpolations
Bertg / devise_migration.rb
Created May 11, 2011
Migrating to a new password encryption in devise, coming from authlogic
View devise_migration.rb
class MigrateUserToDevise < ActiveRecord::Migration
def self.up
change_table :users do |t|
t.string :encrypted_password, :null => false, :limit => 128
# ...
def self.down
These are some snips to help you converting video to flash and thumbnails using ruby and paperclip.
Needed: ffmpeg & flvtool, RVideo gem, paperclip
Converting the video is done using outside of paperclip, as this could take quite a while. Paperclip by default does it's conversions during the request, and the last thing you want is a request hanging for 10minutes while ffmpeg does it's thing. It is advised to do this conversion somewhere in the background using Resque or DelayedJob. (make sure not to run to many conversions at one time on your machine)
Most video thumbnailing solutions out there will create all thumbnails from the video. This solution (on paperclip 2.3.0) however will create one large "temp_thumbnail" once and all consequent thumbnails can use this temporary version.
VideoGeometry will make sure that the target dimensions for ffmpeg are always a multiple of 2 and as close as possible to the desired dimensions without breaking the aspect ratio of the original video.
Bertg / flash_session_cookie_middleware.rb
Created Nov 18, 2009
FlashSessionCookieMiddleware with fix for sessions with url encoded tokens
View flash_session_cookie_middleware.rb
You can’t perform that action at this time.