Skip to content

Instantly share code, notes, and snippets.

View lavoiesl's full-sized avatar

Sébastien Lavoie lavoiesl

View GitHub Profile
@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 '|'
@lavoiesl
lavoiesl / remove-crap.sh
Last active August 29, 2015 14:00
remove-crap.sh
#!/bin/bash
#
# Script to remove temporary and junk files from Windows and OS X
# @link https://gist.github.com/lavoiesl/11023700
### Not set up to run as root. Advised not to do this. ###
#### Variables ####
# Files to remove (Add others, just remember to increment the
@lavoiesl
lavoiesl / genpasswd.sh
Last active August 29, 2015 14:00
password generator + key-store
#!/bin/bash
# Generates a random password using only non-ambiguous alphanumeric characters
# Usage: genpasswd.sh [length]
#
# @link https://gist.github.com/lavoiesl/11023640
length=16
if [[ -n "$1" ]]; then
length="$1"