This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Refer to https://stackoverflow.com/questions/48343669/how-to-install-python-packages-over-ssh-port-forwarding. | |
# Login to server via following ssh command. Your computer must have permission to connect to PIP server directly. | |
ssh -R 9999 username@server.host.name | |
# After login to your server.host.name. Use following command to install proxy package. | |
pip install package_name --proxy socks5h:127.0.0.1:9999 | |
# The apt and yum can work with this tunnel by setting proxy. | |
# Add following line in /etc/yum.conf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
def linear_regression(x, y): | |
"""The input are x and y for 2D""" | |
assert isinstance(x, np.ndarray) | |
assert isinstance(y, np.ndarray) | |
w = np.sum((y - np.average(y)) * x) / np.sum((x - np.average(x))**2) | |
b = np.average(y) - w * np.average(x) | |
return w, b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def parse_verilog_number(s): | |
"""Parse a verilog number literal to the tuple (sign, bits, base, value). | |
sign: 1 for postive, -1 for negative. | |
bits: The bits token in the number literal. | |
base: The base of number(2, 10 or 16). | |
value: The value token. | |
""" | |
base_token = {'b': 2, 'd': 10, 'h': 16} | |
pattern = re.compile(r"""(?P<sign>[\-\+])?(?P<define>\`)?(?P<bits>[\w]+)?\'((?P<base2>[bB])(?P<value2>[01]+)|(?P<base10>[dD])(?P<value10>\d+)|(?P<base16>[hH])(?P<value16>[0-9a-fA-F]+)|(?P<value>\d+))""") | |
m = pattern.match(s) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# -delete flag will delete unmatched files and folder on target. | |
#DELETE_FLAG=-delete | |
DELETE_FLAG= | |
# The rsync flags | |
# -a, --archive | |
# This is equivalent to -rlptgoD. It is a quick way of saying you want recursion and want to preserve almost | |
# everything (with -H being a notable omission). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections.abc import Sequence | |
def flatten(x): | |
"""Flatten given parameter recursively.""" | |
if isinstance(x, Sequence): | |
for v in x: | |
yield from flatten(v) | |
else: | |
yield x | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!python | |
# coding: utf-8 | |
import sys | |
import zlib | |
import base64 | |
import xml.etree.ElementTree as ET | |
from urllib.parse import unquote | |
def decode_drawio(filename): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!python | |
# Provide a serial of postfix unit symbol. | |
class UnitScaleOp: | |
def __init__(self, scale, desc=None): | |
self.scale = scale | |
self.desc = desc | |
def __rmatmul__(self, value): | |
return value * self.scale |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!python | |
# coding: utf-8 | |
'''Parse drawio file and generate command lines for export figures with drawio app.''' | |
import click | |
import re | |
import platform | |
from cmdlet.cmds import * | |
DRAWIO_BIN = { | |
'Windows': r'draw.io.exe', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!python | |
# coding: utf-8 | |
import sys | |
import os | |
from mako.template import Template | |
yml_content = r'''site_name: "${site_name}" | |
nav: | |
- ${index_page_name}: ${index_filename}.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!python | |
# coding: utf-8 | |
import numpy as np | |
def generate_clock(freq, time=10.0, phase=0.0, amplitude=1.0, duty=.5, resolution=10): | |
"""Generate clock. | |
Parameters | |
---------- |
NewerOlder