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
@sergey-alekseev
sergey-alekseev / reformal_widget.rb
Created February 3, 2013 16:58
reformal.ru widget Rails helper
# ERB:
#
# <%= reformal_widget 'alma-by' %>
# </head>
#
# Haml:
#
# = reformal_widget('alma-by')
# %body
@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

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
-------------------------------------------------
cr-search field -> api.crossref.org field
totalResults -> "message": { "total-results"
startIndex -> "message": { "query": {"start-index":0
itemsPerPage -> "message": { "items-per-page":20
"query": { "searchTerms": -> "message": { "query": {"search-terms":
"items": [{ "doi": -> "message": { "items": [ "DOI"
"items": [{ "deposited": -> "message": { "items": [ "deposited": {"date-parts":
"items": [{ "published": -> "message": { "items": [ "issued": {"date-parts":
// aligned/shortened/restructures response from http://api.crossref.org/funders/100000015
{
"status":"ok",
"message-type":"work-list",
"message-version":"1.0.0",
"message": {
"total-results":9332,
"query":{"search-terms":null,"start-index":0},
"items-per-page":20,
"items": [
// response from http://search.chorusaccess.org/funders/100000015/dois (cr-search app)
{
"totalResults": 8906,
"startIndex": 0,
"itemsPerPage": 20,
"query": {
"searchTerms": "100000015",
"startPage": 1
},
"items": [
@sergey-alekseev
sergey-alekseev / cr-search-current-routes.rb
Created June 17, 2014 13:34
Present routes on https://github.com/sergey-alekseev/cr-search before I start working on it (except ORCID related routes)
get '/fundref'
get '/fundref.csv'
get '/chorus'
get '/funders/:id/dois'
get '/funders/:id/hierarchy'
get '/funders/:id/hierarchy.csv'
get '/funders/hierarchy'
get '/funders/dois'
get '/funders/prefixes'
get '/funders/:id'