Skip to content

Instantly share code, notes, and snippets.

@shau-lok
shau-lok / docker-command.sh
Last active November 24, 2017 03:02
docker command
# remove container
docker rm -f c52306aaa82e
# run
docker run --name local-mysql -e MYSQL_ROOT_PASSWORD=password -itd mysql:latest
# execute
docker exec -it testxxx bash
# delete none images
@shau-lok
shau-lok / django_model.py
Last active February 2, 2018 01:36
django model
# Conditional Expressions https://docs.djangoproject.com/en/1.11/ref/models/conditional-expressions/
# QuerySet API https://docs.djangoproject.com/en/1.11/ref/models/querysets/
# OR 查询
from django.db.models import Q
Contact.objects.filter(Q(last_name__icontains=request.POST['query']) |
Q(first_name__icontains=request.POST['query']))
@shau-lok
shau-lok / docker-rm-unstage-images.sh
Created September 20, 2017 06:47
docker rm unstage images
# delete ^none image
docker rmi $(docker images | grep "^<none>" | awk '{print $3}')
➜ ~ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
test latest 153f83a4d28f 3 minutes ago 935MB
<none> <none> 780c3cd2f334 10 minutes ago 934MB
<none> <none> b9e62dde27c7 29 minutes ago 934MB
<none> <none> 33629fbd9790 About an hour ago 934MB
@shau-lok
shau-lok / apt-get-install-ping.sh
Created September 20, 2017 06:13
ubuntu install ping
# install ping
apt-get update
apt-get install iputils-ping
@shau-lok
shau-lok / docker-redis.sh
Created September 19, 2017 15:14
docker redis
# pull
docker pull redis
# run
docker run --name local-redis -itd redis
@shau-lok
shau-lok / docker-mysql.sh
Last active September 20, 2017 02:28
docker mysql
# pull
docker pull mysql
# run
docker run --name local-mysql -e MYSQL_ROOT_PASSWORD=password -itd mysql:latest
# enter
docker exec -it local-mysql bash
@shau-lok
shau-lok / docker-nginx.sh
Last active September 19, 2017 12:44
docker nginx
# pull image from docker hub
docker pull nginx
# run image
docker run --name local-nginx -p 8080:80 -itd nginx:latest
# enter image
docker exec -it local-nginx bash
@shau-lok
shau-lok / http_proxy.py
Created September 19, 2017 12:38
python http proxy
import requests
auth_user = 'imUser'
auth_password = 'imPassword'
proxy_host = '127.0.0.1'
proxy_port = '8888'
proxies = {
'all': f'http://{auth_user}:{auth_password}@{proxy_host}:{proxy_port}'
@shau-lok
shau-lok / socks_proxy.py
Last active September 19, 2017 12:33
python socks proxy
# pip install pysock
import socket
import socks
import requests
proxy_host = '127.0.0.1'
proxy_port = 1080
auth_user = 'imUser'
auth_password = 'imPassword'
@shau-lok
shau-lok / urlencode.py
Created September 14, 2017 07:50
url + params
from urllib.parse import urlencode
url = 'https://www.example.com'
params = {
'param1': 'p1',
'param2': 'p2'
}
url = f'{url}?{urlencode(params)}'