Skip to content

Instantly share code, notes, and snippets.

View ejoubaud's full-sized avatar

Emmanuel Joubaud ejoubaud

View GitHub Profile
@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
@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 / 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 / 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 / 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 / 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 / meteor_nitrous.md
Last active December 24, 2015 01:59
Meteor.js setup in nitrous.io

Create a free nitrous.io Node.js box then, in the console:

parts install meteor
npm install -g meteorite

cd workspace
git clone https://your_git.url/repo/username
mrt
@ejoubaud
ejoubaud / mount_dump.sh
Created October 29, 2013 04:43
A MySQL easy-to-customize db mount script, with sensible defaults
#!/bin/sh
DEFAULT_DB=marketplace_development
DEFAULT_DUMP=`ls -1t *.sql | head -1`
MYSQL_USER=root
# Easy overriding
export MYSQL_PWD=$MYSQL_PWD
export MYSQL_HOST=$MYSQL_HOST
@ejoubaud
ejoubaud / loadTsort.js
Last active December 29, 2015 04:09
Bookmarklet that loads jQuery + tinysort, so it's easy to order search results from the browser's JS console: $('.containers-to-sort').tsort('.childnode-criteria-to-sort-by', {order: 'desc'});
javascript:(function(){var v="1.10.2";if(window.jQuery===undefined||window.jQuery.fn.jquery<v){var done=false;var script=document.createElement("script");script.src="//ajax.googleapis.com/ajax/libs/jquery/"+v+"/jquery.min.js"; script.onload=script.onreadystatechange=function(){if(!done&&(!this.readyState||this.readyState=="loaded"||this.readyState=="complete")){done=true;initMyBookmarklet();}};document.getElementsByTagName("head")[0].appendChild(script);}else{initMyBookmarklet();}function initMyBookmarklet(){(window.myBookmarklet=function(){function getSelText(){var s='';if(window.getSelection){s=window.getSelection();}else if(document.getSelection){s=document.getSelection();}else if(document.selection){s=document.selection.createRange().text;}return s;};$.getScript('//tinysort.sjeiti.com/dist/jquery.tinysort.min.js',function(){alert("loaded.\n\n$('.tosort').tsort('.subclass-to-sort-by', {order: 'desc'});\n\n$('#ctl00_ContentMain_CitySearchResult_v2_upResultData>div').tsort('.fontxlargeb.purple', {sortFunctio
@ejoubaud
ejoubaud / pipable_mysql_output.sh
Last active January 1, 2016 23:19
Pipable MySQL output
mysql -uroot -e 'query;' -BN
# -B stands for --bash which usese tab as a separator instead of the annoying tab-like pipes
# -N stands for --skip-column-names which removes the column names header
# Usage Example: Kills all processes created by the ejoubaud user
mysql -uroot -e 'show processlist;' -BN | grep ejoubaud | cut -f1 | xargs -n1 kill