Skip to content

Instantly share code, notes, and snippets.

@brabect1
brabect1 / latex_install_local_pkgs_from_ctan.bash
Created November 18, 2015 13:40
This script tries to automate installation of packagaes directly from CTAN. This may come handy when the latex distro lacks package manager and users have non-root privileges.
PKGS="tabu caption adjustbox collectbox"; \
for p in ${PKGS}; do \
(url=http://mirrors.ctan.org/install/macros/latex/contrib/$p.tds.zip && \
if [[ ! `wget -S --spider ${url} 2>&1 | grep 'HTTP/1.1 200 OK'` ]]; then \
url=http://mirrors.ctan.org/macros/latex/contrib/$p.zip && \
wget ${url} && \
unzip ${url##*/} && \
if [ "$(expr $p/*.sty)" = "$p/*.sty" ]; then \
cd $p && latex $p.ins && cd ..; \
fi && \
@brabect1
brabect1 / description.md
Last active November 21, 2015 17:17
Jekyll experiments Ubuntu 14.04

Installation

This is for ruby version 1.9.3. See that we need to install 2.x version of Jekyll.

apt-get install ruby ruby-dev rubygems-integration
gem install jekyll -v '2.5.0'
apt-get install nodejs
@brabect1
brabect1 / _description.md
Last active November 22, 2015 19:31
Experiments with GHDL (Ubuntu 14.04)
@brabect1
brabect1 / bash_remove_duplicate_slash_in_path.md
Last active August 18, 2022 22:44
Removes duplicate slashes in a path using BASH. Also shows how to recover shopt.
@brabect1
brabect1 / bash_subshell_in_backgrounnd.md
Last active January 14, 2016 12:31
Shows how to run BASH subshell in background (i.e. as a separate process)

To run a command in background in BASH, one simply adds & after the command: command &. The PID of the spawned backgorund proces is the return code, $!. This is fine within a script, but what if you want to run the commands as one liner?

For example

sleep 1
echo slept
sleep 1 &
echo "sleeping (sub process PID=${!})"
@brabect1
brabect1 / getting_verilog_includes.md
Last active January 11, 2016 20:25
Shows how to list include files needed by Verilog/SystemVerilog source files.

Verilog/SystemVerilog are similar to C/C++ by using the ```include`` directive, but not exactly the same by strictly separating header (.h) and code (`.c`, `.cpp`) files. The end result is, though, the same: If one wants to create a `make` target to compile a code file, she will need to know the dependencies on any included files.

In C/C++, where one can use the compiler/preprocessor to get such dependencies. Unfortunately none (to my knowledge) of the major EDA vendors do not equip their compilers with similar functionality. Accidentally I stumbled upon the [Verilog-perl] module (also on [CPAN][Verilog-perl-cpan]) that, among other things, provides a full Verilog/SystemVerilog preprocessor. With its help and little bit of coding, one gets a tool to automatically discover include depenedencies.

@brabect1
brabect1 / sv_coverpoint_with_variable_bins.md
Created February 26, 2016 06:47
Shows how create a reusable covergroup with a coverpoint of configurable bins.

Problem: When generating random stimulus, one needs to check that all sought cases have been witnessed. Often, the cases are a subset of a limited set (e.g. a list of register addresses). Creating covergroup for each subset is at most boring copy&paste exercise and creates maintenance nightmare.

IEEE 1800-2012 allows coverpoint bins being specified using set covergroup expressions (Sec. 19.5.1.2). This lets one to define bins from an array. To make it configurable, the array needs to be passed to the coverpoint; covergroup's constructor is the ideal way.

@brabect1
brabect1 / working_with_pysec.md
Last active October 26, 2018 13:45
Describes how to get started with `pysec` (https://github.com/lukerosiak/pysec)

Legacy pysec

What I see as the biggest problem of pysec is that is not really a completed project. Its XBRL API is probably fine, but the rest related to the Django app is not more than a proof of concept. The following gives instruction on how to use the legacy pysec.

Install django. The following would install the packaged version, which may be somewhat obsolette:

apt-get install python-django

@brabect1
brabect1 / sv_queue_randomization.md
Created October 11, 2016 10:40
Shows how to randomize a queue or a dynamic array with unique elements.

The following code shows how to randomize a queue. The use of unique is obvious, but the trick is in using size as a constraint, which lets one to control how many elements will be randomized.

int q[$];
...
q.delete();
assert(
    std::randomize( q ) with {
 unique{q};
@brabect1
brabect1 / make_intermediate.md
Created October 14, 2016 07:25
GNU Make and the effects of intermediate targets.

Intermediate files in make's terminology is a file needed somewhere on way from a source file to target file. An examples is a file.c needed to create file.o from file.y (YACC source). From that principle, an intermediate file is needed only once to generate the target after the source changed and thus can be removed after it was used. Therefore, an intermediate file which did not exist before make also does not exist after make (see [gnu_rule_chains]). In other words, make removes the intermediate files it needed to create (unless .SECONDARY or .PRECIOUS is used). For details refer to [gnu_rule_chains].

That being said, the use of explicit intermediate files (i.e. .INTERMEDIATE) is rarely needed. Often one either really wants to see the itermediate files too (thus making explicit targets and dependencies and remove