Skip to content

Instantly share code, notes, and snippets.

@shau-lok
shau-lok / django-url.py
Created January 9, 2018 08:44
django-url
# https://docs.djangoproject.com/en/2.0/topics/http/urls/
# django的url正则匹配
from django.urls import path, re_path
from . import views
urlpatterns = [
path('articles/2003/', views.special_case_2003),
@shau-lok
shau-lok / docker-mongo.sh
Last active January 17, 2019 23:33
docker-mongo
$ docker pull mongo:3.0.15-wheezy
$ docker run --name mongo -itd -p 27017:27017 mongo:3.0.15-wheezy --auth
# 增加admin管理账号
$ docker exec -it mongo mongo admin
> use admin
switched to db admin
@shau-lok
shau-lok / regular.py
Created November 21, 2017 13:44
Regular Expression -正则表达式
import
# 匹配3到6个数字
re.findall('\d{3,6}', words)
# 匹配 reservation_grid$ctl06$lnkcancel
words= "javascript:__doPostBack('reservation_grid$ctl06$lnkcancel','')"
re.findall('\(\'(.*)\',\'',href)
@shau-lok
shau-lok / mysql-command.sql
Last active July 7, 2018 14:00
mysql-command
-- get now
select DATE(NOW());
-- date between
WHERE CONVERT(start_date, DATE) => DATE(NOW()) AND CONVERT(end_date, DATE) => DATE(NOW();
-- 7天前 2017-10-25
select convert(NOW(), DATE) - interval 7 day;
-- 今天
@shau-lok
shau-lok / django-model-migrate.py
Created November 1, 2017 08:20
django model migrate
# https://docs.djangoproject.com/en/1.11/topics/migrations/
# which is responsible for applying and unapplying migrations.
python manage.py migrate
# which is responsible for creating new migrations based on the changes you have made to your model
python manage.py makemigrations
@shau-lok
shau-lok / python_imaplib.py
Created November 1, 2017 02:42
python imaplib
# Mark email as seen
mail.uid('store', uid, '+FLAGS', '\SEEN')
@shau-lok
shau-lok / check-string.py
Created November 1, 2017 02:40
Check if a Python list item contains a string inside another string
# Check if a Python list item contains a string inside another string
# If you only want to check for the presence of abc in any string in the list, you could try
some_list = ['abc-123', 'def-456', 'ghi-789', 'abc-456']
if any("abc" in s for s in some_list):
# whatever
# If you really want to get all the items containing abc, use
matching = [s for s in some_list if "abc" in s]
@shau-lok
shau-lok / terminal-du,df.sh
Last active January 17, 2019 23:33
terminal-du,df
# get current dir size!
$ du -sh
>>> 224M .
# get specific file (logs) size!
$ du -sh logs
>>> 2.7M logs
# get disk useage
$ df -h
@shau-lok
shau-lok / terminal-proxy.md
Created October 23, 2017 02:52
terminal set proxy

add to ~/.zshrc

alias setproxy="export ALL_PROXY=socks5://127.0.0.1:1080"
alias unsetproxy="unset ALL_PROXY"
alias ip="curl -i http://httpbin.org/ip"

then restart termainl

@shau-lok
shau-lok / include.cpp
Created September 30, 2017 06:16
cpp include
#include <file>
//This variant is used for system header files. It searches for a file named file in a standard list of system directories.
#include "file"
//This variant is used for header files of your own program. It searches for a file named file first in the directory containing the current file, then in the quote directories and then the same directories used for <file>. You can prepend directories to the list of quote directories with the -iquote option