Skip to content

Instantly share code, notes, and snippets.

@eecsmap
eecsmap / mio.py
Last active April 24, 2021 08:41
import os
import mmap
import contextlib
def gen(filename, length=0, offset=0):
create = not os.path.isfile(filename)
mode = 'w+b' if create else 'r+b'
with open(filename, mode) as fileobj:
if create and length == 0: length = 1
if length:
@eecsmap
eecsmap / xv6_ubuntu21.4_debug.md
Last active May 6, 2021 19:48
Setup xv6 on Ubuntu 21.4

Setup xv6 on Ubuntu 21.4

  1. setup a ubuntu 21.4 desktop box in VMware/VirtualBox with minimum setup chosen.
  2. follow instructions here https://pdos.csail.mit.edu/6.828/2020/tools.html You do not need to apply the hack of qemu on ubuntu 21.4
engineer@vm-ubuntu:~$ sudo apt-get install git build-essential gdb-multiarch qemu-system-misc gcc-riscv64-linux-gnu binutils-riscv64-linux-gnu
engineer@vm-ubuntu:~$ riscv64-linux-gnu-gcc --version

Install xv6

@eecsmap
eecsmap / memoization.py
Created February 1, 2022 01:03
memoization in fib examples
# visualize the function runtime
# using https://pythontutor.com/composingprograms.html#mode=edit
def fib0(n):
if n < 2: return n
return fib0(n - 1) + fib0(n - 2)
fib0(3)
def fib1(n, m={}):
@eecsmap
eecsmap / fib.py
Last active May 5, 2022 19:07
cs61a
class VirFib():
"""A Virahanka Fibonacci number.
>>> start = VirFib()
>>> start
VirFib object, value 0
>>> start.next()
VirFib object, value 1
>>> start.next().next()
VirFib object, value 1
@eecsmap
eecsmap / sendRawEth.c
Created July 7, 2022 21:27 — forked from austinmarton/sendRawEth.c
Send a raw Ethernet frame in Linux
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*/
#include <arpa/inet.h>
#include <linux/if_packet.h>
#include <stdio.h>
#include "quick_sort.h"
#include "utils.h"
#include <fstream>
typedef std::pair<uintV, uintV> intPair;
template <class E> struct ascendingF {
E operator()(const E &a, const E &b) const { return a > b; }
};
module debouncer #(
parameter WIDTH = 1,
parameter SAMPLE_CNT_MAX = 62500,
parameter PULSE_CNT_MAX = 200,
parameter WRAPPING_CNT_WIDTH = $clog2(SAMPLE_CNT_MAX),
parameter SAT_CNT_WIDTH = $clog2(PULSE_CNT_MAX) + 1
) (
input clk,
input [WIDTH-1:0] glitchy_signal,
#include <Windows.h>
#include <WinCrypt.h>
#include <iostream>
#pragma comment (lib, "Crypt32.lib")
bool InstallCertificate(const char* certificateFile, const char* certificateStore)
{
bool success = false;
@eecsmap
eecsmap / template_verilog_test.v
Last active May 15, 2023 22:11
tempate of verilog test
// 设定单位时间和解析精度
`timescale 1ns/1ns
// 后续的#1表明经过1个时间单位
// iverilog -g2012 -o demo.vvp demo.v
// vvp demo.vvp -fst
// gtkwave demo.fst
module test ();
@eecsmap
eecsmap / Makefile
Created May 15, 2023 22:11
template_verilog_test
%.fst: %.vvp
vvp $< -fst
%.vvp: %.v
iverilog -g2012 -o $@ $<
clean:
rm -f *.vvp *.fst