Imagine this case:
class Account < ActiveRecord::Base
def transfer(other, quantity)
tries = 0
begin
tries += 1
transaction do
self.quantity -= quantity
# Passos para rodar: | |
# 1. ruby extconf.rb | |
# 2. make | |
# 3. ruby benchmark.rb | |
require 'benchmark' | |
require 'bigdecimal' | |
require './test' | |
n = 50 |
Imagine this case:
class Account < ActiveRecord::Base
def transfer(other, quantity)
tries = 0
begin
tries += 1
transaction do
self.quantity -= quantity
# Of course we can make something like this | |
class Module | |
@include: (mixin) -> | |
this.prototype[name] = method for name, method of mixin | |
Saveable = | |
save: -> alert "#{@name} saved!" | |
class User extends Module |
require "thread" | |
class Account | |
attr_reader :amount | |
def initialize(amount) | |
@amount = amount | |
end | |
def debit(amount) |
class Presenter < BasicObject | |
def initialize(object) | |
@object = object | |
end | |
def method_missing(method, *args, &block) | |
@object.send method, *args, &block | |
end | |
module RailsHelpers |
def password_prompt(message = "Inform your password: ") | |
puts message | |
begin | |
system "stty -echo -icanon" | |
gets.rstrip | |
ensure | |
system "stty echo icanon" | |
end | |
end |
var async = function(url, callback) { | |
var script = document.createElement("script"); | |
script.src = url; | |
if (callback != null) { | |
callback.done = false; | |
script.onreadystatechange = s.onload = function() { | |
var state = script.readyState; |
var redis = require("redis") | |
, subscriber = redis.createClient() | |
, publisher = redis.createClient(); | |
subscriber.on("message", function(channel, message) { | |
console.log("Message '" + message + "' on channel '" + channel + "' arrived!") | |
}); | |
subscriber.subscribe("test"); |
require 'rubygems' | |
require 'pcaprub' | |
capture = PCAPRUB::Pcap.open_live('lo0', 65535, true, 0) | |
capture.setfilter('icmp') | |
while 1==1 | |
puts(capture.stats()) | |
pkt = capture.next() | |
if pkt | |
puts "captured packet" |
function inherit(child, parent) { | |
child.prototype = Object.create(parent.prototype); | |
child.prototype.constructor = child; | |
} | |
var Person = function Person(firstName, lastName) { | |
if (!firstName || !lastName) throw "Primeiro e último nome requerido!"; | |
this.firstName = firstName; | |
this.lastName = lastName; |