Skip to content

Instantly share code, notes, and snippets.

View lavoiesl's full-sized avatar

Sébastien Lavoie lavoiesl

View GitHub Profile
#!/bin/bash
# Converts an image in a multi-resolution favicon
# Requires Imagemagick
#
# @link https://gist.github.com/lavoiesl/a7ccb4affe869d0a0bca
if [[ "$#" != "2" ]]; then
echo "Usage: $0 input.png output.ico" >&2
exit 1
fi
@lavoiesl
lavoiesl / osx-socks-proxy.sh
Last active March 21, 2019 14:34
OSX script to fire up a SSH connection and tunnel all traffic to it using a SOCKS proxy.
#!/bin/bash
# OSX script to fire up a SSH connection and tunnel all traffic to it using a SOCKS proxy.
# @link https://gist.github.com/lavoiesl/3bd6a07af04a7979a814
#
# Features:
# - Network detection (wi-fi/Ethernet)
# - SSH crash detection
# - Graceful interrupt
# - Automatic proxy deconfiguration
@lavoiesl
lavoiesl / mysql-drop-tables.sh
Last active August 29, 2015 14:03
Drop all tables of a MySQL database
#!/bin/bash
# Drop all tables of a MySQL database
# https://gist.github.com/lavoiesl/96aa8586b609daac2dad
if [ -z "$@" ]; then
echo "Usage: $0 database_name" >&2
echo " or : $0 -uuser -ppassword -hlocalhost database_name" >&2
exit 1
fi
@lavoiesl
lavoiesl / process-mysqldump.c
Last active October 4, 2024 20:10
Add newlines before parenthesis for a SQL mysqldump
// gcc -O2 -Wall -pedantic process-mysqldump.c -o process-mysqldump
// Usage: cat dump.sql | process-mysqldump
// Or : process-mysqldump dump.sql
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#define BUFFER 100000
<?php
// $pdo = new PDO(...)
$charsets = array('UTF-8', 'ISO-8859-1');
$tables = array(
'events' => array(
'title',
'description',
@lavoiesl
lavoiesl / php-extras.ini
Created May 27, 2014 03:32
PHP dev extra settings
; Extra configuration
; priority=50
allow_url_fopen = On
allow_url_include = Off
auto_detect_line_endings = On
date.timezone = 'America/Montreal'
default_charset = "utf-8"
default_mimetype = "text/html"
default_socket_timeout = 10
@lavoiesl
lavoiesl / convert-to-utf8.sh
Last active August 29, 2015 14:00
convert a file to UTF-8 using iconv
#!/bin/bash
# Convert file from iso-8859-* to UTF8 if needed
if [[ $# -lt 1 ]]; then
echo "Usage: $0 input-file" >&2
exit 1
fi
mime_encoding="$(file -b --mime-encoding "$1")"
@lavoiesl
lavoiesl / list-filetypes.sh
Last active November 13, 2016 15:21
list file types
#!/bin/bash
#
# @link https://gist.github.com/lavoiesl/11024316
folder="${1:-.}"
find -E "$folder" -regex '.*/\.(git|svn)' -prune -o -type f -print \
| grep -oiE '\.[a-z0-9_]+$' \
| tr '[:upper:]' '[:lower:]' \
| sort \
@lavoiesl
lavoiesl / optimize-images.sh
Last active February 19, 2016 16:47
optimize images
#!/bin/bash
#
# @link https://gist.github.com/lavoiesl/11024067
find . -type f \( -name '*.jpg' -or -name '*.jpeg' \) -exec jpegoptim --strip-all "{}" \;
find . -type f -name '*.png' -exec optipng -o8 -strip all '{}' \;
@lavoiesl
lavoiesl / battery-status.sh
Last active September 25, 2018 22:10
Apple Battery Status
#!/bin/bash
#
# @link https://gist.github.com/lavoiesl/11023856
ioreg="$(ioreg -c AppleSmartBattery)"
current="$(echo "$ioreg" | grep CurrentCapacity | grep -oE "[0-9]+" | head -n1)"
max="$(echo "$ioreg" | grep MaxCapacity | grep -oE "[0-9]+" | head -n1)"
battery="$(( current * 100 / max ))"
echo -ne '|'