Skip to content

Instantly share code, notes, and snippets.

View chongxi's full-sized avatar

chongxi lai chongxi

  • Astera.org
  • California
View GitHub Profile
@chongxi
chongxi / example.py
Created May 3, 2018 16:52 — forked from schlamar/example.py
mplog: Python advanced multiprocessing logging.
import logging
import multiprocessing
import time
import mplog
FORMAT = '%(asctime)s - %(processName)s - %(levelname)s - %(message)s'
logging.basicConfig(level=logging.DEBUG, format=FORMAT)
existing_logger = logging.getLogger('x')
@chongxi
chongxi / draw_neural_net.py
Created November 9, 2016 15:06 — forked from craffel/draw_neural_net.py
Draw a neural network diagram with matplotlib!
import matplotlib.pyplot as plt
def draw_neural_net(ax, left, right, bottom, top, layer_sizes):
'''
Draw a neural network cartoon using matplotilb.
:usage:
>>> fig = plt.figure(figsize=(12, 12))
>>> draw_neural_net(fig.gca(), .1, .9, .1, .9, [4, 7, 2])
from multiprocessing import Pool
from functools import partial
def _pickle_method(method):
func_name = method.im_func.__name__
obj = method.im_self
cls = method.im_class
if func_name.startswith('__') and not func_name.endswith('__'): #deal with mangled names
cls_name = cls.__name__.lstrip('_')
func_name = '_' + cls_name + func_name
@chongxi
chongxi / mmap_write.py
Created April 12, 2016 14:10
use mmap to write file
size = 83456
file = open("s:/test.bin", "w+b")
file.write("\0" * size)
file.flush()
mm = mmap.mmap(file.fileno(), size, access=mmap.ACCESS_WRITE)
mm.write('12345')
mm.tell()
mm.seek(0)
file.flush()
@chongxi
chongxi / KC705_BPI.md
Last active February 2, 2016 04:37
Programming FPGA BPI(Byte-wide Peripheral Interface) memory
  • Make sure the switch under U58 is 00010, the last one is M0

  • Convert .bit file into .mcs file

  cd [your impl_ directory]
  write_cfgmem -format mcs -interface bpix16 -size 128 -loadbit "up 0x0 *.bit" -file *.mcs -force
  • Connect to the Hardware Target in Vivado
@chongxi
chongxi / fir_gen.vhd
Created January 30, 2016 04:57
Generic FIR filter VHDL
-- This is a generic FIR filter generator
-- It uses W1 bit data/coefficients bits
LIBRARY ieee; -- Using predefined packages
USE ieee.std_logic_1164.ALL;
USE ieee.std_logic_arith.ALL;
USE ieee.std_logic_signed.ALL;
-- --------------------------------------------------------
ENTITY fir_gen IS ------> Interface
GENERIC (W1 : INTEGER := 9; -- Input bit width
W2 : INTEGER := 18;-- Multiplier bit width 2*W1
@chongxi
chongxi / btn_func.py
Last active October 25, 2015 20:05
super deco button for any function in jupyter
from IPython.html import widgets
from IPython.display import display
####### decoration for jupyter button function ########################
def btn_func(description='deco', color='lightlime'):
def btn_deco(func):
# description='deco'
# color='#495ba3'
btn = info_btn(description = description, color=color)
btn.on_click(func)
@chongxi
chongxi / open_file.py
Last active October 24, 2015 21:00
A button to select a file in Ipython Notebook
import Tkinter,tkFileDialog
btn = widgets.Button(description="Click me!")
display(btn)
btn.button_style = 'Info'
btn.description = 'Open *.Bin'
btn.width =100
btn.height = 100
btn.border_radius = 15
@chongxi
chongxi / bokeh.py
Last active October 24, 2015 06:17
from bokeh.plotting import *
output_notebook()
p = figure(plot_width=900, plot_height=300)
p.multi_line(xs=[t[:100000]],ys=[plot_data[:100000,0]])
show(p)
@chongxi
chongxi / sort.py
Created October 22, 2015 01:22
sort first by id[0], then id[1], via key = lambda
id_list = sorted(id_list, key=lambda _id: (_id[0],_id[1:]))