Skip to content

Instantly share code, notes, and snippets.

@lrhache
lrhache / file-extension.awk
Created April 21, 2015 01:06
Find unique file extension from list of files
awk -F. '!a[$NF]++{print $NF}'
@lrhache
lrhache / match-doublequote-enclosed.awk
Created April 21, 2015 01:05
Get text in enclosed in double quote
awk -F\" '{print $(NF-1)}'
@lrhache
lrhache / bash.sh
Created April 15, 2015 13:59
MySQL import from CSV files
mysqlimport -u root -p<password or prompt> -f --local <database> `pwd`/*.csv &> ../db_insert.log
@lrhache
lrhache / bash
Created April 15, 2015 02:57
Load up multiple .sql dump files into MySQL
find . -name '*.sql' | awk '{ print "source",$0 }' | mysql --batch -u xxx -p <database>
@lrhache
lrhache / bash
Created April 15, 2015 02:39
Set MySQL to EBS storage
sudo service mysql stop
sudo mkdir /ebs1/etc /ebs1/lib /ebs1/log
sudo mv /etc/mysql /ebs1/etc
sudo mv /var/lib/mysql /ebs1/lib
sudo mv /var/log/mysql /ebs1/log
sudo mkdir /etc/mysql /var/lib/mysql /var/log/mysql
echo "/ebs1/etc/mysql /etc/mysql none bind" | sudo tee -a /etc/fstab
sudo mount /etc/mysql
echo "/ebs1/lib/mysql /var/lib/mysql none bind" | sudo tee -a /etc/fstab
sudo mount /var/lib/mysql
@lrhache
lrhache / export-mssql-csv.ps1
Last active March 11, 2024 20:06
Export all tables from a database to CSV files - AWS MSSQL 2008 / Win 2008
set-alias installutil $env:windir\microsoft.net\framework\v2.0.50727\installutil
installutil -i "C:\Program Files\Microsoft SQL Server\100\Tools\Binn\Redist\Microsoft.SqlServer.Management.PSProvider.dll"
installutil -i "C:\Program Files\Microsoft SQL Server\100\Tools\Binn\Redist\Microsoft.SqlServer.Management.PSSnapins.dll"
Add-PSSnapin SqlServerCmdletSnapin100
Add-PSSnapin SqlServerProviderSnapin100
$SERVER_NAME="<SERVER NAME>"; $DB_NAME="<DB NAME>";$Tables = invoke-sqlcmd -query "SELECT name FROM sys.tables order by name" -database $DB_NAME -serverinstance $SERVER_NAME;foreach ($Table in $Tables){$TableName = $Table["name"];write-host -ForegroundColor Green "Creating File $TableName.csv";invoke-sqlcmd -query "SELECT * FROM $TableName" -database $DB_NAME -serverinstance $SERVER_NAME |export-csv -path D:\dump\$TableName.csv;}
@lrhache
lrhache / .bash_profile
Last active October 8, 2015 15:58
Install a new working environment
# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.
# the default umask is set in /etc/profile; for setting the umask
# for ssh logins, install and configure the libpam-umask package.
#umask 022
@lrhache
lrhache / list_unique_benchmark.py
Last active September 30, 2021 12:26
Two method to remove duplicates from a python list while keeping order
"""Benchmark multiple method of removing duplicates in a list
while keeping item's order in the list.
numpy.unique will likely be faster and more efficient
the more the list grows.
If a list is submitted to numpy.unique, it will be transformed and flattened
into a numpy.Array which it's data structure is more efficient than standard
lists since all elements have the same size in memory therefor requires less
access to the memory. Lists are stored as array of adresses pointing to
to the objects and requires more memory access (but more flexible).
@lrhache
lrhache / install.sh
Created April 5, 2014 03:19
phantomjs
cd /usr/local/share
wget http://phantomjs.googlecode.com/files/phantomjs-1.9.7-linux-x86_64.tar.bz2
tar xjf phantomjs-1.9.7-linux-x86_64.tar.bz2
sudo ln -s /usr/local/share/phantomjs-1.9.7-linux-x86_64/bin/phantomjs /usr/local/share/phantomjs
sudo ln -s /usr/local/share/phantomjs-1.9.7-linux-x86_64/bin/phantomjs /usr/local/bin/phantomjs
sudo ln -s /usr/local/share/phantomjs-1.9.7-linux-x86_64/bin/phantomjs /usr/bin/phantomjs
@lrhache
lrhache / install.sh
Last active August 29, 2015 13:58
PyQt in virtualenv
mkdir lib
cd lib
wget http://sourceforge.net/projects/pyqt/files/PyQt4/PyQt-4.10.4/PyQt-x11-gpl-4.10.4.tar.gz
tar xvf PyQt-x11-gpl-4.10.4.tar.gz
cd PyQt-x11-gpl-4.10.4/
python configure.py
make && make install