Skip to content

Instantly share code, notes, and snippets.

View duan-li's full-sized avatar

D Li duan-li

View GitHub Profile
@duan-li
duan-li / colored_bash.md
Created January 8, 2017 23:02
How to get a colored bash

open ~/.bashrc in text editor and uncomment line:

#force_color_prompt=yes

to be:

force_color_prompt=yes
@duan-li
duan-li / 010_Python_Basic.py
Last active January 4, 2017 04:02
Automate the Boring Stuff with Python
# Exception Handling
def spam(divideBy):
return 42 / divideBy
try:
print(spam(2))
print(spam(12))
print(spam(0))
print(spam(1))
except ZeroDivisionError:
@duan-li
duan-li / bash.sh
Last active February 18, 2023 00:26
youtube-dl and ffmpeg download audio
#download
youtube-dl -F <URL> # see all format
youtube-dl -f <format> <URL> # download format
# DASH decode
ffmpeg -i input.m4a -vn -acodec copy output.m4a # Solve: writing DASH m4a. Only some players support this container. Install ffmpeg or avconv to fix this automatically.
#mp3
ffmpeg -codecs help | grep 'mp3' # check mp3 codecs
ffmpeg -i input.m4a -acodec libmp3lame -ab 128k output.mp3
@duan-li
duan-li / stop_them.sh
Created September 23, 2016 03:52
clean homestead, stop some unnesseary services
sudo service beanstalkd stop
sudo service supervisor stop
sudo service memcached stop
sudo service hhvm stop
@duan-li
duan-li / class_extends.php
Last active June 21, 2016 00:06
fake multiple inheritance, use the magic function __call().
<?php
// ref: http://stackoverflow.com/questions/356128/can-i-extend-a-class-using-more-than-1-class-in-php
class B {
public function method_from_b($s) {
echo $s;
}
}
class C {
public function method_from_c($s) {
@duan-li
duan-li / my.ini
Created May 17, 2016 01:54
disable and remove bin log file
[mysqld]
skip-log-bin
innodb_file_per_table=1
expire_logs_days = 1
max_binlog_size = 10M
#use following detail to clean everything about bin log
#PURGE BINARY LOGS TO 'mysql-bin.000029';
#RESET MASTER;
@duan-li
duan-li / users_trend.sql
Created November 9, 2015 00:10
select query to find users trend from mysql
select count(id), join_datetime from customers
where status > 0
group by DATE(join_datetime)
order by join_datetime desc
select count(id), join_datetime from customers
where status > 0
group by MONTH(join_datetime)
order by join_datetime desc
@duan-li
duan-li / apache2-default-ssl-tls1.2.conf
Created October 13, 2015 23:33
setup apache2 SSL based on TLS 1.2
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin webmaster@localhost
ServerName domain.com.au
DocumentRoot /path-to-www
SuexecUserGroup web-data web-data
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error-ssl-html.log
CustomLog ${APACHE_LOG_DIR}/access-ssl-html.log combined
@duan-li
duan-li / all_privileges.sql
Created October 3, 2015 01:55
Enable Remote Access To MySQL Database
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'dbpassword' WITH GRANT OPTION;
FLUSH PRIVILEGES;
@duan-li
duan-li / initial_lamp.sh
Last active August 21, 2022 19:07
Ubuntu 14.04 LTS apache php-fpm setup
#!/bin/bash
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root" 1>&2
exit 1
fi
CURRENT_USER=$(id -u -n)
CURRENT_GROUP=$(id -g -n)
CURRENT_USER_HOME=$(eval echo ~${SUDO_USER})