Skip to content

Instantly share code, notes, and snippets.

@codeif
codeif / phpserialize.py
Created September 8, 2020 11:36 — forked from sj26/phpserialize.py
Python port of PHP serialize() and unserialize()
#!/usr/bin/python -u
"""
Python port of PHP serialize() and unserialize()
by Samuel Cochran <[email protected]>
I couldn't find a nice, fairly efficient implementation of serialize/unserialize for Python... so I wrote one. I didn't use str().partition because I wanted Python <2.5 compatibility.
TODO: Performance review. There's an awful lot of string copying. >.>
import aiohttp
import asyncio
async def main():
session = aiohttp.ClientSession()
ws = await session.ws_connect(
'wss://ws.example.com/channel')
while True:
msg = await ws.receive()
def get_right_img(image):
# https://stackoverflow.com/a/6218425/7403042
if not hasattr(image, '_getexif'):
return image
image_exif = image._getexif()
if not image_exif:
return image
image_orientation = image_exif[274]
# Rotate depending on orientation.
@codeif
codeif / post-receive
Last active February 13, 2019 15:14
git自动部署hooks
#!/usr/bin/env bash
GIT_WORK_TREE='..'
while read oldrev newrev ref
do
echo "******************** $oldrev $newrev $ref *****************************"
if [[ "$newrev" =~ ^0+$ ]]; then
exit 0
fi
echo "Commit ref received. Deploying ..."
@codeif
codeif / git-auto-commit-push.sh
Last active January 30, 2019 18:13
git 自动 commit and push
#!/usr/bin/env bash
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
echo "crreunt branch is $CURRENT_BRANCH"
if [[ $CURRENT_BRANCH =~ ^[0-9]{2}-[0-9]{4}$ ]]; then
ST=$(git st)
if [[ $ST != *"nothing to commit"* ]]; then
echo "commit and push"
git ci -am "0"
git push
echo "finish push"
@codeif
codeif / unzip.py
Created April 20, 2017 18:04
unzip.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
解决mac下解压zip文件乱码问题
代码参考:
http://stackoverflow.com/questions/9431918/extracting-zip-file-contents-to-specific-directory-in-python-2-7
http://www.zhihu.com/question/20523036/answer/35225920
http://stackoverflow.com/questions/4917284/extract-files-from-zip-without-keeping-the-structure-using-python-zipfile
编码: https://docs.python.org/2.4/lib/standard-encodings.html
@codeif
codeif / tmux-cheatsheet.markdown
Created April 14, 2017 07:33 — forked from MohamedAlaa/tmux-cheatsheet.markdown
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@codeif
codeif / check_port.py
Created April 11, 2017 03:50
check socket port
# -*- coding: utf-8 -*-
import socket;
from contextlib import closing
socket.setdefaulttimeout(0.5)
import socket
from contextlib import closing
def check_socket(host, port):
@codeif
codeif / http_basic_auth_demo.py
Last active March 23, 2017 11:45
Flask HTTPBasicAuth
# -*- coding: utf-8 -*-
from flask import Flask, request, abort
app = Flask(__name__)
@app.route('/')
def index():
return 'Hello World'
@codeif
codeif / remove-old-tags.sh
Last active June 13, 2018 15:33
git remove old tags script
#!/usr/bin/env bash
sync_tags() {
git tag | xargs git tag -d
git fetch $1 -p
}
# git只保留最新的N个tag
N=15
git push --tags
sync_tags origin