This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
log:/[1-9][0-9]{4,}ms/ | |
log: END: current_user\[.*\] \([1-9][0-9]{1,}.\d+ seconds\) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
With Resque: | |
queue_name = 'default' | |
jobs = Resque.data_store.peek_in_queue(queue_name, 0, 500_000); nil; | |
deleted_count = 0 | |
jobs.each do |job| | |
decoded_job = Resque.decode(job) | |
if decoded_job['class'] == "My::Class::Name" | |
Resque.data_store.remove_from_queue(queue_name, job) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def aes256_cbc_encrypt(key, data, iv) | |
if !(key.bytesize === 32) | |
key = Digest::SHA256.digest(key) | |
end | |
if !(iv.bytesize === 16) | |
iv = Digest::MD5.digest(iv) | |
end | |
#padding = 16 - (data.length % 16) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
We tried this about a year or so ago. We didn't see any memory or performance savings at the time, but I'm not sure about our methodology... | |
Eveything I've read about this indicates decent to great memory/peformance gains: | |
(Nate Berkopec is big in the Rails perfomance game, and recommends everyone use it.) | |
https://www.speedshop.co/2017/12/04/malloc-doubles-ruby-memory.html | |
Other good writeups: | |
http://engineering.appfolio.com/appfolio-engineering/2018/2/1/benchmarking-rubys-heap-malloc-tcmalloc-jemalloc | |
https://www.mikeperham.com/2018/04/25/taming-rails-memory-bloat/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Now that I found this... Lets do the next one. | |
https://codility.com/programmers/lessons/2-arrays/odd_occurrences_in_array/ | |
a = [9,3,9,3,9,7,9] | |
a.group_by(&:itself).inject(0){|hash, (k,v)| v.first if v.size.odd?} | |
# Could also use transform_values instead of inject on Ruby 2.4 | |
Turns out this one is easy with XOR exlusive or operator ^. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I read about this problem and thought I would try it. Later I found it is a question here too: | |
https://codility.com/programmers/lessons/1-iterations/binary_gap/ | |
My first instinct was, "I know regex can do this, but I hate regex" (Which is also a good reason to get better at regex). | |
I couldn't quite hoop the syntax so I moved on. Here is what I came up with: | |
def max_binary_gap(n) | |
max_gap = 0 | |
arr = n.to_s(2).chars | |
while arr.size > 2 do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1) Create your private key (any password will do, we remove it below) | |
$ cd ~/.ssh | |
$ openssl genrsa -des3 -out server.orig.key 2048 | |
# 2) Remove the password | |
$ openssl rsa -in server.orig.key -out server.key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'objspace' | |
require 'benchmark' | |
Benchmark.bmbm do |bm| | |
bm.report("using [] :") do | |
GC.start | |
mem_before = ObjectSpace.memsize_of_all | |
before = GC.stat[:total_allocated_objects] | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dis,5,108.59 | |
nflx,3,130.91 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://www.sm-cloud.com/ruby-json-mapping/ | |
http://jsonapi-rb.org/#rails | |
https://github.com/trailblazer/representable | |
https://github.com/trailblazer/roar | |
https://github.com/remiprev/her | |
https://github.com/lostisland/faraday_middleware/wiki | |
http://blog.excelwithcode.com/ruby-api-clients.html |
NewerOlder