Skip to content

Instantly share code, notes, and snippets.

scturtle

View GitHub Profile
@scturtle
scturtle / autolock.sh
Last active Jul 24, 2020
手机插电脑解锁拔下来锁屏
View autolock.sh
#!/bin/bash -x
VENDOR="05ac:12a8"
SERIAL="XXXXXXXXXXXXXXXXX"
#LOCK="gnome-screensaver-command -l"
#UNLOCK="gnome-screensaver-command -d"
LOCK="slock"
UNLOCK="killall slock"
while true; do
# wait new device status
stdbuf -o0 udevadm monitor --udev | stdbuf -o0 grep usb | head -n1 > /dev/null
@scturtle
scturtle / server.py
Last active Jun 27, 2020
python socks5 proxy server with asyncio (async/await)
View server.py
#!/usr/bin/env python3.5
import socket
import asyncio
from struct import pack, unpack
class Client(asyncio.Protocol):
def connection_made(self, transport):
self.transport = transport
self.server_transport = None
@scturtle
scturtle / proxy.py
Last active Jun 22, 2020
use opera's built-in VPN as proxy
View proxy.py
#!/usr/bin/env python3
import asyncio
from vpn import get_proxy
proxy = port = auth = None
pool = asyncio.Queue(5)
psize = 0
async def process_client(client_reader, client_writer, *, CHUNK=4096):
global psize
@scturtle
scturtle / ftpserver.py
Created Jun 20, 2011
simple ftp server by python
View ftpserver.py
#!/usr/bin/env python2
# coding: utf-8
import os,socket,threading,time
#import traceback
allow_delete = False
local_ip = socket.gethostbyname(socket.gethostname())
local_port = 8888
currdir=os.path.abspath('.')
@scturtle
scturtle / ast_dump.py
Created Dec 16, 2017
Dump Clang AST with python bindings.
View ast_dump.py
#!/usr/bin/env python3
import sys
import clang.cindex
INDENT = 4
K = clang.cindex.CursorKind
def is_std_ns(node):
return node.kind == K.NAMESPACE and node.spelling == 'std'
View txt2epub.py
# coding: utf-8
import os
#书籍信息
title='test book'
creator='scturtle'
description='blablablabla'
#章节文件
txtlist=['1.txt','2.txt']
View rg.py
plain = r'foo'
anchor = r'k$'
ranges = r'^[a-f]*$'
backrefs = r'(...).*\1'
abba = (r'^(?!' # don't (
r'.*(.)(.)\2\1.*' # parttern like abba
r'$)') # ) select
plan = r'^(.)(.).*\2\1$'
View .clang-format
BasedOnStyle: LLVM
IndentWidth: 4
BreakBeforeBraces: Custom
ColumnLimit: 80
BraceWrapping:
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
@scturtle
scturtle / backup.sh
Last active Mar 14, 2020
script to backup file to dropbox
View backup.sh
!/usr/bin/bash
DROPBOX_KEY='XXXXXX'
FILENAME=XXXXXX
cd XXXXXX
tar czf $FILENAME XXXXXX > /dev/null
/usr/bin/python - <<END
import dropbox
from dropbox.files import WriteMode
from os.path import getsize, basename
dbx = dropbox.Dropbox('$DROPBOX_KEY')
@scturtle
scturtle / gevent.py
Last active Feb 1, 2020
Let's go HTTPS!
View gevent.py
from gevent import monkey
monkey.patch_all()
import bottle
class SSLWebServer(bottle.ServerAdapter):
def run(self, handler):
from gevent.pywsgi import WSGIServer
srv = WSGIServer((self.host, self.port), handler,
certfile='/etc/letsencrypt/live/XXX/fullchain.pem',
You can’t perform that action at this time.