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 / walkthrough-app.md
Last active May 13, 2018
Simple walkthrough for adding direct (S3) uploads to a Roda & Sequel app with Shrine
@janko
janko / concatenation.rb
Last active Sep 8, 2016
Concatenation plugin for Shrine
View concatenation.rb
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 / 0-gemfile.rb
Created Jul 31, 2016
Using Shrine with ROM and dry-rb
View 0-gemfile.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 / activerecord.md
Last active May 7, 2016
Response to http://bikeshed.fm/56 regarding "ActiveRecord is Reinventing Sequel"
View activerecord.md

Hey Sean,

I just encountered your "The Bike Shed" podcast, concretely number #56 where you were talking about the "ActiveRecord is Reinventing Sequel" post I wrote. I'm sorry that this post struck you as negative, and that it made you feel like I was attacking you. I admit that I did feel some negative energy while I was writing it, but I still felt like I needed to say it.

Firstly, you said in the podcast that you would like to read an article which shows parts where Sequel is better than ActiveRecord. However, I did link my previous "Ode to Sequel" post in the first paragraph of my post, and soon after added two more. So I think it's a bit unfair that I was pr

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 / 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
end
end
data = 50_000.times.map { |i| Hash[column: "Column #{i}"] }
@janko
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 = Class.new(StandardError)
DOWNLOAD_ERRORS = [
SocketError,
OpenURI::HTTPError,
RuntimeError,
URI::InvalidURIError,
@janko
janko / arel.rb
Created Jul 28, 2015
Insert statement in Arel
View arel.rb
require "active_record"
ActiveRecord::Base.establish_connection("postgres:///db")
insert = Arel::Nodes::InsertStatement.new
insert.relation = Arel::Table.new(:movies)
insert.columns = hash.keys.map { |k| Arel::Table.new(:movies)[k] }
insert.values = Arel::Nodes::Values.new(hash.values, insert.columns)
ActiveRecord::Base.connection.execute(insert.to_sql)
@janko
janko / 01-requirements.md
Last active Jun 23, 2017
ActiveRecord vs Sequel (require time)
View 01-requirements.md
$ brew install cloc
$ bundle install
@janko
janko / 01.md
Created May 27, 2015
The Roda Ruby framework (my presentation on our local Ruby meetups)
View 01.md

Roda

  • Web framework (on top of Rack)

  • Forked from Cuba

  • Core + Plugins

    • Core: 440 LOC
    • Total: 3200 LOC
You can’t perform that action at this time.