Hugo Theme 背景图形鼠标跟随效果
就是现在网页的背景效果,是从网上抄的
需要把文件放到个js里面,然后在foolter里面引用。
代码如下, 本质是个IIFE
!function () {
function n(n, e, t) {
return n.getAttribute(e) || t
}
function e(n) {
return document.getElementsByTagName(n)
}
function t() {
var t = e("script"), o = t.length, i = t[o - 1];
return {
l: o, z: n(i, "zIndex", -1), o: n(i, "opacity", .5), c: n(i, "color", "0,0,0"), n: n(i, "count", 99)
}
}
function o() {
a = m.width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth,
c = m.height = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight
}
function i() {
r.clearRect(0, 0, a, c);
var n, e, t, o, m, l;
s.forEach(function (i, x) {
for (i.x += i.xa, i.y += i.ya, i.xa *= i.x > a || i.x < 0 ? -1 : 1, i.ya *= i.y > c || i.y < 0 ? -1 : 1, r.fillRect(i.x - .5, i.y - .5, 1, 1), e = x + 1; e < u.length; e++)n = u[e],
null !== n.x && null !== n.y && (o = i.x - n.x, m = i.y - n.y,
l = o * o + m * m, l < n.max && (n === y && l >= n.max / 2 && (i.x -= .03 * o, i.y -= .03 * m),
t = (n.max - l) / n.max, r.beginPath(), r.lineWidth = t / 2, r.strokeStyle = "rgba(" + d.c + "," + (t + .2) + ")", r.moveTo(i.x, i.y), r.lineTo(n.x, n.y), r.stroke()))
}),
x(i)
}
var a, c, u, m = document.createElement("canvas"),
d = t(), l = "c_n" + d.l, r = m.getContext("2d"),
x = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame ||
function (n) {
window.setTimeout(n, 1e3 / 45)
},
w = Math.random, y = {x: null, y: null, max: 2e4}; m.id = l, m.style.cssText = "position:fixed;top:0;left:0;z-index:" + d.z + ";opacity:" + d.o, e("body")[0].appendChild(m), o(), window.οnresize = o,
window.onmousemove = function (n) {
n = n || window.event, y.x = n.clientX, y.y = n.clientY
},
window.onmouseout = function () {
y.x = null, y.y = null
};
for (var s = [], f = 0; d.n > f; f++) {
var h = w() * a, g = w() * c, v = 2 * w() - 1, p = 2 * w() - 1; s.push({x: h, y: g, xa: v, ya: p, max: 6e3})
}
u = s.concat([y]),
setTimeout(function () {i()}, 100)
}();
……
16 Pandas Demo part 1
the code in jupyter notebook
refer to file pandas_demo.ipynb
……15 Numpy Demo
the code in jupyter notebook
the file numpy_demo.ipynb
……14 Anaconda
How to install new package
conda install xxx
list env
conda env list
activate one env
conda activate xx
deactivate env
conda deactivate
……
13 Python Context Manager
python context manager
use contextlib/yield
@contextmanager
def send_mail_context():
'''context manager
with send_mail_context()
'''
try:
# 1 doing work BEFORE the code goes into with block
print('before yield')
server = smtplib.SMTP(SMTP_SERVERS[0], 25)
# 2 yield back to with/caller
yield server
except Exception as e:
print(e)
finally:
# 4. doing cleanup work
server.quit()
print('in finally')
use class __enter__, __exit__
# 2 implement contextmanager with class
class SMTPCT(object):
'''
1. override __enter__ __exit__
2. in __enter__, return value
'''
def __init__(self):
self.smtp_server = None
def __enter__(self):
# 1 doing work BEFORE the code goes into with block
print('in enter')
self.smtp_server = smtplib.SMTP(SMTP_SERVERS[0], 25)
# 2 return back to with/caller
return self.smtp_server
def __exit__(self, type, value, traceback):
# 4. doing cleanup work
print('in exit')
self.smtp_server.quit()
……
12 Python Smtp
how to send mail in python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# smtplib -> https://docs.python.org/3/library/smtplib.html
import smtplib
# contextlib -> https://docs.python.org/3/library/contextlib.html
from contextlib import contextmanager
# email -> https://docs.python.org/3/library/email.examples.html#email-examples
from email import encoders
from email.header import Header
from email.mime.text import MIMEText
from email.utils import parseaddr, formataddr
SMTP_SERVERS = ['your smtp servers']
def _format_addr(s):
''' format the address
'''
name, addr = parseaddr(s)
return formataddr((Header(name, 'utf-8').encode(), addr))
def generate_mail(from_addr,
to_addr,
cc_addr,
subject,
body,
mime_type='plain'):
'''plain/text text/html
'''
msg = MIMEText(body, mime_type, 'utf-8')
msg['From'] = _format_addr(from_addr)
msg['To'] = ",".join([_format_addr(x) for x in to_addr])
msg['Cc'] = ",".join([_format_addr(x) for x in cc_addr])
msg['Subject'] = Header(subject, 'utf-8').encode()
return msg
def send_mail(from_addr, to_addr, cc_addr, subject, body, mime_type='plain'):
server = smtplib.SMTP(SMTP_SERVERS[0], 25)
server.set_debuglevel(1)
msg = generate_mail(from_addr, to_addr, cc_addr, subject, body, mime_type)
server.sendmail(from_addr, to_addr + cc_addr, msg.as_string())
server.quit()
# 1. to implement context manager, use decorator @contextmanager
# and yield
@contextmanager
def send_mail_context():
'''context manager
with send_mail_context()
'''
try:
# 1 doing work BEFORE the code goes into with block
print('before yield')
server = smtplib.SMTP(SMTP_SERVERS[0], 25)
# 2 yield back to with/caller
yield server
except Exception as e:
print(e)
finally:
# 4. doing cleanup work
server.quit()
print('in finally')
# 2 implement contextmanager with class
class SMTPCT(object):
'''
1. override __enter__ __exit__
2. in __enter__, return value
'''
def __init__(self):
self.smtp_server = None
def __enter__(self):
# 1 doing work BEFORE the code goes into with block
print('in enter')
self.smtp_server = smtplib.SMTP(SMTP_SERVERS[0], 25)
# 2 return back to with/caller
return self.smtp_server
def __exit__(self, type, value, traceback):
# 4. doing cleanup work
print('in exit')
self.smtp_server.quit()
def send_mail_in_context_class(from_addr,
to_addr,
cc_addr,
subject,
body,
mime_type='plain'):
msg = generate_mail(from_addr, to_addr, cc_addr, subject, body, mime_type)
with SMTPCT() as server:
# 3. do the actual job
server.sendmail(from_addr, to_addr + cc_addr, msg.as_string())
print('in with block')
print('sent')
def send_mail_in_context_yield(from_addr,
to_addr,
cc_addr,
subject,
body,
mime_type='plain'):
msg = generate_mail(from_addr, to_addr, cc_addr, subject, body, mime_type)
with send_mail_context() as server:
# 3. do the actual job
server.sendmail(from_addr, to_addr + cc_addr, msg.as_string())
print('in with block')
print('sent')
if __name__ == '__main__':
pass
# 1. send mail with contextmanager implemented in class
# send_mail_in_context_class('your_from_address',
# ['to_address'], [],
# 'test', 'this is test mail')
# 2. send mail with contextmanager implemented with yield
# send_mail_in_context_yield('your_from_address',
# ['to_addr'], [],
# 'test', 'this is test mail')
……
11 Python Mro
method resolution order
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# method resolution order
# mro
class A(object):
def hello(self):
print('class A says hello')
class B(A):
pass
class C(A):
# class variable
BP_URL = 'https://xxxxx'
def __init__(self):
self.name = 'ok'
@staticmethod
def print_hello(name, age):
''' staticmethod
cannot access any class or self variabel/method
'''
pass
@classmethod
def say(cls):
'''class method
can access class level variable/method
'''
print(cls.BP_URL)
def hello(self):
print('class C says hello')
class D(C, B):
pass
if __name__ == '__main__':
d = D()
d.hello()
# to print the mro of one class
print(d.__class__.__mro__)
……
10 Dunder Methods
dunder methods
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# double underscore variable/function
# dunder
class A(object):
def __init__(self, number):
self.number = number
def __eq__(self, value):
'''
a == b
'''
return super().__eq__(value)
def __ge__(self, value):
'''
a >= b
'''
return super().__ge__(value)
def __gt__(self, value):
'''
a > b
'''
return super().__gt__(value)
def __le__(self, value):
'''
a < b
'''
return super().__le__(value)
def __ne__(self, value):
''' a != b
'''
return super().__ne__(value)
def __str__(self):
'''print(a)
'''
return super().__str__()
def __repr__(self):
return super().__repr__()
def __len__(self):
'''
len(a)
'''
return self.number * 10
def __lt__(self, other):
'''less than
a < b
'''
return self.number < other.number
def __getattribute__(self, name):
'''
print(a[the_key])
'''
return super().__getattribute__(name)
def __setattr__(self, name, value):
'''
a[the_key] = 5
'''
return super().__setattr__(name, value)
def __delattr__(self, name):
'''
delete a['the_key']
'''
return super().__delattr__(name)
if __name__ == '__main__':
'''
'''
# a = A(5)
# b = A(6)
# print(a < b)
# print(len(a))
# a['b'] = 10
# c = a['c']
pass
……
Darknet Too Many or Too Few Labels
Too many or too few labels
如果在使用darknet过程中,遇到这个错误,很可能你的labels文件里面的label定义的有问题
- label之间要不包含
- label 名字不要出现在train/test的路径中
所以如果定义一个label是a, 很可能就不行,train里面包含a,所以还是定义的稍微长点。
……