Skip to content

Instantly share code, notes, and snippets.

View ejoubaud's full-sized avatar

Emmanuel Joubaud ejoubaud

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / cleanup-kernels.sh
Created October 30, 2014 15:51
Remove old kernels on a ubuntu box
# Identify the revision of kernel running:
uname -r
# Identify installed kernel packages:
dpkg --get-selections | awk '((/^linux-/) && (/[0-9]./)) {print $1}'
# Reboot box if not running the latest installed kernel.
sudo reboot
# Remove kernel packages (being careful not to uninstall the currently running kernel).
@ejoubaud
ejoubaud / simulate_keypress.js
Last active April 9, 2024 18:38
Simulate keypress that works in Google nav in Chrome
// Based on http://stackoverflow.com/a/10520017/1307721 and http://stackoverflow.com/a/16022728/1307721
Podium = {};
Podium.keydown = function(k) {
var oEvent = document.createEvent('KeyboardEvent');
// Chromium Hack
Object.defineProperty(oEvent, 'keyCode', {
get : function() {
@ejoubaud
ejoubaud / multicom.sh
Created August 7, 2015 08:35
Open variations of a command in multiple iTerm2 panes. Works with bash and zsh.
multicom () {
echo Usage: multicom command arg1 arg2 arg3 arg4...
echo e.g. multicom "ssh %s" web1 web2 web3
echo
read -r -d '' code <<-APPLESCRIPT
activate application "iTerm"
tell application "System Events" to keystroke "n" using command down
APPLESCRIPT
@ejoubaud
ejoubaud / docker-machine-hosts.sh
Last active February 2, 2016 20:40
Docker-machine: Update domain name in /etc/hosts, a bash/zsh one-liner
mark="# DOCKER_MACHINE:" && sudo sed -i '' "/$mark/d" /etc/hosts && docker-machine ls -q | while read m; do echo "$(docker-machine ip $m) $m.docker ${mark} $m" | sudo tee -a /etc/hosts; done