$ rails g model User
belongs_to
has_one
| require "benchmark" | |
| def f(i); i; end | |
| array = Array.new(1_000_000) { rand.to_s } | |
| TESTS = 5 | |
| Benchmark.bmbm do |results| | |
| results.report("null:") { TESTS.times { array.each { |i| f(i) } } } | |
| results.report("sliced each:") { TESTS.times { array[1,array.size-2].each { |i| f(i) } } } |
| class A < Struct.new(:a, :b) | |
| end | |
| B = Struct.new(:a, :b) | |
| require 'benchmark' | |
| Benchmark.bmbm 20 do |r| | |
| n = 10_000_000 | |
| a = A.new(1,2) |
| # Nginx+Unicorn best-practices congifuration guide. Heartbleed fixed. | |
| # We use latest stable nginx with fresh **openssl**, **zlib** and **pcre** dependencies. | |
| # Some extra handy modules to use: --with-http_stub_status_module --with-http_gzip_static_module | |
| # | |
| # Deployment structure | |
| # | |
| # SERVER: | |
| # /etc/init.d/nginx (1. nginx) | |
| # /home/app/public_html/app_production/current (Capistrano directory) | |
| # |
| package main | |
| import ( | |
| "log" | |
| "net/mail" | |
| "encoding/base64" | |
| "net/smtp" | |
| "fmt" | |
| "strings" |
| Usage example: | |
| >> text = Morpher.new('Большой город') | |
| {:Р=>"Большого города", :Д=>"Большому городу", :В=>"Большой город", :Т=>"Большим городом", :П=>"Большом городе", :П_о=>"о Большом городе", :род=>"Мужской", :множественное=>{:И=>"Большие города", :Р=>"Больших городов", :Д=>"Большим городам", :В=>"Большие города", :Т=>"Большими городами", :П=>"Больших городах", :П_о=>"о Больших городах"}, :где=>"в Большом городе", :куда=>"в Большой город", :откуда=>"из Большого города"} | |
| >> text.singular('Д') | |
| "Большому городу" | |
| >> text.plural('Д') |
| q = { | |
| "query": { | |
| "function_score": { | |
| "boost_mode": "replace", | |
| "query": { | |
| "ids": { | |
| "values": [ | |
| 50, | |
| 80, | |
| 44, |
RDBMS-based job queues have been criticized recently for being unable to handle heavy loads. And they deserve it, to some extent, because the queries used to safely lock a job have been pretty hairy. SELECT FOR UPDATE followed by an UPDATE works fine at first, but then you add more workers, and each is trying to SELECT FOR UPDATE the same row (and maybe throwing NOWAIT in there, then catching the errors and retrying), and things slow down.
On top of that, they have to actually update the row to mark it as locked, so the rest of your workers are sitting there waiting while one of them propagates its lock to disk (and the disks of however many servers you're replicating to). QueueClassic got some mileage out of the novel idea of randomly picking a row near the front of the queue to lock, but I can't still seem to get more than an an extra few hundred jobs per second out of it under heavy load.
So, many developers have started going straight t
| /** | |
| * IE 5.5+, Firefox, Opera, Chrome, Safari XHR object | |
| * | |
| * @param string url | |
| * @param object callback | |
| * @param mixed data | |
| * @param null x | |
| */ | |
| function ajax(url, callback, data, x) { | |
| try { |
TL;DR
Create a backup:
pg_dumpall > mybackup.sqlPerform the upgrade:
sudo pg_dropcluster 9.4 main --stop