Skip to content

Instantly share code, notes, and snippets.

View vmoravec's full-sized avatar

Vladimir Moravec vmoravec

View GitHub Profile
@vmoravec
vmoravec / Gemfile
Created September 13, 2012 18:14
Rails Lightweight Stack. Most of this is detailed on Crafting Rails Applications - http://pragprog.com/book/jvrails/crafting-rails-applications
source :rubygems
# We are not loading Active Record, nor Active Resources etc.
# We can do this in any app by simply replacing the rails gem
# by the parts we want to use.
gem "actionpack", "~> 3.2"
gem "railties", "~> 3.2"
gem "tzinfo"
# Let's use thin
@vmoravec
vmoravec / i18n.coffee
Created October 31, 2012 14:56 — forked from madrobby/i18n.coffee
Backbone i18n with CoffeeScript
# before this file is loaded, a locale should be set:
#
# In a browser environment, you can use:
# ```<script>__locale='en';</script>```
#
# In a server environment (specifically node.js):
# ```global.__locale = 'en';```
# normalize in-app locale string to "en" or "de-AT"
parts = @__locale.split('-')
@vmoravec
vmoravec / chat.rb
Created December 4, 2012 18:50 — forked from rkh/chat.rb
Simple Chat Application using the Sinatra Streaming API
# coding: utf-8
require 'sinatra'
set server: 'thin', connections: []
get '/' do
halt erb(:login) unless params[:user]
erb :chat, locals: { user: params[:user].gsub(/\W/, '') }
end
get '/stream', provides: 'text/event-stream' do
# This is a possible approach to baking in side-effect free support into
# the context object for DCI. The #on_call would support a declarative way of
# knowing which roles to mixin/unmix on a given object. This could
# use something like mixology or another implementation under the covers.
class AddToCartContext < Context
attr_reader :user, :book
def self.call(user, book)
AddToCartContext.new(user, book).call
# ---role
module BookManager
def create_book(attrs)
self.books.create! attrs
end
def update_book(book_id,attrs)
book = self.books.find(book_id)
book.update_attributes attrs
namespace :gemfile do
desc "filters the gemfile, leaving only gems belonging to specific groups"
task :filter => :environment do
groups = (ENV['groups'] || "").split(',')
if groups.empty?
puts "! Invalid usage"
puts
puts "Please specify the groups you want to filter. Example:"
class RPMSpec
attr_reader :spec
def initialize(spec)
@tags = Hash.new {|h,k| h[k] = []}
@defines = {}
@spec = spec
@sections = Hash.new {|h,k| h[k] = []}
#@rpm_build_dir = rpm_build_dir

I'm a fan of MiniTest::Spec. It strikes a nice balance between the simplicity of TestUnit and the readable syntax of RSpec. When I first switched from RSpec to MiniTest::Spec, one thing I was worried I would miss was the ability to add matchers. (A note in terminology: "matchers" in MiniTest::Spec refer to something completely different than "matchers" in RSpec. I won't get into it, but from now on, let's use the proper term: "expectations").

Understanding MiniTest::Expectations

Let's take a look in the code (I'm specifically referring to the gem, not the standard library that's built into Ruby 1.9):

# minitest/spec.rb

module MiniTest::Expectations

TL;DR

Unicorn was by far the best performing (5.94 trans/sec over the 1-minute test, 352 total). Puma (3.95 trans/sec, 235 total) appeared to perform no better than Webrick, despite the default behavior of using up to 16 threads. Perhaps increasing its worker count to the number of cores will improve its performance.

I've tried to run multiple Puma workers with the workers directive (per their sample documentaiton), but I receive errors about undefined method 'workers' for #<Puma::Configuration::DSL:0x007ffca4bde798>).

Webrick

Server

$ bundle exec rails server

@vmoravec
vmoravec / spark.rb
Created September 4, 2013 21:44 — forked from jcromartie/spark.rb
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
# prints a sparkline in the terminal using the supplied list of numbers
# examples:
# spark.rb 10 20 30 100 90 80
# spark.rb 1 2 0.4 0.1 1.3 0.7
@ticks = %w[▁ ▂ ▃ ▄ ▅ ▆ ▇]
values = ARGV.map { |x| x.to_f }