Skip to content

Instantly share code, notes, and snippets.

@ficapy
ficapy / exception_architecture.py
Last active July 18, 2016 00:05
打印模块的异常结构
import requests
import inspect
from collections import defaultdict
def _tree(): return defaultdict(_tree)
tree = _tree()
@ficapy
ficapy / cloudfront.py
Last active August 22, 2016 11:44
列出CloudFront的ip所在地
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Author: Ficapy
# Create: '8/22/16'
import requests
import ipaddress
import asyncio
import aiohttp
@ficapy
ficapy / CSharp_project_recommend.py
Created February 23, 2016 15:23
今天开始学C#,找几个小项目看源码练练手
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Author: Ficapy
# Create: '16/2/23'
import sys
if sys.version_info[0] < 3:
sys.exit(1)
from github import Github
@ficapy
ficapy / README.md
Last active December 12, 2016 06:47
celery+sqlalchemy architecture demo
  1. 启动celery

    celery -A base_celery worker --loglevel=info 
    
  2. 关闭celery(所有任务将丢失不会重启)

pkill -9 -f 'celery worker'

@ficapy
ficapy / google_chrome_webstore_devtools_users_rank.py
Created October 27, 2015 12:21
谷歌浏览器应用商店使用人数排行 P.S 因木有代理 使用单线程执行,有极少部分请求被ban没有得到结果
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Author: Ficapy
# Create: '15/10/27'
from pyquery import PyQuery as pq
from operator import attrgetter
from concurrent.futures import ThreadPoolExecutor, as_completed
from operator import methodcaller
import requests
@ficapy
ficapy / test_sqlalchemy.py
Created December 14, 2016 07:10
sqlalchemy+pytest
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Author: Ficapy
# Create: '12/14/16'
import pytest
from sqlalchemy import create_engine, Column, BIGINT
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.exc import IntegrityError
@ficapy
ficapy / sqlalchemy_test.py
Created June 2, 2017 12:51
namedtuple搭配sqlalchemy进行测试
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Author: ficapy
# Create: '5/25/17'
import inspect
from datetime import datetime
from sqlalchemy import inspection
from collections import namedtuple
from sqlalchemy import create_engine, Column, Integer, String, DateTime
@ficapy
ficapy / optimistic_lock.py
Created June 15, 2017 08:58
乐观锁和悲观锁以及事物隔离级别
# !/usr/bin/env python
# -*- coding: utf-8 -*-
# Author: ficapy
import time
import threading
from threading import Thread
from sqlalchemy import create_engine, Column, Integer
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
@ficapy
ficapy / tornado_db.py
Created August 1, 2017 03:37
tornado 数据库操作
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Author: ficapy
import threading
import functools
import tornado.ioloop
import tornado.web
from sqlalchemy import Column, create_engine
from sqlalchemy.dialects.mysql import INTEGER, BIT, VARCHAR
from sqlalchemy.ext.declarative import declarative_base
@ficapy
ficapy / RateLimited.py
Last active August 4, 2017 06:36
限制单位时间内函数执行次数
#https://gist.github.com/gregburek/1441055
#限制单位时间内函数执行次数
import time
from collections import deque
def RateLimited(minutes=1, limitNum=3):
status = deque([0] * limitNum, maxlen=limitNum)
def decorate(func):
def wrap(*args, **kwargs):