Skip to content

Instantly share code, notes, and snippets.

@deevis
deevis / gist:b4f71ba52067531575ca
Created February 24, 2015 19:35
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
@deevis
deevis / gist:580ffc503d4bf7dc8182
Created February 19, 2015 22:53
Count requests by hour from NGINX logfile from a particular IP address
for h in 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24;do echo ""; echo "19/Feb/$h:00"; echo "----------------------"; grep "199.102.210.214 - - \[19\/Feb\/2015\:$h" /var/log/nginx/access.log.1 | wc -l ;done
@deevis
deevis / gist:3d34499cd441fe3f3375
Last active August 29, 2015 14:15
Show requests by IP address from NGINX access log (for a particular day)
grep "19\/Feb\/2015" /var/log/nginx/access.log.1 | sed 's/\(.*\) - - .*/\1/g' | sort | uniq -c | sort -n
@deevis
deevis / gist:7d675e1824ed845e1d2e
Created January 9, 2015 17:38
MySQL Storage summary into Ruby Hash
db_name = Rails.configuration.database_configuration[Rails.env]["database"]
sql = "SELECT table_name AS name, table_rows, data_length, index_length FROM information_schema.TABLES WHERE table_schema = '#{db_name}' ORDER BY (data_length + index_length) DESC;"
table_data = ActiveRecord::Base.connection.execute(sql).map{|r| {name: r[0], rows: r[1], data_size: r[2], index_size: r[3]}}
@deevis
deevis / gist:4c025f365cc44589a603
Last active February 13, 2018 13:59
Git Bash Prompt
bash_prompt_command() {
local K="\[\033[0;30m\]" # black
local R="\[\033[0;31m\]" # red
local G="\[\033[0;32m\]" # green
local Y="\[\033[0;33m\]" # yellow
local B="\[\033[0;34m\]" # blue
local M="\[\033[0;35m\]" # magenta
local C="\[\033[0;36m\]" # cyan
local W="\[\033[0;37m\]" # white
local NONE="\[\033[0m\]"
@deevis
deevis / gist:2601b62a842006547289
Created January 8, 2015 18:39
MySQL table storage summary
SELECT table_name AS "Tables", table_rows, round(((data_length + index_length) / 1024 / 1024), 2) "Size in MB" FROM information_schema.TABLES WHERE table_schema = "pyr_revel_prod" ORDER BY (data_length + index_length) DESC;
@deevis
deevis / gist:989d6f5a34b2c25bbeb0
Last active August 29, 2015 14:13
Subscribe to Redis expired key events
redis.subscribe("__keyevent@0__:expired") { |on| on.subscribe { |channel, subscriptions| puts "Subscribed to ##{channel} (#{subscriptions} subscriptions)" }; on.message { |channel, message| puts "Key expired: [#{message}]" }; on.unsubscribe { |channel, subscriptions| puts "Unsubscribed from ##{channel} (#{subscriptions} subscriptions)" }}
@deevis
deevis / gist:ef5071d6d251acae765f
Created November 18, 2014 06:41
Nginx, Faye, Nodejs and SSL configuration
NGINX - Configured to forward root domain requests to SSL, subdomains w/o SSL, and to upgrade /faye to websocket
--------------------------------------------------------------------------------------------------------------------
upstream my_app_upstream {
server unix:///var/run/my_app/my_app.sock;
}
server {
listen 80;
server_name mydomain.com;
pyr_models = ActiveRecord::Base.subclasses.map(&:name).select{|c| c =~ /Pyr.*/}.sort
pyr_polys = {}.tap{|m| pyr_models.each{|klazz| m[klazz] = begin;obj=klazz.constantize.send(:first); app.polymorphic_path(obj) if obj;rescue Exception => e; e.message;end};nil}
pyr_models_mapped = pyr_polys.select{|k,v| v =~ /\/.*/}.keys
# Those without polymorphic paths
(pyr_models - pyr_models_mapped).sort.each {|m| puts m}
# Those with polymorphic paths
@deevis
deevis / Rails - load controllers and models
Last active December 21, 2015 18:19
Reload Rails Controllers and/or Models
# Controllers
Dir["#{Rails.root}/../pyr/*/app/controllers/**/*.rb"].each{|p| puts "require #{p}";require p};nil
# Models
Dir["#{Rails.root}/../pyr/*/app/models/**/*.rb"].each{|p| puts "require #{p}";require p};nil