Skip to content

Instantly share code, notes, and snippets.

View janko's full-sized avatar

Janko Marohnić janko

View GitHub Profile
@janko
janko / benchmark.rb
Last active September 16, 2018 23:01
Benchmarking different ways of filtering by the associated dataset in SQL
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 July 24, 2018 08:34
Ruby keyword arguments advantages and use cases
####
# 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 09:53
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 20:33
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 20:32
Simple walkthrough for adding resumable uploads to a Roda & Sequel app with Shrine
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 / 0-gemfile.rb
Created July 31, 2016 11:24
Using Shrine with ROM and dry-rb
source "https://rubygems.org"
gem "shrine", github: "janko-m/shrine"
gem "rom-repository"
gem "rom-sql"
gem "sqlite3"
gem "dry-validation"
gem "roda"
gem "sucker_punch", "~> 2.0"
@janko
janko / carrierwave.rb
Created October 31, 2013 22:03
Paperclip vs CarrierWave
class ImageQuestion < TextQuestion
store :data, accessors: [:image]
mount_uploader :image, ImageUploader
validates :image, download: true, processing: true
end
class ImageUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
@janko
janko / concatenation.rb
Last active September 8, 2016 03:14
Concatenation plugin for Shrine
class Shrine
module Plugins
# The `concatenation` plugin allows you to assign to the attacher a
# cached file which is composed of multiple uploaded parts. The plugin
# will then call `#concat` on the storage, which is expected to
# concatenate the given parts into a single file. The assigned
# attachment will then be a complete cached file.
#
# plugin :concatenation
#
@janko
janko / 01.md
Created May 27, 2015 23:07
The Roda Ruby framework (my presentation on our local Ruby meetups)

Roda

  • Web framework (on top of Rack)

  • Forked from Cuba

  • Core + Plugins

    • Core: 440 LOC
  • Total: 3200 LOC