Skip to content

Instantly share code, notes, and snippets.

View Bertg's full-sized avatar
🏠
Working from home

Bert Goethals Bertg

🏠
Working from home
  • Younited
  • Ghent, Belgium
  • 04:04 (UTC +02:00)
View GitHub Profile
@Bertg
Bertg / flash_session_cookie_middleware.rb
Created November 18, 2009 10:43
FlashSessionCookieMiddleware with fix for sessions with url encoded tokens
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
Bertg / devise_migration.rb
Created May 11, 2011 14:05
Migrating to a new password encryption in devise, coming from authlogic
class MigrateUserToDevise < ActiveRecord::Migration
def self.up
change_table :users do |t|
t.string :encrypted_password, :null => false, :limit => 128
# ...
end
end
def self.down
end
@Bertg
Bertg / Suggestion
Created August 13, 2012 09:29
I18n Interpolation
# 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
Bertg / spawn_methods.rb
Created January 10, 2014 13:18
This version of spawn methods removes the dangerous behaviour where rails 3.2 (after 3.2.13) clobbers conditions.
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
Bertg / digg_benchmark.rb
Created July 8, 2015 22:23
Speed test for two digg implementations
module Digg
class Digger
attr_reader :path
def initialize(*path)
@path = path
end
def random_bytes
100_000 + rand(128849018880)
end
require 'benchmark/ips'
file_sizes = 350_000.times.map { random_bytes }
MEGA_BYTE = 1048576.0
Benchmark.ips do |x|