Skip to content

Instantly share code, notes, and snippets.

View leafsummer's full-sized avatar
🎯
Focusing

LeafSummer leafsummer

🎯
Focusing
View GitHub Profile
#!/usr/bin/env python
import re
text = u'This dog \U0001f602'
print(text) # with emoji
emoji_pattern = re.compile("["
u"\U0001F600-\U0001F64F" # emoticons
u"\U0001F300-\U0001F5FF" # symbols & pictographs
u"\U0001F680-\U0001F6FF" # transport & map symbols
u"\U0001F1E0-\U0001F1FF" # flags (iOS)
"]+", flags=re.UNICODE)
@leafsummer
leafsummer / singleton_bus.py
Created March 30, 2017 10:53
singleton bus for the thread running
#encoding=utf8
import threading
import time
#这里使用方法__new__来实现单例模式
class Singleton(object):#抽象单例
def __new__(cls, *args, **kw):
if not hasattr(cls, '_instance'):
orig = super(Singleton, cls)
cls._instance = orig.__new__(cls, *args, **kw)
return cls._instance
@leafsummer
leafsummer / writer_queue.py
Created July 17, 2017 08:11
a writer thead to database with queue for handling the many requests
class AsyncCursor(object):
def __init__(self, event, sql, params, timeout):
self._event = event # Used to signal when results are ready.
self.sql = sql
self.params = params
self.timeout = timeout
self._cursor = None
self._rows = None
self._ready = False
@leafsummer
leafsummer / config.fish
Created August 3, 2021 10:53 — forked from pierre-b/config.fish
golang fish shell config
# config file
# vim ~/.config/fish/config.fish
# reload the config
# source ~/.config/fish/config.fish
# set the workspace path
set -x GOPATH /users/my-username/go
# add the go bin path to be able to execute our programs
@leafsummer
leafsummer / func_timeout.py
Created May 10, 2021 03:00
[function timeout decorator]
from threading import Thread
ThreadStop = Thread._Thread__stop
class TimeoutException(Exception):
pass
def timelimited(timeout):
@leafsummer
leafsummer / daemonize_class.py
Last active May 8, 2021 09:31
daemonize a process class of python script
import os
import sys
import time
import atexit
class Daemon(object):
def __init__(self, pidfile="/dev/null", stdin="/dev/null", stdout="/dev/null", stderr="/dev/null"):
@leafsummer
leafsummer / walk_up.py
Created May 7, 2021 10:49
[walk up directory for list all files]
def walk_up(bottom):
"""mimic os.walk, but walk 'up' instead of down the directory tree.
From: https://gist.github.com/zdavkeos/1098474
"""
bottom = os.path.realpath(bottom)
# get files in current dir
try:
names = os.listdir(bottom)
@leafsummer
leafsummer / gist:8b74d99bee233514db8f96239a2fb004
Created April 10, 2021 09:40 — forked from david415/gist:8274636
/etc/ufw/before.rules - for use with tor...
#
# rules.before
#
# Rules that should be run before the ufw command line added rules. Custom
# rules should be added to one of these chains:
# ufw-before-input
# ufw-before-output
# ufw-before-forward
#
@leafsummer
leafsummer / aes_python.py
Created March 5, 2021 02:08
[python aes cbc encrypt]
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# FileName : aes_python.py
# must install the pycrypto at frist, cmd: pip install pycrypto
import hashlib
from Crypto.Cipher import AES
import base64
@leafsummer
leafsummer / arch_aws.plantuml
Created September 1, 2020 07:19
[plantuml learning]
@startuml Basic Sample
!include <awslib/AWSCommon>
!includeurl https://raw.githubusercontent.com/RicardoNiepel/C4-PlantUML/release/1-0/C4_Container.puml
' Uncomment the following line to create simplified view
' !include <awslib/AWSSimplified>
!include <awslib/General/all>
!include <awslib/NetworkingAndContentDelivery/all>