Skip to content

Instantly share code, notes, and snippets.


Janko Marohnić janko

View GitHub Profile

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 / 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 / shrine-cli.rb
Created Mar 24, 2020
The CLI I wrote for creating new AWS S3 buckets for reproducing issues reported for Shrine. It's can serve as an example for programmatically creating new S3 buckets with bucket-specific credentials.
View shrine-cli.rb
#!/usr/bin/env ruby
require "dry/cli"
require "aws-sdk-s3"
require "aws-sdk-iam"
require "json"
janko / application_controller.rb
Last active May 8, 2021
Simpler implementation of ActionController::Live
View application_controller.rb
class ApplicationController < ActionController::Base
def stream_body(async: false, **options, &block)
self.status ||= 200
self.headers["Cache-Control"] = "no-cache"
stream_class = async ? AsyncStream : Stream
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 / script.rb
Last active Jan 25, 2019
Ruby operator coercion inconsistency
View script.rb
Value = do
def coerce(other)
puts "called #{self}#coerce(#{other.inspect})"
[, self]
def +(other)
puts "called #{self} + #{other.inspect}"
janko /
Last active Nov 18, 2018
Plans for the new derivate_endpoint Shrine plugin

Derivate Endpoint

Derivate blocks are executed in context of the uploader instance:

class ImageUploader < Shrine
  plugin :derivate_endpoint

  derivate :thumbnail do |file, context|
janko / script.rb
Created Oct 29, 2018
Zip unpacking with Shrine while retaining the same directory structure
View script.rb
require "sequel"
require "shrine"
require "shrine/storage/memory"
require "zip"
require "tempfile"
require "securerandom"
DB = Sequel.sqlite
DB.create_table :archives do
primary_key :id
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