Skip to content

Instantly share code, notes, and snippets.

View zenofile's full-sized avatar

zenofile zenofile

View GitHub Profile
@zenofile
zenofile / bench.rs
Last active June 22, 2020 09:10
Crude zerofill benchmark
use std::io::Write;
use std::fs::OpenOptions;
use std::time::Instant;
fn allocate_chunk(src: &[u8], size: usize) -> Result<(), std::io::Error> {
let mut file = OpenOptions::new()
.read(false)
.write(true)
.create(true)
.open("/tmp/testfile")?;
#!/bin/bash
###
### my-script — does one thing well
###
### Usage:
### my-script <input> <output>
###
### Options:
### <input> Input file to read.
### <output> Output file to write. Use '-' for stdout.
@zenofile
zenofile / make_current_arm64_rpi_kernel_debs.sh
Last active February 3, 2021 14:40 — forked from satmandu/make_current_arm64_rpi_kernel_debs.sh
Make arm64 deb packages for the offical Raspberry Pi Foundation arm64 kernels + NOW INSTALLS headers package too.
#!/bin/bash -x
# make_arm64_rpi_kernel_debs.sh
# Builds arm64 debian packages from the CURRENT rpi firmware repository kernel which is installed by:
# sudo rpi-update
# This runs on an arm64 host with arm64 compilation tools...
# or with some sort of cross-compilation setup.
# Debs are put in $workdir/build
#
# This will NOT work in Raspbian unless you have an arm64 compilation
# environment setup. Appears to work on
@zenofile
zenofile / firebog.sh
Created September 27, 2020 15:11
Populates a pi-hole group with adlists from firebog
#!/bin/bash
# This idempotent script populates a pi-hole group with adlists
# from firebog (https://v.firebog.net/hosts/lists.php)
#
# By default, 'nocross' is used, unless specified otherwise by the
# first argument (tick, nocross, all).
# The group is created and enabled automatically and each script
# invocation will update this group.
@zenofile
zenofile / mix_playlist.js
Created September 30, 2020 00:47
Extract video URLs from YouTube's dynamic mix playlists
var parse = (list) => {
const vp = /(?:youtube\.com.*(?:\?|&)(?:v)=|youtube\.com.*embed\/|youtube\.com.*v\/|youtu\.be\/)((?!videoseries)[a-zA-Z0-9_-]*)/;
const dl = Array.from(document.querySelectorAll(`a[href*="list=${list}"]`), e => e.href.match(vp)[1]);
return dl.filter((v, i, a) => a.indexOf(v) === i).map(e => `https://youtube.com/watch?v=${e}`);
};
var dl = (() => {
let a = document.createElement("a");
document.body.appendChild(a);
a.style = "display: none";
@zenofile
zenofile / mono_gain_compress_audio.js
Created September 30, 2020 00:53
Improve videos with bad audio (too quiet or loud, one channel stereo, ..)
(function() {
let ctx = new AudioContext();
let gain = ctx.createGain();
let cmpr = ctx.createDynamicsCompressor();
let src = ctx.createMediaElementSource(document.getElementsByTagName("video")[0]);
ctx.destination.channelCount = 1;
let ts = ctx.currentTime;
gain.gain.setValueAtTime(6, ts);
@zenofile
zenofile / github2Gitea.js
Created October 9, 2020 16:59 — forked from lrecknagel/github2Gitea.js
a small nodejs module to migrate a list of github repos (FROM A ORGANIZATION) to gitea
const fetch = require('node-fetch'),
FormData = require('form-data');
// your gitea domain without trailing slash
const GITEA_DOMAIN = 'https://subdomain.domain.xyz';
// you can find this variables when you visit your gitea installation
// open dev-tools and look in the Cookies section
const i_like_gitea = 'YOUR_I_LIKE_GITEA_STRING';
const gitea_awesome = 'YOUR_GITEA_AWESOME_STRING';
@zenofile
zenofile / opustrackno.sh
Created October 14, 2020 19:44
Write opus track metadata extracted from filename
#!/usr/bin/env bash
trim() {
local var="$*"
# remove leading whitespace characters
var="${var#"${var%%[![:space:]]*}"}"
# remove trailing whitespace characters
var="${var%"${var##*[![:space:]]}"}"
printf '%s' "$var"
}

Foreward

This document was originally written several years ago. At the time I was working as an execution core verification engineer at Arm. The following points are coloured heavily by working in and around the execution cores of various processors. Apply a pinch of salt; points contain varying degrees of opinion.

It is still my opinion that RISC-V could be much better designed; though I will also say that if I was building a 32 or 64-bit CPU today I'd likely implement the architecture to benefit from the existing tooling.

Mostly based upon the RISC-V ISA spec v2.0. Some updates have been made for v2.2

Original Foreword: Some Opinion

The RISC-V ISA has pursued minimalism to a fault. There is a large emphasis on minimizing instruction count, normalizing encoding, etc. This pursuit of minimalism has resulted in false orthogonalities (such as reusing the same instruction for branches, calls and returns) and a requirement for superfluous instructions which impacts code density both in terms of size and

@zenofile
zenofile / wg-netns
Last active May 3, 2024 16:55
wg-quick like script with namespace support
#!/usr/bin/bash
# configuration matches the wg-quick specifications
# manual invocation:
# $ sudo wg-netns vpn-1
# via systemd:
# $ sudo systemctl start [email protected]
# examples: