Skip to content

Instantly share code, notes, and snippets.

Avatar
🤗
Killing it, hustling, no code is best code

Sergey Alekseev sergey-alekseev

🤗
Killing it, hustling, no code is best code
View GitHub Profile
View mysql2-single-column-with-unique-index-reports.txt
=========== [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 Dec 21, 2016
Скрипт для автоматического поднятия объявлений на Барахолке Онлайнера (http://baraholka.onliner.by)
View onliner-by-auto-up.rb
# 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"
View rails-uniqueness-validation-scope-with-polymorphic-association_active_record_master.rb
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"
View logstash-es-to-csv-example.conf
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 Dec 2, 2015 — forked from wvengen/README.md
Ruby memory analysis over time
View README.md

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 Mar 30, 2015
Ruby Merge vs. Merge! comparison (benchmarking)
View merge-vs-merge-with-bang.rb
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
View exists-vs-where_any-comparison.rb
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
View exists-vs-any-comparison.rb
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
View object-vs-id-comparison.rb
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
-------------------------------------------------
@sergey-alekseev
sergey-alekseev / sublime-text-settings-user
Created Feb 12, 2015
Sublime Text configuration. Make sure you have these lines in your Settings - User.
View sublime-text-settings-user
{
"ensure_newline_at_eof_on_save": true,
"tab_size": 2,
"translate_tabs_to_spaces": true,
"trim_trailing_white_space_on_save": true
}