Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

shellbye Shellbye

🎯
Focusing
View GitHub Profile
@Shellbye
Shellbye / auth3.py
Created Dec 4, 2018
python3 authentication bearer demo
View auth3.py
import urllib.request
headers = {"Authorization":"Bearer eyJhbGciOiJIUzUxMiJ1.eyJzdWIiOiJhZG1pbiIsImF1dGhvcml0aWVzIjpbIlJPTEVfQURNSU4iXSwiaWF0IjoxNTQzOTA0NTY5LCJleHAiOjE1NDM5OTA5Njl9.0MLfJa9oud0ZMNC2e0q8YciuuB1G56KZH3m87ilrd7ryy4sjtR2U0MQnWSd89u-liWo1gLAgX9OyIDUnFXzJUw"}
req = urllib.request.Request(url="http://127.0.0.1:8090", headers=headers)
contents = urllib.request.urlopen(req).read()
print(contents)
@Shellbye
Shellbye / auth.py
Last active Dec 4, 2018
python2 authentication bearer demo
View auth.py
import urllib2
headers = {"Authorization":"Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZG1pbiIsImF1dGhvcml0aWVzIjpbIlJPTEVfQURNSU4iXSwiaWF0IjoxNTQzOTA0NTY5LCJleHAiOjE1NDM5OTA5Njl9.1MLfJa9oud0ZMNC2e0q8YciuuB1G56KZH3m87ilrd7ryy4sjtR2U0MQnWSd89u-liWo1gLAgX9OyIDUnFXzJUw"}
req = urllib2.Request(url="http://127.0.0.1:8090", headers=headers)
contents = urllib2.urlopen(req).read()
print(contents)
@Shellbye
Shellbye / compare_image_similarity.sh
Created Sep 19, 2017
compare two image similarity
View compare_image_similarity.sh
# -*- coding:utf-8 -*-
# Created by shellbye on 2017/9/19.
from PIL import Image
from skimage.measure import compare_ssim as ssim
import numpy as np
# requirements
# pip install scikit-image
# pip install pillow
@Shellbye
Shellbye / install_python.sh
Last active Jul 12, 2017
Install python on Ubuntu
View install_python.sh
sudo apt-get update
sudo apt-get install -y build-essential
sudo apt-get install -y libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev
version=2.7.13
cd /tmp
wget https://www.python.org/ftp/python/$version/Python-$version.tgz
tar -xvf Python-$version.tgz
@Shellbye
Shellbye / nginx_grok.conf
Last active Jul 8, 2020
uwsgi & nginx grok pattern
View nginx_grok.conf
# https://logz.io/blog/nginx-access-log-monitoring-dashboard/
input {
file {
type => nginx_web
path => "/var/log/nginx/*"
exclude => "*.gz"
}
}
@Shellbye
Shellbye / uwsgi_start_boots.txt
Created May 4, 2017
uwsgi start when system boots
View uwsgi_start_boots.txt
# http://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html#make-uwsgi-startup-when-the-system-boots
# create a directory for the vassals
sudo mkdir /etc/uwsgi
sudo mkdir /etc/uwsgi/vassals
# symlink from the default config directory to your config file
sudo ln -s /path/to/your/mysite/mysite_uwsgi.ini /etc/uwsgi/vassals/
# run the emperor
uwsgi --emperor /etc/uwsgi/vassals --uid www-data --gid www-data
@Shellbye
Shellbye / nginx_load_balance.conf
Created Apr 18, 2017
nginx load balance simple demo
View nginx_load_balance.conf
# nginx_load_balance.conf
# https://www.nginx.com/resources/admin-guide/load-balancer/
upstream backend {
server 127.0.0.1:8000;
server 192.168.1.1;
server domain.to.other.server;
}
server {
listen 80;
@Shellbye
Shellbye / nginx.conf
Last active Apr 11, 2017
uwsgi zero downtime restart config Zerg Dance
View nginx.conf
# nginx.conf
# the upstream component nginx needs to connect to
upstream my_project {
server 127.0.0.1:3031
}
# configuration of the server
server {
# the port your site will be served on
@Shellbye
Shellbye / multi_proc_list.py
Created Apr 6, 2017
process list with multiprocess
View multi_proc_list.py
# -*- coding:utf-8 -*-
# Created by shellbye on 2017/3/10.
import multiprocessing
def multi_process_list(process_num=None, func=None, list_to_process=None, **kwargs):
"""
处理多进程任务的框架,用于按段处理list数据
:param process_num: 进程数
:param func: 对每段list的处理方法,需要接收三个参数:queuestart_posoffset
@Shellbye
Shellbye / demo.py
Created Mar 30, 2017
sphinxsearch python mysql
View demo.py
import MySQLdb
conn = MySQLdb.connect(host="127.0.0.1", port=9306)
cursor = conn.cursor()
cursor.execute("select * from test1 where MATCH ('@content another')")
rows = cursor.fetchall()
for row in rows:
for i in range(len(row)):
print row[i]