Skip to content

Instantly share code, notes, and snippets.

View ejoubaud's full-sized avatar

Emmanuel Joubaud ejoubaud

View GitHub Profile
@ejoubaud
ejoubaud / enable_sql_logs.rb
Created August 16, 2013 00:36
Rails: Enable SQL logs in debugger/pry/console
ActiveRecord::Base.logger = Logger.new(STDOUT)
@ejoubaud
ejoubaud / rails_delegate.coffee
Created August 12, 2013 10:08
Rails-like `delegate` in Coffeescript
# Micro-optimized, with extra-function (so it's not redefined at each call)
delegate = (delegatorConstructor, delegeeProp, method) ->
delegatorConstructor.prototype[ method ] = ->
this[ delegeeProp ][ method ].apply( this[ delegeeProp ], arguments )
Function.prototype.delegate = ( methodNames..., toProp ) ->
delegeeProp = toProp.to
for method in methodNames
delegate(this, delegeeProp, method)
@ejoubaud
ejoubaud / sort_new_relic_queries.sh
Created August 1, 2013 03:38
Awk for Turtlestein: Sort New Relic queries by pain
# In New Relic > Monitoring > Database > Show SQL Trace,
# we get a table of slow queries sortable by time spent or by number of occurrences
# This allows us to multiply these 2 values to get an actual amount of pain (qty * unit_cost)
# Copy/Paste this in Sublime's Shell Turtlestein:
| awk -F\t '{ gsub(/[^0-9]/, "", $2); print $2*$3 "\t" $1 }' | sort -nr |
@ejoubaud
ejoubaud / all_users_cron_jobs.sh
Created July 31, 2013 07:14
List all cron jobs for all users on a given box
# List cron jobs for all users
for user in $(cut -f1 -d: /etc/passwd); do sudo crontab -u $user -l; done
@ejoubaud
ejoubaud / find_duplicates.sh
Created May 8, 2013 05:19
Awk for Turtlestein: Find duplicates elements in a list
# Find duplicates in a textual list
#
# Just:
# * paste the list into Sublime
# * paste this line in Shell Turtlestein (plugin) invite
# * replace $1 by $<element_column_index> if there are more than 1 column
# * add flag -F if columns separator is not default (spaces and tabs)
#
# Can be easily adapted for VIM, it's just awk
@ejoubaud
ejoubaud / sort_ids_by_cat_for_migration.sh
Last active December 17, 2015 02:48
Parses Excel spreadsheets from the review team for big category changes by item ID
# Parse category migrations by ID from Excel files
#
# Just:
# * paste from the spreadsheet into Sublime
# * paste this line in Shell Turtlestein (plugin) invite
# * replace $4 and $1 by $<category_column_index> and $<id_column_index> (1-based index)
#
# Can be easily adapted for VIM, it's just awk