Skip to content

Instantly share code, notes, and snippets.

View oilbeater's full-sized avatar
🎯
Focusing

Mengxin Liu oilbeater

🎯
Focusing
View GitHub Profile
@oilbeater
oilbeater / python_fib
Created February 1, 2015 06:04
python fib
ref = 'https://docs.python.org/3/library/functools.html'
@lru_cache(maxsize=None)
def fib(n):
if n < 2:
return n
return fib(n-1) + fib(n-2)
@oilbeater
oilbeater / python
Last active February 28, 2018 11:55
python
// use shell command
import subprocess
output = subprocess.check_output('dir', shell=True)
print(output)
@oilbeater
oilbeater / SHELLs
Created October 31, 2014 06:17
Common used shells
#Batch move
ls | head -n 50 | xargs -i mv {} mvdir/
#Batch files replace
sed -i "s/older/newser/g" `grep -li older *`
@oilbeater
oilbeater / count_database.sh
Last active August 29, 2015 14:08
Count database row number
#!/bin/bash -x
# To count row number of each table in a schema
# Example: echo 127.0.0.1 root rootpassword rootdatabase | ./count_database.sh 2>/dev/null
while read host username password schema;
do
mysql -h$host -u$username -p$password -Ne "select table_name from information_schema.tables where table_schema='${schema}'"|
while read table;
do
@oilbeater
oilbeater / SQLs
Last active August 29, 2015 14:08
Common sql statement
* Change the column property
ALTER TABLE table_name MODIFY COLUMN column_name VARCHAR(50);
* Create table from exist table
CREATE TABLE table_name LIKE exist_table; //empty table with same structure
CREATE TABLE table_name AS SELECT * FROM exist_table; //copy the whole table
* Estimate rough row number of a database
SELECT TABLE_NAME,TABLE_ROWS FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=table_schema; // this is only an estimate,not the exact one!!!!!