Skip to content

Instantly share code, notes, and snippets.

@austra
austra / gist:a5682ec0fc3af6d11057de40d512de42
Last active December 9, 2024 12:03
Rails Performance Resources
https://www.youtube.com/watch?v=kZcqyuPeDao
https://gist.github.com/nateberkopec/2b1f585046adad9a55e7058c941d3850
https://www.speedshop.co/2015/07/15/the-complete-guide-to-rails-caching.html
https://www.railsspeed.com/
https://www.speedshop.co/2015/07/29/scaling-ruby-apps-to-1000-rpm.html
https://www.speedshop.co/2015/10/07/frontend-performance-chrome-timeline.html
https://github.com/ruby-prof/ruby-prof
https://github.com/schneems/get_process_mem
https://github.com/ko1/allocation_tracer
https://github.com/evanphx/benchmark-ips
@austra
austra / gist:451d0a527adf0d7fbf165701d7f65932
Created August 25, 2016 22:00
Kill irb sessions after x minutes of inactivity
# Add some methods to IRB::Context and IRB::Irb
# for easier timeout implementation.
class IRB::Irb
def status
@signal_status
end
end
class IRB::Context
attr_reader :irb
@austra
austra / spoilerbot
Last active October 26, 2017 19:48
spoilerbot
188,139,85,078,41,251,234,35,275,136,014,270,179,46,89,172,052,207,192,55,205,42,133,26,37,71,083,153,97,142,197,134,159,109,162,79,184,101,4,169,196,185,195,59,103,204,170,22,247,24,144,036,21,80,065,149,217,3,222,104,60,232,64,224,44,161,231,094,230
@austra
austra / Find duplicate cms keys in mongo
Last active February 18, 2016 01:00
Find duplicate cms keys in mongo
Cms::Content.collection.aggregate([{"$group" => {"_id" => "$key", "count" => {"$sum" => 1}}}, {"$match" => {"count" => {"$gt" => 1}}}, {"$sort" => {"count" => -1}}])
@austra
austra / gist:ae39fc95ee7abdc8f061
Created December 7, 2015 23:58
nested datatables
http://live.datatables.net/IroN/399/edit
@austra
austra / gist:9ba13748bdad60da712f
Last active November 5, 2015 16:48
activerecord - .endmost scope - optimized .last
.endmost is what you want when you call .last: the last N records in the result set without having to retrieve all records from the database, and it works with any ordering. You can impose filtering before, Message.where(…).in_order.endmost(10), and afterwards to filter your final results as well Message.in_order.endmost(10).where(…).
class Message
class << self
def in_order
order(created_at: :asc)
end
def recent(n)
in_order.endmost(n)
@austra
austra / gist:5847cecd4d645182fcbf
Created November 4, 2015 18:10
destroy datetimepicker
$('#banDateOneReal').data("DateTimePicker").destroy();
http://stackoverflow.com/questions/22957699/how-to-change-a-bootstrap-datetimepicker-language-during-running
@austra
austra / gist:f9f3f3364760efda320d
Created October 28, 2015 16:04
ActiveRecord::Base.connection
raw = ActiveRecord::Base.connection.execute(sql)
raw.each(:as => :hash) do |row|
puts row.inspect # row is hash
end
@austra
austra / gist:7dc8429145d386499872
Created October 27, 2015 14:57 — forked from deevis/gist:b4f71ba52067531575ca
Get list of users with occurrence count who had a certain type of error occur
for request in `grep -e "undefined local variable or method .*html_safe" log/production.log -B 1 | grep FATAL | sed 's/.*FATAL.*\[\(.*\)\]/\1/g'`;do grep "$request" log/production.log | head -n 20 | grep current_user;done | sed 's/.*current_user\(.*\).*/\1/g' | sort | uniq -c | sort -n
@austra
austra / gist:07225957f9f173fff422
Created October 26, 2015 21:01 — forked from deevis/gist:61113a95429e219fd108
Parse Vibe logs for slowest showing time to render, user, path, and time of request
zgrep "END: current_user" production.log.2.gz | sed 's/\(.*\) \[.*INFO.*current_user\[\(.*\)\] (\(.*\)) \(.*\)/\3\t\4\t\2\t\1/g' | sort -n | tail -n 20
# with process:request
grep "END: current_user" production.log | sed 's/\(.*\) \[.*INFO.*\[\(.*\)\].*current_user\[\(.*\)\] (\(.*\)) \(.*\)/\4\t\2\t\1\t\3\t\5/g' | sort -n | tail -n 100
# find with process:request, then loop back and find problems for each...
# Part 1
grep "END: current_user" production.log | sed 's/\(.*\) \[.*INFO.*\[\(.*\)\].*current_user\[\(.*\)\] (\(.*\)) \(.*\)/\4\t\2\t\1\t\3\t\5/g' | sort -n | tail -n 100 > slow_requests_10_26_2015.txt
# Part 2
for rqid in `cat slow_requests_10_26_2015.txt | sed 's/.*seconds\t\(.*\)\s.*2015.*/\1/g'`;do echo -e "API Calls for [$rqid]\n---------------------------\n"; grep $rqid production.log | grep "request to api.exigo.com" -A 1; echo -e "\n\n";done > exigo_slow_calls_report_10_26_2015.txt