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 / 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
@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 / 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 / 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
int_arr = [97, 98, 99, 100, 101]
char_arr = ''.join([unichr(i) for i in int_arr])
@beanyoung
beanyoung / diffbot_demo.py
Created January 2, 2014 16:26
diffbot demo
from diffbot import Client
c = Client('demo_token')
url = 'http://www.diffbot.com/products/automatic/article/'
json_object = c.get('/v2/article', url)
data = 'Now is the time for all good robots to come to the aid of their-- oh never mind, run!'
json_object = c.post('/v2/article', url, content_type='text-plain', data=data)
@beanyoung
beanyoung / flask_thrift_server.py
Last active October 8, 2020 15:12
thrift server based on flask
from flask import Flask, request, make_response
from thrift.protocol import TBinaryProtocol
from thrift.server import TServer
from thrift.transport import TTransport
from FooService import FooService
from foo_service_handler import FooServiceHandler
#!/usr/bin/python
# -*- coding: utf-8 -*-
import requests
# api = 'https://api.xmpush.xiaomi.com/v2/message/regid'
api = 'https://sandbox.xmpush.xiaomi.com/v2/message/regid'
secret = 'demo_secret'
import sys
template = """
def test_%s():
pass
"""
def main():
<?php
$app_key = 'demo_key';
$app_secret = 'demo_secret';
$rfc_1123_date = gmdate('D, d M Y H:i:s T', time());
file_put_contents('./log.txt',json_encode($_POST),FILE_APPEND);
// $_POST['job_id'] ='577c460f-140a-4112-8898-a943ea020ccc';
if(isset($_POST['job_id'])){