Skip to content

Instantly share code, notes, and snippets.

View janko's full-sized avatar

Janko Marohnić janko

View GitHub Profile
@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-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.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 / 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 / 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 / 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.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.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
@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 / 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