- Run
$ createdb uniq-db-test
to create DB - Run example with Ruby (e.g.,
$ ruby 1_find_or_create_by_single_thread.rb
)
With many successful INSERTs
Warming up --------------------------------------
# Внимание! Перед запуском программы: | |
# - отключите все соц.сети, мессенджеры, чтобы случайно не нажать. | |
# - поставьте magic в 3 и _перейдите в ваш браузер_ (!), чтобы программа | |
# работала в фоне. Посмотрите как ваш терминал уведомит вас. Может | |
# появиться одинарный звук и всплывающее уведомление. Зависит от | |
# операционной системы и терминала. Вы должны точно знать как выглядит | |
# или звучит уведомление, чтобы нажать в правильный момент. | |
# главная переменная программы, чем больше, тем лучше. | |
magic = 9 |
Picking the right architecture = Picking the right battles + Managing trade-offs
Method lookup is a simple affair in most languages without multiple inheritance. You start from the receiver and move up the ancestors chain until you locate the method. Because Ruby allows you to mix in modules and extend singleton classes at runtime, this is an entirely different affair.
I will not build contrived code to exemplify the more complicated aspects of Ruby method lookup, as this will only serve to confuse the matter.
When you pass a message to an object, here is how Ruby finds what method to call:
Tests encoding of UTF-16 data with ruby-smpp
Usage example:
$ javac -cp .:smpp.jar SmppDecodeTest.java
$ ruby ./smpp-test.rb | java -Dfile.encoding=utf-8 -cp .:smpp.jar:log4j-1.2.8.jar SmppDecodeTest
Привет
$
# Sample implementation of quicksort and mergesort in ruby | |
# Both algorithm sort in O(n * lg(n)) time | |
# Quicksort works inplace, where mergesort works in a new array | |
def quicksort(array, from=0, to=nil) | |
if to == nil | |
# Sort the whole array, by default | |
to = array.count - 1 | |
end |
$(function() { | |
/* Convenience for forms or links that return HTML from a remote ajax call. | |
The returned markup will be inserted into the element id specified. | |
*/ | |
$('form[data-update-target]').live('ajax:success', function(evt, data) { | |
var target = $(this).data('update-target'); | |
$('#' + target).html(data); | |
}); | |
}); |
module CarrierWave | |
module FFMPEG | |
extend ActiveSupport::Concern | |
module ClassMethods | |
def faststart | |
process :faststart => true | |
end | |
def transcode options |
# RSpec 2.0 syntax Cheet Sheet by http://ApproachE.com | |
# defining spec within a module will automatically pick Player::MovieList as a 'subject' (see below) | |
module Player | |
describe MovieList, "with optional description" do | |
it "is pending example, so that you can write ones quickly" | |
it "is already working example that we want to suspend from failing temporarily" do | |
pending("working on another feature that temporarily breaks this one") |