Skip to content

Instantly share code, notes, and snippets.

View sergey-alekseev's full-sized avatar
🇺🇦
#StandWithUkraine

Sergey Alekseev sergey-alekseev

🇺🇦
#StandWithUkraine
View GitHub Profile

Keybase proof

I hereby claim:

  • I am sergey-alekseev on github.
  • I am sergeyalekseev (https://keybase.io/sergeyalekseev) on keybase.
  • I have a public key whose fingerprint is 2D4B 460A 441B D5A9 F42E 97A9 781C 4863 C8D7 8D81

To claim this, I am signing this object:

=========== [mysql2] Single column with unique index (1000 records) ============
Warming up --------------------------------------
validate_only_if_changed_by_default = true
2.014k i/100ms
validate_only_if_changed_by_default = false
227.000 i/100ms
Calculating -------------------------------------
validate_only_if_changed_by_default = true
21.060k (± 3.1%) i/s - 106.742k in 5.073537s
@sergey-alekseev
sergey-alekseev / onliner-by-auto-up.rb
Created December 21, 2016 16:07
Скрипт для автоматического поднятия объявлений на Барахолке Онлайнера (http://baraholka.onliner.by)
# this is a simple Ruby script written by https://github.com/sergey-alekseev
# to automate dummy "UP"s for adverts on the most popular local Belarusian
# online flea market – http://baraholka.onliner.by
# feel free to create a recurring task from the script
# using launchd on Mac or cron on Linux
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do
source "https://rubygems.org"
gem "rails", github: "rails/rails"
input {
# Read all documents from Elasticsearch matching the given query
elasticsearch {
hosts => "localhost"
index => "index_name"
query => '{"query":{"regexp":{"not_analyzed_field":".*"}}}'
}
}
output {
@sergey-alekseev
sergey-alekseev / README.md
Last active December 2, 2015 15:32 — forked from wvengen/README.md
Ruby memory analysis over time

Finding a Ruby memory leak using a time analysis

When developing a program in Ruby, you may sometimes encounter a memory leak. For a while now, Ruby has a facility to gather information about what objects are laying around: ObjectSpace.

There are several approaches one can take to debug a leak. This discusses a time-based approach, where a full memory dump is generated every, say, 5 minutes, during a time that the memory leak is showing up. Afterwards, one can look at all the objects, and find out which ones are staying around, causing the

@sergey-alekseev
sergey-alekseev / merge-vs-merge-with-bang.rb
Created March 30, 2015 12:38
Ruby Merge vs. Merge! comparison (benchmarking)
Benchmark.ips do |x|
x.report('merge') { {}.merge :a => 1 }
x.report('merge!') { {}.merge! :a => 1 }
x.compare!
end
Calculating -------------------------------------
merge 34.220k i/100ms
merge! 33.039k i/100ms
-------------------------------------------------
merge 1.923M (±32.2%) i/s - 7.631M
Benchmark.ips do |x|
x.report('exists?') { User.exists?(:id => 1) }
x.report('where-any?') { User.where(:id => 1).any? }
x.compare!
end
Comparison:
exists?: 636.0 i/s
where-any?: 567.1 i/s - 1.12x slower
Benchmark.ips do |x|
x.report('exists?') { user.printers.exists? }
x.report('any?') { user.printers.any? }
x.compare!
end
Comparison:
any?: 615.6 i/s
exists?: 601.8 i/s - 1.02x slower
@sergey-alekseev
sergey-alekseev / object-vs-id-comparison.rb
Created March 10, 2015 20:33
Object comparison vs. id
Benchmark.ips do |x|
x.report('object comparison') { item.user == print.user }
x.report('id comparison') { item.user_id == print.user_id }
x.compare!
end
Calculating -------------------------------------
object comparison 1.204k i/100ms
id comparison 1.972k i/100ms
-------------------------------------------------