Skip to content

Instantly share code, notes, and snippets.


Janko Marohnić janko

View GitHub Profile
janko / results
Last active Mar 31, 2021
MiniMagick vs libvips benchmark (generating a 500x500 thumbnail)
View results
width, imagemagick, libvips
1000, 0.129, 0.045
1500, 0.190, 0.067
2000, 0.276, 0.054
2500, 0.380, 0.068
3000, 0.498, 0.085
janko / 01-activerecord.rb
Created May 27, 2015
PostgreSQL JSON querying in Sequel (my presentation from our local Ruby meetup)
View 01-activerecord.rb
require "active_record"
ActiveRecord::Migration.verbose = false
ActiveRecord::Migration.class_eval do
create_table :played_quizzes, force: true do |t|
t.integer :player_ids, array: true
t.json :quiz_snapshot
janko / 01-safe-download.rb
Last active Dec 20, 2020
A safe way in Ruby to download a file to disk using open-uri (with/without comments)
View 01-safe-download.rb
require "open-uri"
require "net/http"
Error =

Keybase proof

I hereby claim:

To claim this, I am signing this object:

janko / Gemfile
Last active Nov 1, 2020
Benchmark measuring execution time and memory allocation of different strategies of inserting many records in Sequel – 1a) individual insert, 1b) individual prepared insert, 2a) bulk insert, 2b) batched bulk insert, and 3) database insert
View Gemfile
source ""
gem "sequel"
gem "pg"
gem "sequel_pg"
gem "memory_profiler"
janko / 1-activerecord.rb
Last active Sep 25, 2020
INSERTing 50,000 records into a database in ActiveRecord, Arel, SQL, activerecord-import and Sequel.
View 1-activerecord.rb
require "active_record"
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
ActiveRecord::Migration.class_eval do
create_table(:records) do |t|
t.string :column
data = { |i| Hash[column: "Column #{i}"] }
janko / arel.rb
Created Jul 28, 2015
Insert statement in Arel
View arel.rb
require "active_record"
insert =
insert.relation =
insert.columns = { |k|[k] }
insert.values =, insert.columns)
janko / benchmark.rb
Last active Sep 11, 2020
Comparing performance of Sequel and Active Record when fetching 1000 records
View benchmark.rb
require "bundler/inline"
gemfile do
source ""
gem "activerecord", "", require: "active_record"
gem "sequel", "5.36"
gem "sequel_pg", "1.13.0", require: false
gem "pg", "1.2.3"
gem "mysql2", "0.5.3"
janko / Gemfile
Created May 31, 2018
Memory profiling of http.rb and other popular Ruby HTTP client libraries
View Gemfile
source ""
gem "roda"
gem "http", "~> 3.3"
gem "rest-client"
gem "httparty"
janko / script.rb
Last active Apr 30, 2020
Workaround for embedded documents in shrine-mongoid
View script.rb
require "mongoid"
require "shrine"
require "shrine/storage/memory"
require "stringio"
Mongoid.configure do |config|
config.clients.default = { hosts: ['localhost:27017'], database: 'my_db' }
config.log_level = :debug