Skip to content

Instantly share code, notes, and snippets.

View jodosha's full-sized avatar

Luca Guidi jodosha

View GitHub Profile
@jodosha
jodosha / lotus-faq.md
Last active August 29, 2015 13:56
Lotus FAQs

Lotus::Router

Why Lotus::Router uses internally http_router?

Because I consider http_router like an excellent low level adapter. I needed to start with a certain degree of code maturity, and build on top of it the public API that I wanted for Lotus.

Lotus::Utils

What's the purpose of Lotus::Utils?

@jodosha
jodosha / index.html
Last active August 29, 2015 13:56
Limit endless page loading, by wrapping long running functions invocation in a setTimeout. Run with `bash server.sh`.
<!DOCTYPE html>
<html>
<head>
<script>window.PROFILER||(PROFILER={});PROFILER.data={start:(new Date).getTime()}</script>
<script src="http://code.jquery.com/jquery-2.1.0.min.js"></script>
<title>JS Timeout</title>
</head>
<body>
<div id="loaded"></div>
<div id="long-running"></div>
@jodosha
jodosha / benchmark.rb
Last active August 29, 2015 13:57
Ruby's benchmark for regular expressions: Hash#find vs multiple case statement
#!/usr/bin/env ruby
require 'benchmark'
TIMES = (ENV['TIMES'] || 1_000_000).to_i
ENDPOINT = ->(env) { [200, {}, ['Hello, World!']] }
ROUTES = {
# '/articles(.:format)'
/\A\/articles(?-mix:[\.]*(?<format>[a-z0-9_]*))\z/ => ENDPOINT,
# '/accounts/:account_id/people/:id'
@jodosha
jodosha / Gemfile
Created March 15, 2014 13:22
Rack map vs Lotus::Router performance
source 'https://rubygems.org'
ruby '2.1.1'
gem 'lotus-router' # github: 'lotus/router', branch: 'engine-rewriting'
gem 'puma'
@jodosha
jodosha / lotus_presenter.rb
Last active August 29, 2015 13:57
A Lotus::View sneak peek: Lotus::Presenter
module Lotus
module Presenter
def initialize(object)
@object = object
end
protected
def method_missing(m, *args, &blk)
if @object.respond_to?(m)
@object.__send__ m, *args, &blk
@jodosha
jodosha / include_controller.rb
Created March 18, 2014 10:07
Ruby's include tweaks for Lotus::Controller
# Coded for:
# https://github.com/lotus/controller/pull/7
module Lotus
module Controller
module Dsl
def self.included(base)
base.extend ClassMethods
end
@jodosha
jodosha / lotus_controller.rb
Last active August 29, 2015 13:57
Instance configuration vs global configuration
# This is a simplified version of Lotus::Controller
# Problem:
#
# Global configurations are handy both for framework authors and for developers.
# However, they make hard using the same library twice in the same Ruby process.
# Solution constraints:
#
# 1. It should offer a DSL to developers
source 'https://rubygems.org'
gem 'tilt', github: 'jodosha/tilt', branch: 'prefer-erb-over-erubis'
module MegaLotto
class Configuration
attr_accessor :drawing_count
def initialize
@drawing_count = 6
end
end
class Drawing
@jodosha
jodosha / application.rb
Last active August 29, 2015 13:59
Use sessions in Lotus::Action. In response of https://gist.github.com/sidonath/10450111
require 'lotus/controller'
module Blog
module Action
def self.included(base)
base.class_eval do
include Lotus::Action
include Lotus::Action::Session
end
end