Skip to content

Instantly share code, notes, and snippets.

View janko's full-sized avatar

Janko Marohnić janko

View GitHub Profile
@janko
janko / activerecord.md
Last active May 7, 2016 11:33
Response to http://bikeshed.fm/56 regarding "ActiveRecord is Reinventing Sequel"

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

@janko
janko / 01-intro.md
Last active March 20, 2016 21:02
Yaks demonstration on the local Ruby meetup

API

  • You sometimes need to create an API

    • You want frontend and backend separate
    • You need REST API alongside the web app (GitHub, DNSimple, Travis)
  • JSON API specifications

@janko
janko / activerecord.rb
Created November 13, 2012 17:02
Eliminate need for class eval
# lib/carrierwave/orm/activerecord.rb from jnicklas/carrierwave
# before
class_eval <<-RUBY, __FILE__, __LINE__+1
def #{column}=(new_file)
column = _mounter(:#{column}).serialization_column
send(:"\#{column}_will_change!")
super
end
@janko
janko / presentation.rb
Created May 27, 2015 23:05
Advanced Regex features in Ruby (my presentation from our local Ruby meetups)
############
# GROUPING #
############
def Given(*) end
Given(/There (is|are) some links?/) { } # ERROR
Given(/There (?:is|are) some links?/) { }
@janko
janko / 01.rb
Created May 27, 2015 22:54
Capabilities of the "mail" gem, without ActionMailer (my presentation from our local Ruby meetups)
require "mail"
Mail.defaults do
delivery_method :smtp,
address: "smtp.gmail.com",
port: 587,
user_name: ENV["GMAIL_EMAIL"],
password: ENV["GMAIL_PASSWORD"],
authentication: "plain",
end
@janko
janko / 01-intro.md
Last active August 29, 2015 14:22
Dynamic eager loading in JSON APIs (my presentation from our local Ruby meetups)

Dynamic eager loading

  • Static: User.includes(:posts => :comments)

  • Dynamic: :posts => :comments is a product of user's input

Where did I need this?

@janko
janko / 01-before.rb
Created May 27, 2015 22:41
Double dispatch in Ruby example (my presentation at a local Ruby meetup)
module SocialPresenter
# ...
class Twitter < Struct.new(:object)
def message
case object
when String
@janko
janko / 01-classic.rb
Created May 27, 2015 22:38
Controller refactoring (my presentation at a local Ruby meetup)
#################
# CLASSIC STYLE #
#################
class SessionsController < ApplicationController
# ...
def create
if user = AuthenticateUser.call(params[:username], params[:password])
sign_in!(user)
@janko
janko / 1-models.rb
Created May 27, 2015 17:50
Components of good application design (my presentation for a local Ruby meetup)
# 1. Models (Entities)
#
# * The nouns of your business logic
# * Usually persisted in the database
# * Usually contain validations
# * Usually expose associations with other models
# * Usually have scopes (to encapsulate the query logic)
################
# ActiveRecord #
@janko
janko / benchmark.rb
Created May 19, 2015 23:17
Serialization performance
gem "active_model_serializers", "0.10.0.rc1"
require "yaks"
require "active_record"
require "active_model_serializers"
require "benchmark/ips"
ActiveRecord::Base.establish_connection(adapter: "postgresql", database: "testing")
ActiveRecord::Schema.define do
create_table :users, force: true do |t|