This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// use shell command | |
import subprocess | |
output = subprocess.check_output('dir', shell=True) | |
print(output) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Batch move | |
ls | head -n 50 | xargs -i mv {} mvdir/ | |
#Batch files replace | |
sed -i "s/older/newser/g" `grep -li older *` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* 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!!!!! |
NewerOlder