Skip to content

Instantly share code, notes, and snippets.

View ejoubaud's full-sized avatar

Emmanuel Joubaud ejoubaud

View GitHub Profile
@ejoubaud
ejoubaud / create_db_snapshot.sh
Created October 3, 2014 07:36
Snapshot DB: Create snapshots of db fast. Inspired by Stellar. Useful to switch to different themes with starter data in Wordpress development much faster than WP Importer.
#!/bin/bash
TARGET_DB=wordpress_default
# This is meant for a dev env (VVV actually), you may want to use something more secure to store credentials, and possibly a user with target-db-specific privileges.
ROOT=root
ROOT_PW=root
mysql -u${ROOT} -p${ROOT_PW} -e'SHOW DATABASES;'
echo "Warning! This will copy the content of ${TARGET_DB}, which may take a lot of disk space (possibly more than you have."
read -p "What name for your snapshot? " snapshot
@ejoubaud
ejoubaud / create_trello_cards.rb
Last active December 13, 2021 22:45
Ruby script to create Trello cards
#!/usr/bin/env ruby
# If you're not using rbenv in this script's dir, you may wanna run
# these as `sudo gem install ruby-trello`, etc.
['ruby-trello', 'dotenv'].each do |gem_name|
begin
gem gem_name
rescue LoadError
puts "Running `gem install #{gem_name}`..."
puts "If this takes too long, you may want to run it manually, as `sudo` if needed."
@ejoubaud
ejoubaud / arrayify.sh
Created August 26, 2014 10:40
Turn 1-per-line list of values into a 10-per-line comma-separated list of values
awk 'FNR%10!=0 {printf "%d, ",$1} FNR%10==0 {print $1}' file_with_one_val_per_line.txt
@ejoubaud
ejoubaud / os_from_ua.sql
Created June 16, 2014 09:53
Tell OS from user agent in a MySQL query, for stats and security research. Just the select part. Also allows ordering by OS safety.
select case
when user_agent like '%iPad%' then '4.iPad'
when user_agent like '%iPhone%' then '4.iPhone'
when user_agent like '%Android%' then '4.Android'
when user_agent like '%Mac OS X%' then '4.OS X'
when user_agent like '%X11%' then '4.Linux'
when user_agent like '%Windows NT 6.3%' then '3.Windows 8.1'
when user_agent like '%Windows NT 6.2%' then '3.Windows 8'
when user_agent like '%Windows NT 6.1%' then '3.Windows 7'
when user_agent like '%Windows NT 6.0%' then '2.Windows Vista'
@ejoubaud
ejoubaud / sysadmin_commands.sh
Last active August 29, 2015 14:01
Favorite sysadmin commands
# List all crontabs on a box (from http://stackoverflow.com/questions/134906/how-do-i-list-all-cron-jobs-for-all-users)
for user in $(cut -f1 -d: /etc/passwd); do sudo crontab -u $user -l; done
# See what's eating up disk space
sudo du -h / | grep '[0-9]G'
# Multiple ssh, install i2cssh
# cmd+shift+i to broadcast'
# Terminal.app alternative is csshx
i2cssh -mdj1,dj2,dj3,dj4,dj5
@ejoubaud
ejoubaud / com.ejoubaud.symlinkntfsdisk.plist
Created January 20, 2014 14:31
Symlink my ntfs external hard drive on mount on OSX - /System/Library/LaunchDaemons/com.ejoubaud.symlinkntfsdisk.plist - /Users/ejoubaud/Library/Scripts/symlink_ntfs_disk
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" \
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<dict>
<key>Label</key>
<string>com.ejoubaud.symlinkntfsdisk</string>
<key>LowPriorityIO</key>
<true/>
<key>Program</key>
<string>/Users/ejoubaud/Library/Scripts/symlink_ntfs_disk.bash</string>
@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
@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 / 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 / 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