Skip to content

Instantly share code, notes, and snippets.

@Wonicon
Wonicon / OH1.scala
Created March 3, 2017 12:13
[rocket-chip] Generate a bit array whose length equals to a UInt
/**
* The `UIntToOH1` method is found from rocket-chip repo at
* https://github.com/ucb-bar/rocket-chip/blob/dfa61bc48709a7733b73d24eb81acc2da227cfd4/src/main/scala/uncore/tilelink2/package.scala#L19
* As it is hard to me to figure out what the abbreviation of OH and OH1 is,
* I write this standalone demo in order to find out its semnatic from the pattern output.
*
* Finally, I find that the `UIntToOH1` method will convert a UInt value to bits of 1 whose length equals to that value.
*
* To run this demo:
* 1. git clone https://github.com/ucb-bar/chisel-template demo
@Wonicon
Wonicon / sym-tri.c
Created January 30, 2017 06:55
Basic programming questions
/**
* Question: https://www.zhihu.com/question/55234202
* Usage: <proc> <lines>
* Example: ./a.out 6
* A
* ABA
* ABCBA
* ABCDCBA
* ABCDEDCBA
* ABCDEFEDCBA
@Wonicon
Wonicon / JumpFrame.java
Created January 8, 2017 12:51
Optimized accept-reject sequence to approach target frame. (Pokemon Sun / Moon)
import java.util.ArrayList;
import java.util.Scanner;
/**
* This code generate optimized accept-reject sequence to approach target frame.
* Background: Pokemon Sun / Moon Random Number
*/
public class JumpFrame {
enum Op {Accept, Reject};
@Wonicon
Wonicon / DBTrick.java
Last active November 30, 2016 07:33
Create sql insert statement from GBK priliminary tuple description, seperated by "、", and auto add quotation marks.
/**
* Input sample:
*
* TableName
* (1,样例,example)、(2,样例,example)
* ;
* EOF
*
* Output:
* insert into TableName values (1, "样例", "example");
@Wonicon
Wonicon / algo.java
Created November 1, 2016 10:15
An optimization problem using dp
/*
* U = { x1, x2, ... , xn }
* A, B is subset of U. A and B are disjoint, and SUM(A) > SUM(B).
* Ask for the minimum SUM(A) / SUM(B)
*/
import java.util.Scanner;
public class Foo {
public static void main(String[] args) {
@Wonicon
Wonicon / course.rb
Last active August 30, 2016 14:36
select course
# Usage:
# ruby course.rb <stu-id> <password> [category] [campus] [host]
#
# Rerequsities:
# # apt-get install ruby
# $ gem install rest-client
# $ gem install nokogiri
#
# Note:
# if a file called 'wishes' exists, then we only scout the wished
@Wonicon
Wonicon / gem5_dump_stat.rb
Created July 30, 2016 12:06
gem5 dump stat
#!/usr/bin/env ruby
def StatDump(seq_num)
Dir.glob('/proc/*').each do |process|
next if not File.directory?(process)
pid = process.split('/')[2]
next if not pid =~ /\d+/
is_gem5 = false
@Wonicon
Wonicon / chk_dump_sym.rb
Created July 11, 2016 11:07
Check function name from objdump -d output
#!/usr/bin/env ruby
result = []
File.read(ARGV[0]).each_line do |line|
# Match pattern "XXXXXXXX <function-name>:"
# and extract the function name.
# Note that all the symbol including '<', '>'
# and ':' are literal, except 'function-name',
# which is the variable we want.
matchData = /(?<=\h{8} <)\w+(?=>:$)/ .match line
@Wonicon
Wonicon / config
Created June 6, 2016 19:28
doxygen config
# Doxyfile 1.8.11
# This file describes the settings to be used by the documentation system
# doxygen (www.doxygen.org) for a project.
#
# All text after a double hash (##) is considered a comment and is placed in
# front of the TAG it is preceding.
#
# All text after a single hash (#) is considered a comment and will be ignored.
# The format is:
@Wonicon
Wonicon / seg.v
Created May 4, 2016 16:51
数码管
reg [7:0] an;
always @(posedge CLK100MHZ) begin
if (reset) begin
an <= 8'b1111_1110;
end
else begin
an <= { an[6:0], an[7] };
end
end