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 / 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 / script.rb
Last active Oct 10, 2018
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
janko /
Last active Sep 30, 2018
Java vs Ruby (#1) -- File reading.
// Java
import java.util.BufferedReader;
import java.util.FileReader;
import java.util.IOException;
String content = new String();
try {
BufferedReader reader = new BufferedReader(;
String line;
while ((line = reader.readLine()) != null) {
janko / benchmark.rb
Last active Sep 16, 2018
Benchmarking different ways of filtering by the associated dataset in SQL
View benchmark.rb
require "sequel"
require "benchmark"
system "createdb testing"
DB = Sequel.postgres("testing")
at_exit do
system "dropdb testing"
janko / keyword_arguments.rb
Last active Jul 24, 2018
Ruby keyword arguments advantages and use cases
View keyword_arguments.rb
# 1. Simple assertion of required arguments
# - You can forget #fetch
# - You get a better error, and always on the line where method is defined
def search(options = {})
query = options.fetch(:query)
search() # => KeyError: key not found :query
janko /
Last active May 13, 2018
Simple walkthrough for adding direct (S3) uploads to a Roda & Sequel app with Shrine
janko /
Last active May 4, 2018
Short guide showing how to use checksums when doing direct (S3) uploads using Uppy and Shrine
janko /
Last active May 4, 2018
Simple walkthrough for adding resumable uploads to a Roda & Sequel app with Shrine
View sequel.rb
require "sequel"
DB = Sequel.postgres("arel")
DB.create_table!(:movies) { primary_key :id }
class Movie < Sequel::Model
# Asterisk (I agree this one isn't ideal){count{}.*} # SELECT count(*) FROM "movies"
janko /
Last active Jun 23, 2017
ActiveRecord vs Sequel (require time)
$ brew install cloc
$ bundle install
You can’t perform that action at this time.