Skip to content

Instantly share code, notes, and snippets.

Avatar

Hans Hasselberg i0rek

View GitHub Profile
View gist:4541852
$ ruby --version
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin12.0.0]
$ irb --version
irb 0.9.6(09/06/30)
$ irb
> a = "gc me"
=> "gc me"
> ObjectSpace.define_finalizer(a, proc {|id| puts "Finalizer one on #{id}" })
=> [0, #<Proc:0x007f9e2abb9200@(irb):3>]
> a = nil
View gist:4514777
webmock master bundle exec rspec spec;
Run options:
include {:focus=>true}
exclude {:without_webmock=>true}
All examples were filtered out; ignoring {:focus=>true}
.......................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
View gist:4496262
APIBETA_Redis_VMaster:~$ cat /var/log/syslog | grep -i redis
Jan 9 06:44:30 ip-10-32-32-9 redis-6379[19818]: Opening port 6379: bind: Address already in use
Jan 9 06:44:30 ip-10-32-32-9 redis-6379[19827]: Opening port 6379: bind: Address already in use
Jan 9 06:50:03 ip-10-32-32-9 redis-6379[20334]: Opening port 6379: bind: Address already in use
Jan 9 06:50:04 ip-10-32-32-9 redis-6379[20343]: Opening port 6379: bind: Address already in use
Jan 9 06:55:23 ip-10-32-32-9 redis-6379[20857]: Opening port 6379: bind: Address already in use
Jan 9 06:55:23 ip-10-32-32-9 redis-6379[20866]: Opening port 6379: bind: Address already in use
Jan 9 07:00:54 ip-10-32-32-9 redis-6379[21375]: Opening port 6379: bind: Address already in use
Jan 9 07:00:54 ip-10-32-32-9 redis-6379[21384]: Opening port 6379: bind: Address already in use
Jan 9 07:06:31 ip-10-32-32-9 redis-6379[21899]: Opening port 6379: bind: Address already in use
View gist:4487967
NoMethodError: undefined method `cmd_tuples' for nil:NilClass: UPDATE "tasks" SET "completed_at" = '2013-01-08 20:58:11.000000', "version" = 2, "updated_at" = '2013-01-08 21:08:09.784780' WHERE "tasks"."id" = 279862062
/var/www/wunderapi/shared/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/postgresql_adapter.rb:675:in `block in exec_delete'
/var/www/wunderapi/shared/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log'
/var/www/wunderapi/shared/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.9/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/var/www/wunderapi/shared/vendor/bundle/ruby/1.9.1/bundler/gems/octopus-3025b7b8a5e7/lib/octopus/rails3/abstract_adapter.rb:14:in `instrument'
/var/www/wunderapi/shared/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
/var/www/wunderapi/shared/vendor/bundle/ruby/1.9.1/g
View gist:4482885
NoMethodError: undefined method `fields' for nil:NilClass: SELECT "list_elements"."id" AS t0_r0, "list_elements"."container_id" AS t0_r1, "list_elements"."container_type" AS t0_r2, "list_elements"."resource_id" AS t0_r3, "list_elements"."resource_type" AS t0_r4, "list_elements"."user_id" AS t0_r5, "list_elements"."owner" AS t0_r6, "list_elements"."position" AS t0_r7, "list_elements"."bucket" AS t0_r8, "list_elements"."deleted_at" AS t0_r9, "list_elements"."created_at" AS t0_r10, "list_elements"."updated_at" AS t0_r11, "tasks"."id" AS t1_r0, "tasks"."title" AS t1_r1, "tasks"."starred" AS t1_r2, "tasks"."note" AS t1_r3, "tasks"."completed_at" AS t1_r4, "tasks"."created_at" AS t1_r5, "tasks"."updated_at" AS t1_r6, "tasks"."parent_id" AS t1_r7, "tasks"."due_date" AS t1_r8, "tasks"."recurrence_type" AS t1_r9, "tasks"."recurrence_count" AS t1_r10, "tasks"."recurring_parent_id" AS t1_r11, "tasks"."updated_by_id" AS t1_r12, "tasks"."deleted_at" AS t1_r13, "tasks"."local_identifier" AS t1_r14, "tasks"."version" AS t1_
View gist:4334087
# number postgres connections
sudo ps -ef | grep postgres | wc -l
# disk usage
iostat 5
# memory
mpstat 5
# slow req per second
View gist:4023661
require 'json'
url = "http://search.tez-tour.com/toursearch/getResult?accommodationId=2&after=29.11.2012&before=29.11.2012&cityId=345&countryId=5732&currency=8390&hotelClassId=12703&hotelClassBetter=true&hotelInStop=false&locale=ru&nightsMin=7&nightsMax=7&noTicketsFrom=false&noTicketsTo=false&priceMax=9999999&priceMin=0&rAndBId=15350&rAndBBetter=true&formatResult=true&xml=false&"
JSON.parse(Typhoeus.get(url).body.force_encoding("utf-8"))
#=> => {"success"=>true, "serverName"=>"don.teztour.com", "data"=>[[1, "29.11.2012", "Чт", [...]
@i0rek
i0rek / gist:3976076
Created Oct 29, 2012
Curl.set_option performance
View gist:3976076
$ b ruby perf/ethon.rb
user system total real
[ 1 000 000 Iterations]
String.new 0.200000 0.000000 0.200000 ( 0.200820)
Easy.new 6.250000 0.130000 6.380000 ( 6.377507)
Curl.set_option 3.540000 0.050000 3.590000 ( 3.597051)
@i0rek
i0rek / gist:3760076
Created Sep 21, 2012
sample mongoid exception
View gist:3760076
irb(main):001:0> Product.find("123")
Mongoid::Errors::DocumentNotFound:
Problem:
Document(s) not found for class Product with id(s) 123.
Summary:
When calling Product.find with an id or array of ids, each parameter must match a document in the database or this error will be raised. The search was for the id(s): 123 ... (1 total) and the following ids were not found: 123.
Resolution:
Search for an id that is in the database or set the Mongoid.raise_not_found_error configuration option to false, which will cause a nil to be returned instead of raising this error when searching for a single id, or only the matched documents when searching for multiples.
irb(main):002:0>
View gist:3693182
Typhoeus.on_complete {|r| p Time.now.to_f }
hydra = Typhoeus::Hydra.new(max_concurrency: 1)
10.times.map{ hydra.queue(Typhoeus::Request.new("www.example.com")) }
hydra.run
# 1347304950.781197
# 1347304950.9252968
# 1347304951.216028
# 1347304951.3606741
# 1347304951.660367
# 1347304951.80959