Skip to content

Instantly share code, notes, and snippets.

@vi
vi / hextobin.c
Created August 25, 2017 15:10
Hex string to byte buffer in C
// Based on https://stackoverflow.com/a/23898449/266720
void tallymarker_hextobin(const char * str, uint8_t * bytes, size_t blen)
{
uint8_t pos;
uint8_t idx0;
uint8_t idx1;
// mapping of ASCII characters to hex values
const uint8_t hashmap[] =
{
@vi
vi / _example.c
Last active October 27, 2017 04:50
Simple Robin Hood hash table implemented using C macros. See also: https://github.com/vi/macro_robinhood_hash
#include <stdio.h>
#include <stddef.h>
#include <assert.h>
#include "robinhoodhash.h"
struct entry {
int key;
char value;
};
@vi
vi / zlibdict.c
Last active May 4, 2017 01:44
Compress short files with a pre-defined zlib dictionary from command line
#include <stdio.h>
#include <string.h>
#include <zlib.h>
#include <inttypes.h>
#include <assert.h>
uint8_t dict[4096];
size_t dict_size;
@vi
vi / mkv.csv
Last active February 1, 2017 21:03
Matroska element types from official spec page
We can make this file beautiful and searchable if this error is corrected: It looks like row 10 should actually have 14 columns, instead of 11. in line 9.
AlphaMode,4,[53][C0],-,-,-,0,u,,,*,*,*,Alpha Video Mode. Presence of this Element indicates that the BlockAdditional Element could contain Alpha data.
AspectRatioType,4,[54][B3],-,-,-,0,u,*,*,*,*,*,"Specify the possible modifications to the aspect ratio (0: free resizing, 1: keep aspect ratio, 2: fixed)."
AttachedFile,2,[61][A7],mand.,mult.,-,-,m,*,*,*,*,,An attached file.
AttachmentLink,3,[74][46],-,-,not 0,-,u,*,*,*,*,,The UID of an attachment that is used by this codec.
Attachments,1,[19][41][A4][69],-,-,-,-,m,*,*,*,*,,Contain attached files.
Audio,3,[E1],-,-,-,-,m,*,*,*,*,*,Audio settings.
BitDepth,4,[62][64],-,-,not 0,-,u,*,*,*,*,*,"Bits per sample, mostly used for PCM."
BitsPerChannel,5,[55][B2],-,-,-,0,u,,,,*,,Number of decoded bits per channel. A value of 0 indicates that the BitsPerChannel is unspecified.
Block,3,[A1],mand.,-,-,-,b,*,*,*,*,*,Block containing the actual data to be rendered and a timestamp relative to the Cluster Timecode. (see Block Structure)
BlockAddID,5,[EE],mand.,-,not 0,1,u,*,*,*
// Source: http://unix.stackexchange.com/a/251769/17594
// Modifications: long long, exit codes, diagnostics
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <sys/ptrace.h>
#include <sys/socket.h>
#include <arpa/inet.h>
@vi
vi / formatunicode.pl
Last active February 21, 2024 16:55
Simple converter from markdown-style _annotations_ to Unicode combining characters.
#!/usr/bin/perl -C63
# Converts
# The -quick- _brown_ =fox= ^jumps^ +over+ ~the~ @lazy@ dog.
# into
# The q̶u̶i̶c̶k̶ b̲r̲o̲w̲n̲ f̳o̳x̳ j̅u̅m̅p̅s̅ o̱v̱e̱ṟ t̴h̴e̴ l̿a̿z̿y̿ dog.
#
# Implemented by Vitaly "_Vi" Shukela in 2016. Public domain / CC-0.
use strict;
@vi
vi / 000.txt
Last active May 24, 2016 22:01
Testing of bup hashsplit
Aggregated data and plots: https://docs.google.com/spreadsheets/d/1lZ0D9ximUQuBydBsv-ASZ7L4NLMqipeg1o34z3LGbxY/edit#gid=0
System:
Linux vi-notebook 4.4.8-grsec-64+ #78 SMP PREEMPT Fri May 6 01:12:25 FET 2016 x86_64 GNU/Linux
Userland is 32-bit Linux Debian jessie/wheezy (bup is running in 32-bit mode)
Python 2.7.9
12 Gigabytes of RAM installed
There is considerable background activity.
@vi
vi / scgi_uploader.rs
Created April 26, 2016 18:09
Simple SCGI service that saves all POSTed or PUT bodies.
// cargo-deps: time="0.1.34" scgi="0.3.3"
extern crate scgi;
extern crate time;
use std::io::Write;
use std::net::TcpListener;
use std::thread::spawn;
use std::io::Read;
use std::fs::File;
@vi
vi / envtemplater
Last active April 22, 2016 07:14
Simplify setting multiple environment variables using templates
#!/bin/bash
ENVTEMPLATER_SEPARATOR='%'
if [[ -z "$1" || $1 = "--help" ]]; then
echo >&2 "Usage: T_template1=substitution1 ... T_templateN=substitutionN envtemplater arg%...%template ... arg%...%template -- command [arguments]"
echo >&2 "Example: T_github=ALTURL_%0%=https://github.com/vi/%0% envtemplater dive%github fdlinecombine%github -- submodule_update_alturl.sh --force"
exit 1
fi
@vi
vi / submodule_update_alturl.sh
Last active April 22, 2016 06:19
"git submodule update --init --recursive" with second change for submodules referencing unpushed code (alternative URIs for submodules)
#!/bin/sh
unset CDPATH
cd_to_toplevel () {
cdup=$(git rev-parse --show-toplevel) &&
cd "$cdup" || {
echo >&2 "Cannot chdir to $cdup, the toplevel of the working tree"
exit 1