Skip to content

Instantly share code, notes, and snippets.

View mguterl's full-sized avatar

Mike Guterl mguterl

View GitHub Profile

Which do you prefer and why?

Task contains enqueue_at an optional attribute that defines when (hour and minute) the job should be enqueued. If the attribute is not present, the current time should be used.

# tasks (id INT, enqueue_at DATETIME, action VARCHAR(255))
class Task < ActiveRecord::Base
end
class TripsController < ApplicationController
class Action < ApplicationController::Action
end
class New < Action
expose(:trip) { Trip.new(params[:trip]) }
end
class Create < New
def call
module Upsertable
def upsert_added!
@upsert_added = true
end
def upsert_added?
@upsert_added
end
def upsert_updated!
@mguterl
mguterl / latency.txt
Created February 12, 2013 12:42 — forked from jboner/latency.txt
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns
Send 1K bytes over 1 Gbps network 10,000 ns 0.01 ms
Read 4K randomly from SSD* 150,000 ns 0.15 ms
require "net/http"
module Blocking
module Sunspot
class Server < ::Sunspot::Rails::Server
def start
@started = Time.now
@mguterl
mguterl / newrelic_outline.mkd
Created September 12, 2012 19:36 — forked from queso/newrelic_outline.mkd
New Relic Outline

Don't be blind when making adjustments for performance. Measure, measure, measure.

Overview

New Relic is a great product for monitoring the peformance of your application. They provide performance management for Ruby, PHP, .Net, Java and Python. Today's presentation is going to focus on Ruby and specifically Rails, however, the basic New Relic overview will be applicable to any of the platforms mentioned. Integrating New Relic into your Rails application is as easy as signing up and adding the gem to your Rails application's Gemfile.

Apdex

When measuring performance in the browser or on the server New Relic provides Apdex scores. Apdex is

{{bd-back-button action='goBack'}}
# Syntax highlighting for pre/code blocks
require 'rack/pygmoku'
use Rack::Pygmoku, :lexer_attr => 'lang'
# Workaround https://github.com/heroku/heroku-buildpack-python/issues/5
RubyPython.configure :python_exe => 'python2.6'
require "net/http"
module Sunspot
class BlockingServer < ::Sunspot::Rails::Server
def start
@started = Time.now
super
up
rescue ::Sunspot::Server::AlreadyRunningError
# do nothing
@mguterl
mguterl / .rvmrc
Created February 21, 2012 23:19 — forked from st23am/urinal_etiquette.rb
Test Problem
#!/usr/bin/env bash
# This is an RVM Project .rvmrc file, used to automatically load the ruby
# development environment upon cd'ing into the directory
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
# Only full ruby name is supported here, for short names use:
# echo "rvm use 1.9.3" > .rvmrc
environment_id="ruby-1.9.3-p0@cincirb_katas"