Skip to content

Instantly share code, notes, and snippets.

View honmaple's full-sized avatar

honmaple honmaple

View GitHub Profile
@honmaple
honmaple / paginate.html
Created May 26, 2016 14:29
flask use paginate
{% macro paginate(pagination, endpoint,kw=None) %}
<ul class="pagination" style="margin:0">
{% if pagination.items and pagination.pages > 1 -%}
{%- if pagination.has_prev -%}
{%- if not kw -%}
<li><a href="{{ url_for(endpoint,page=pagination.page-1)}}" aria-label="Previous"><span aria-hidden="true">&laquo;</span></a></li>
{%- else -%}
<li><a href="{{ url_for(endpoint,page=pagination.page-1,**kw)}}" aria-label="Previous"><span aria-hidden="true">&laquo;</span></a></li>
{% endif -%}
{%- else %}
@honmaple
honmaple / Get zero datetime
Created September 23, 2016 01:11
得到当天零点时间
today = datetime.datetime.today()
b = datetime.datetime(today.year, today.month, today.day, 0, 0, 0)
print(b)
now = time.time()
midnight = now - (now % 86400) + time.timezone
itime = time.ctime(midnight)
print(itime)
@honmaple
honmaple / datetime or time to string
Created September 23, 2016 01:14
python时间或时间戳与字符串转换
#把datetime转成字符串
def datetime_toString(dt):
return dt.strftime("%Y-%m-%d-%H")
#把字符串转成datetime
def string_toDatetime(string):
return datetime.strptime(string, "%Y-%m-%d-%H")
#把字符串转成时间戳形式
def string_toTimestamp(strTime):
@honmaple
honmaple / Restful View Pemission
Created October 12, 2016 02:15
restful形式的权限管理 based on flask
class RestfulBase(object):
decorators = ()
def __call__(self, func):
f = self.method(func)
if self.decorators:
for dec in reversed(self.decorators):
f = dec(f)
return f
@honmaple
honmaple / validator
Last active October 26, 2016 06:07
数据校验
class DataValidator(object):
def __init__(self, values, validators, force=False, callback=None):
self.values = values
self.validators = validators
self.callback = callback
self.force = force
def check(self):
values = self.values.copy()
for k, v in self.validators.items():
@honmaple
honmaple / session.py
Last active July 20, 2017 06:37
tornado session include memory and redis
from uuid import uuid4
from redis import StrictRedis
from functools import wraps
from datetime import datetime
from pytz import timezone
def singleton(cls):
instances = {}
package main
import (
"compress/gzip"
"flag"
"fmt"
"io"
"os"
)
@honmaple
honmaple / re_multiline_test.go
Created September 5, 2021 14:54
golang多行匹配与逐行匹配性能
package main
import (
"fmt"
"regexp"
"strings"
"testing"
)
var template = `
@honmaple
honmaple / upload.go
Created September 10, 2021 10:24
upload multi file with golang http client
package main
import (
"bytes"
"fmt"
"io"
"io/ioutil"
"mime/multipart"
"net/http"
"os"
@honmaple
honmaple / slice_pass_test.go
Created February 11, 2022 06:45
test function slice param
package main
import (
"testing"
)
type myStruct struct {
list []string
}