Skip to content

Instantly share code, notes, and snippets.

View bindiego's full-sized avatar
🎸
be cool

Bin Wu bindiego

🎸
be cool
View GitHub Profile
@bindiego
bindiego / purge_kernel.sh
Last active August 29, 2015 14:06
Shell scripts that are useful to clear your system.
#!/bin/sh -ex
##################
# Author: Bin Wu #
##################
dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge
@bindiego
bindiego / doit.py
Created September 10, 2014 06:44
plain text processing
import sys
import csv
import re
filein = open('lcshtopics-synonymlinkage.tsv', 'r')
#filein = open('abc.tsv', 'r')
fileout = open('out', 'w')
try:
i = 1
@bindiego
bindiego / homedir_bak.sh
Last active August 29, 2015 14:06
backup and synchronization
#!/bin/bash
# crontab settings
# 0 3 * * * <path to file>/homedir_bak.sh
rsync -acz /home/wubin /data/backup/wubin_home > /dev/null 2>&1 &
@bindiego
bindiego / push_es.sh
Created September 13, 2014 10:24
Push to ElasticSearch
for f in ${BATCH_DIR}/batch-*.json
do
echo "aboutto index $f"
curl --silent --show-error --request POST \
--data-binary @$f localhost:9200/_bulk > /dev/null 2>&1
echo
done
@bindiego
bindiego / showip.sh
Created September 16, 2014 07:22
Display ip address
ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'
@bindiego
bindiego / grant.sql
Last active December 31, 2019 09:26
mysql setup
GRANT ALL PRIVILEGES ON *.* TO 'mysqluser'@'%' IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
@bindiego
bindiego / show_relation.sql
Created September 19, 2014 08:05
Get a list of all foreign key constraints pointing to a particular table, a particular column.
select
TABLE_NAME,COLUMN_NAME,CONSTRAINT_NAME, REFERENCED_TABLE_NAME,REFERENCED_COLUMN_NAME
from INFORMATION_SCHEMA.KEY_COLUMN_USAGE
where
REFERENCED_TABLE_NAME = '<table>';
@bindiego
bindiego / apacheuser.sh
Created September 24, 2014 09:22
shows apache user
#!/bin/bash
APACHE_USER=$(ps axho user,comm|grep -E "httpd|apache"|uniq|grep -v "root"|awk 'END {if ($1) print $1}')
echo $APACHE_USER
@bindiego
bindiego / kill_zombies.sh
Last active August 29, 2015 14:07
Kill zombies
#!/bin/sh -ex
# find zombie pid
# ps aux | awk '{ print $8 " " $2 }' | grep -w Z
# kill -9 PID
# All in one cmd does all
kill -HUP `ps -A -ostat,ppid | grep -e '^[Zz]' | awk '{print $2}'`
@bindiego
bindiego / mongod.sh
Last active December 26, 2015 13:23
MongoDB startup script
#!/bin/bash
mongod=/usr/local/mongodb/bin/mongod
mongod_data=/Users/michito/work/mongodb_data
mongod_log=/Users/michito/work/mongodb_log/mongodb.log
prog=mongod.sh
RETVAL=0
stop() {
grep_mongo=`ps aux | grep -v grep | grep "${mongod}"`