- 🌈 I’m currently working hard
- 📫 How to reach me: https://blog.csdn.net/orangleliu
orangle / blog Goto Github PK
View Code? Open in Web Editor NEW博客--自我学习监督
Home Page: http://orangleliu.info
博客--自我学习监督
Home Page: http://orangleliu.info
直接下载地图通过import导入总是报错
Can't read property 'custom/world-continents' of undefined, using Highcharts.maps['custom/world-continents']
或者是 Highcharts not defined
地图引入 以及 案例 https://gist.github.com/oysteinmoseng/99808bc853faa80294c3066e4da951cb
麻烦的就是js地图数据es6不能直接引用 需要使用 module.exports =
来替换之前的属性写法
看到越来越多的直接使用binlog来进行一些回复还有自定义同步的操作,例如从mysql同步数据到redis或者mongodb等,很神奇。通过binlog可以及时的查看数据库正在进行的 增删改操作(查询只能通过抓包或者是query log来分析了)
Github 给我们带来太多的惊喜了,用来开源,用来写书,用来分享,用来弄博客。 现在决定用它来改掉坏毛病!下面给出一些目标和问题,每天写一个简报来监督。
坏习惯监督
开发中一些简单的web防御
时间戳,和时间戳转换
In [13]: import time
In [14]: t = time.time()
In [15]: t
Out[15]: 1435138598.654128
In [16]: import datetime
In [18]: time.mktime(datetime.datetime.now().timetuple())
Out[18]: 1435138684.0
In [19]: time.mktime(datetime.datetime.now().date().timetuple())
Out[19]: 1435075200.0
In [20]: datetime.datetime.fromtimestamp(1435075200.0).strftime('%Y-%m-%d %H:%M:%S')
Out[20]: '2015-06-24 00:00:00'
时间戳到字符格式化
import datetime
def timestamp_to_strtime(timest):
return datetime.datetime.fromtimestamp(
int(timest)
).strftime('%Y-%m-%d %H:%M:%S')
字符格式化到时间戳
def get_str_to_stamp(mtime):
dtime = datetime.strptime(mtime, "%Y-%m-%d %H:%M")
return int(time.mktime(dtime.timetuple()))
获得2个日期之间的天数
def get_order_valid_days(plan_end, plan_start):
return (plan_end - plan_start).days + 1
电脑里已经下载了数不清的PDF,家里的书架上也摆上了各种技术书籍,再看看浏览器收藏夹中也满满的一列电子书了,烟花缭乱的。 技术书籍层出不穷,可以是又万变不离其宗,太多的书就是个文档翻译,太多的数就是博客搜集,回归基础,把计划要看的,正在看的书列在此处,记录阅读生涯。
功能权限比较好做,数据权限有些麻烦。 比较通用的是 rbac权限
perf, sysdig, dtrace, strace, bcc-tools
没有专门的运维人员,所以自己的应用只有自己来做运维了,服务器只有那么几台(<10)。 装软件,部署系统,还有一些基本的监控呀,问题查找啊,虽然只有几台机器,但是运维的事情也不少,还挺繁杂。在此记录和总结一些想法和心得,希望能把自己的这点事理顺。
工作分支
程序开发中需要注意的关键词,以及自己的理解和做法等
在不懂和不会用设计模式这些东西的时候,DRY,KISS原则为主。
提示:需求较多,请谨慎, windows也没测试, macos上使用。 需要 国外主机一个,Python比较多的依赖环境,了解Python还有对ss代理原理有一定理解。(自己本来用Python开发较多,所以基础环境都有)
用到了 Twisted
和 twunnel
(感谢这个库的作者) 这两个Python的库。主要是折腾着玩,不过也挺好用。
写博客开始在51cto后来是CSDN 再后来自己弄了个静态博客,最看重的还是markdown这种简单的文本编辑方式,即使用静态博客也是要经常弄主题,生成,上传,挺麻烦。其实现在对于写东西最本质的需求就是记录和分享。干嘛弄那么麻烦呢,所以也开始尝试用这种简单的方式。
上学那会根本没有想过干软件这一行,毕业的时候为了工作才匆匆茫茫学起来,干一行爱一行。 虽说技术上一直没有什么质的飞跃,还是要一如既往的坚持学习和实践。 抛弃浮华,坚持初心应该才是做技术这一行的座右铭。这里记录下自己的技术栈,以及想要的技术能力,算是自我监督和规划。
C
系统编程的不二选择,熟悉即可。主要的目的是学习算法,数据结构,和操作系统底层汇编
有印象即可,主要用来理解底层运作机制,以及编译原理等知识。GO
语言 持续关注中,目前不会,需要网络编程时候会选择。Python
现在是主要使用的编程语言,需要熟练并熟悉,业务层,WEB开发,以及原型主要用它来实现。Lua
胶水语言,嵌入式环境,DSL环境,还有Openresty中会用到,高性能开发中,应用逻辑实现的好方式。记录下那些简单,又容易忘掉,并且有用的技巧等。
threading.local()
用来保存当前线程级别的变量,给人的感觉是就当前线程的全局变量,每个线程维持自己的拷贝。如果我想在django的一个请求处理中,任何位置获取user或者是request对象,如果采用一般的方式,就需要传递 request对象,或者解析出request中的内容,在传递。 如果使用 threading.local()
做一个middlewire,在请求进来的时候把request和user对象放到local中,那么在这个请求的处理函数中,直接就可以从local中得到这两个对象,不需要直接把他们传参到函数中。
说的有点绕人,看看代码比较容易明白,下面是几个开源项目用到的这个技巧
每次当你需要当前用户的时候 current_request()
就能轻松的得到了,而不需要通过参数来传递
# coding: utf-8
"""
:copyleft: 2009-2011 by the django-tools team, see AUTHORS for more details.
:license: GNU GPL v3 or above, see LICENSE for more details.
"""
from __future__ import absolute_import, division, print_function
try:
from threading import local
except ImportError:
from django.utils._threading_local import local
_thread_locals = local()
def get_current_request():
""" returns the request object for this thread """
return getattr(_thread_locals, "request", None)
def get_current_user():
""" returns the current user, if exist, otherwise returns None """
request = get_current_request()
if request:
return getattr(request, "user", None)
class ThreadLocalMiddleware(object):
""" Simple middleware that adds the request object in thread local storage."""
def process_request(self, request):
_thread_locals.request = request
def process_response(self, request, response):
if hasattr(_thread_locals, 'request'):
del _thread_locals.request
return response
def timefn(fn):
@wraps(fn)
def count_time(*args, **kwargs):
st = time.time()
res = fn(*args, **kwargs)
ed = time.time()
print "@time: {0} tasks {1} secs".format(fn.func_name, str(ed-st))
return res
return count_time
import time
from functools import wraps
def retry(ExceptionToCheck, tries=4, delay=3, backoff=2, logger=None):
def deco_retry(f):
@wraps(f)
def f_retry(*args, **kwargs):
mtries, mdelay = tries, delay
while mtries > 1:
try:
return f(*args, **kwargs)
except ExceptionToCheck, e:
msg = "%s, Retrying in %d seconds..." % (str(e), mdelay)
if logger:
logger.warning(msg)
else:
print msg
time.sleep(mdelay)
mtries -= 1
mdelay *= backoff
return f(*args, **kwargs)
return f_retry # true decorator
return deco_retry
http://blog.dhananjaynene.com/2013/10/partially-applied-functions-and-decorators-in-python/
from functools import wraps
def trace(trace_arguments = False) :
def decorator(func) :
@wraps(func)
def wrapper(*args, **kwargs) :
if trace_arguments :
print("Entering {} with arguments {} {}".format(
func.__name__, args, kwargs))
else :
print("Entering {}".format(func.__name__))
ret = func(*args, **kwargs)
if trace_arguments :
print("Leaving {} with result {}".format(func.__name__, ret))
else :
print("Leaving {}".format(func.__name__))
return ret
return wrapper
return decorator
# using a global for brevity
function_calls = 0
def track(func) :
@wraps(func)
def wrapper(*args, **kwargs):
global function_calls
function_calls = function_calls + 1
return func(*args, **kwargs)
return wrapper
@track
@trace(True)
def add(a, b) :
return a + b
print("Function calls so far {}".format(function_calls))
print("3 + 5 = {}".format(add(3,5)))
print("2 + 7 = {}".format(add(2,7)))
print("Function calls so far {}".format(function_calls))
另一个种方式
from functools import partial
def _pseudo_decor(fun, argument):
def ret_fun(*args, **kwargs):
#do stuff here, for eg.
print "decorator arg is %s" % str(argument)
return fun(*args, **kwargs)
return ret_fun
real_decorator = partial(_pseudo_decor, argument=arg)
@real_decorator
def foo(*args, **kwargs):
pass
# 通过参数传参数,也可以通过修改 function 的参数字典
def decorate(function):
def wrap_function(*args, **kwargs):
kwargs['str'] = 'Hello!'
return function(*args, **kwargs)
return wrap_function
@decorate
def print_message(*args, **kwargs):
print(kwargs['str'])
# 通过修改function的参数列表
def decorate(function):
def wrap_function(*args, **kwargs):
str = 'Hello!'
return function(str, *args, **kwargs)
return wrap_function
@decorate
def print_message(str, *args, **kwargs):
print(str)
# 给类添加
def decorate(function):
def wrap_function(*args, **kwargs):
str = 'Hello!'
args.insert(1, str)
return function(*args, **kwargs)
return wrap_function
class Printer:
@decorate
def print_message(self, str, *args, **kwargs):
print(str)
exec 和 evel比较
In [9]: %timeit t=eval('TTest'); t()
100000 loops, best of 3: 4.94 µs per loop
In [10]: %timeit exec("TTest()")
100000 loops, best of 3: 6.19 µs per loop
exec动态执行和编译成bytecode执行对比
liuzhizhi@lzz-rmbp|hexo_blog # python -mtimeit -s 'code = "a = 2; b = 3; c = a * b"' 'exec code'
100000 loops, best of 3: 13 usec per loop
liuzhizhi@lzz-rmbp|hexo_blog # python -mtimeit -s 'code = compile("a = 2; b = 3; c = a * b","<string>", "exec")' 'exec code'
1000000 loops, best of 3: 0.562 usec per loop
阅读: http://lucumr.pocoo.org/2011/2/1/exec-in-python/
需要记住的一点就是从 源码转化成为bytecode是一个非常消耗资源的过程,程序执行中总是去做这种转化,效率就会很低了。全局变量是存储在字典中,本地变量也有一个字典,但是还有个fast locals来存储资源(数组类型),优先使用它,所以更快。
Why is getattr() so much slower than self.dict.get()? 或者这个 http://stackoverflow.com/questions/14084897/getattr-versus-dict-lookup-which-is-faster
这种一般用在动态调用类的方法,可配置调用里面,也是经常用的模式。
慢的原因: getattr() 是python的一个标准接口,它需要兼容的东西非常多,做了很多工作性能当人会差一些。 而 dict 则要简单直接的多,所以速度也快一些.
getattr(Obj, 'xxx') 的作用等于 ‘Obj.xxx’, 会慢一些。
>>> import timeit
>>> class Foo(object):
... pass
...
>>> f = Foo()
>>> f.bar = "lzz"
>>> timeit.timeit("getattr(f, 'bar')", 'from __main__ import f')
0.13153386116027832
>>> timeit.timeit("f.__dict__['bar']", 'from __main__ import f')
0.10464715957641602
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.