Skip to content

Instantly share code, notes, and snippets.

View beanyoung's full-sized avatar

BeanYoung beanyoung

  • ByteDance
  • Beijing, China
View GitHub Profile
@beanyoung
beanyoung / query_violation.py
Created October 28, 2013 03:50
query violation using api
while True:
if result.job_status in ['started', 'queued']:
sleep(result.sleep)
continue
elif result.vehicle_status == 'ok':
process_violation(result.violations)
break
elif result.vehicle_status == 'error':
# vehicle info error
break
@beanyoung
beanyoung / method_lock.py
Created October 14, 2013 02:29
A proxy that ensures only one method of class is running.
from functools import wraps
import threading
import types
lock = threading.Lock()
def method_lock(f):
@wraps(f)
def decorator(*args, **kwargs):
lock.acquire()
@beanyoung
beanyoung / singleton.py
Last active May 7, 2018 10:07
Ensure that only one instance running
#!/usr/bin/python
# -*- coding: utf-8 -*-
import fcntl
from functools import wraps
import os
def singleton(pid_filename):
def decorator(f):
@beanyoung
beanyoung / Makefile
Created December 15, 2011 05:18
make file template
CXX:=g++
SOURCE:=local-global-snake.cpp \
snake.cpp \
image-process.cpp
PROJECT_NAME:=local-global-snake
SOURCE_DIR:=source
RELEASE_DIR:=release
DEBUG_DIR:=debug