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() {……

Continue reading

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 ……

Continue reading

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() ……

Continue reading

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.……

Continue reading

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__) ……

Continue reading