Skip to content

Instantly share code, notes, and snippets.

View lvsmart's full-sized avatar
🎯
Focusing

lvsmart lvsmart

🎯
Focusing
View GitHub Profile
@lvsmart
lvsmart / app.py
Last active July 14, 2017 09:47
基于jwt的文件上传与下载flask服务
# -*- coding: utf-8 -*-
import datetime
import hashlib
import os
from functools import wraps
import jwt
from flask import Flask
from flask import request, jsonify, send_from_directory
from werkzeug.utils import secure_filename
@lvsmart
lvsmart / mysql_json_search.py
Last active May 11, 2017 08:33
mysql json query
def condition_sql(path, search_params):
from_condition = []
if not search_params:
return ''
if type(search_params) == list:
for i in search_params:
from_condition.append('JSON_CONTAINS(param_json, \'%s\', "%s")' % (json.dumps(i), path))
elif type(search_params) == dict:
for k, v in search_params.items():
if v:
@lvsmart
lvsmart / pca.js
Created November 25, 2016 03:43
地铁末班车查询
/**
* @author zhangsd
*
* treeast.com
*
**/
var gis =
{
"0111": "121.391832,31.116809",
"0112": "121.399814,31.126929",
#! /bin/bash
echo "kill $1"
port_array=$(lsof -ti tcp:$1)
echo $port_array
echo ${#port_array}
if [ ${#port_array} -gt 1 ]
then
import time
import math
def retry(tries, delay=3, backoff=2):
if backoff <= 1:
raise ValueError("backoff must be greater than 1")
tries = math.floor(tries)
if tries < 0:
raise ValueError("tries must be 0 or greater")
@lvsmart
lvsmart / cache_fibonacci.py
Last active September 9, 2016 03:08
test_decorator
def fibonacci(n, cache=None):
if cache is None:
cache = {}
if n in cache:
return cache[n]
if n <=1:
return 1
cache[n] = fibonacci(n - 1, cache) + fibonacci(n - 2, cache)
@lvsmart
lvsmart / aware_time.py
Created September 1, 2016 06:07
时间转换
# coding=utf-8
import datetime
import arrow
from django.conf import settings
def get_now():
"""
**返回当前时间**
@lvsmart
lvsmart / admin.py
Last active September 1, 2016 05:48
push
def push_order_po(modeladmin, request, queryset):
"""
推送指定的PO
"""
# TODO filter order
today = erp_time.day(2016, 3, 22)
push_presale_po.process_pre_order(FrappeClient(), today, 1, queryset)
@lvsmart
lvsmart / json_util.py
Created September 1, 2016 05:40
JSONEncoder
import json
from datetime import datetime
from uuid import UUID
class LogJSONEncoder(json.JSONEncoder):
"""
专门为了解决各种:``TypeError: xx is not JSON serializable``
"""
@lvsmart
lvsmart / idioms_README.md
Created January 6, 2015 07:17
python test

python_test

this is a test case for python