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 / openssl.md
Last active Aug 29, 2015
OpenSSL upgrade instructions
View openssl.md

These are upgrading instructions for the new OpenSSL vulnerability, Heartbleed. This is only for Mac, and assumes you have Homebrew installed.

OpenSSL

You need to upgrade OpenSSL to at least version 1.0.1g.

$ brew update
$ brew upgrade openssl
$ brew link --force openssl
@janko
janko / ldap.rb
Last active Aug 29, 2015
Example Faraday integration with the LDAP protocol, with caching to the database.
View ldap.rb
require "faraday"
module Faraday
class Adapter
class NetLdap < Faraday::Adapter
def call(env)
# LDAP request, and call `save_response(env, status, body, headers)`
@app.call(env)
end
end
@janko
janko / application.rb
Created Jun 7, 2014
Custom error pages in Rails
View application.rb
module MyApp
class Application < Rails::Application
# ...
config.exceptions_app = self.routes
config.action_dispatch.rescue_responses.merge!(
"RDS::ResourceNotFound" => :not_found,
)
# ...
end
@janko
janko / dive.rb
Last active Aug 29, 2015
A script that opens any gem in your EDITOR.
View dive.rb
#!/usr/bin/env ruby
# USAGE: dive GEM_NAME
#
# Opens the lib/ directory of the specified gem in EDITOR. If you're in a Bundler
# project, it will open the locked-down version of the gem.
#
# You can supply only the first few letters of the gem, and the first gem that
# matches will be opened.
@janko
janko / Gemfile
Last active Aug 29, 2015
Specifying dependencies: Java vs Ruby vs Node
View Gemfile
source "https://rubygems.org"
gem "rspec", "~> 3.1"
gem "rspec-rails", "~> 3.1"
@janko
janko / activerecord.rb
Created Apr 4, 2015
Sequel's vritual rows are awesome
View activerecord.rb
Movie.select(
:year,
"ts_headline(title, to_tsquery('#{query}'), 'StartSel = <strong>, StopSel = </strong>, HighlightAll = true') AS title",
"ts_headline(plot, to_tsquery('#{query}'), 'StartSel = <strong>, StopSel = </strong>, HighlightAll = true') AS plot",
"ts_headline(episode, to_tsquery('#{query}'), 'StartSel = <strong>, StopSel = </strong>, HighlightAll = true') AS episode"
)
@janko
janko / benchmark.rb
Last active Aug 29, 2015
Minitest loads *slower* than RSpec?
View benchmark.rb
require "benchmark/ips"
File.write "minitest_test.rb", <<-EOS
require "minitest/autorun"
require "minitest/pride"
class MintestTest < Minitest::Test
def test_foo
assert true
end
@janko
janko / benchmark.rb
Created May 19, 2015
Serialization performance
View benchmark.rb
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|
@janko
janko / 1-models.rb
Created May 27, 2015
Components of good application design (my presentation for a local Ruby meetup)
View 1-models.rb
# 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 / 01-classic.rb
Created May 27, 2015
Controller refactoring (my presentation at a local Ruby meetup)
View 01-classic.rb
#################
# CLASSIC STYLE #
#################
class SessionsController < ApplicationController
# ...
def create
if user = AuthenticateUser.call(params[:username], params[:password])
sign_in!(user)
You can’t perform that action at this time.