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
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::Base.establish_connection('postgres:///testing')
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
end
@janko
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
end
@janko
janko / file_reading.java
Last active Sep 30, 2018
Java vs Ruby (#1) -- File reading.
View file_reading.java
// Java
import java.util.BufferedReader;
import java.util.FileReader;
import java.util.IOException;
String content = new String();
try {
BufferedReader reader = new BufferedReader(FileReader.new(filename));
String line;
while ((line = reader.readLine()) != null) {
@janko
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
DB.disconnect
system "dropdb testing"
end
@janko
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)
end
search() # => KeyError: key not found :query
@janko
janko / walkthrough-app.md
Last active May 13, 2018
Simple walkthrough for adding direct (S3) uploads to a Roda & Sequel app with Shrine
@janko
janko / shrine-uppy-checksum.md
Last active May 4, 2018
Short guide showing how to use checksums when doing direct (S3) uploads using Uppy and Shrine
@janko
janko / walkthrough-resumable.md
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
end
# Asterisk (I agree this one isn't ideal)
Movie.select{count{}.*} # SELECT count(*) FROM "movies"
@janko
janko / 01-requirements.md
Last active Jun 23, 2017
ActiveRecord vs Sequel (require time)
View 01-requirements.md
$ brew install cloc
$ bundle install
You can’t perform that action at this time.