Skip to content

Instantly share code, notes, and snippets.

Janko Marohnić janko

Block or report user

Report or block janko

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
janko / application_controller.rb
Last active Oct 31, 2019
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 Aug 24, 2019
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-safe-download.rb
Last active Jul 24, 2019
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 =
janko /
Last active Jun 6, 2019
PostgreSQL full-text search capabilites (my presentation from our local Ruby meetup)

Full-text search

  • Keywords

  • Typos

  • Stemming

  • Stopword ignore

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 / 1-activerecord.rb
Last active Jan 24, 2019
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 / 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 /
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 / 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 / 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
You can’t perform that action at this time.