Skip to content

Instantly share code, notes, and snippets.

@stengoes
stengoes / tpm2.0-fulldisk-decryption-at-boot.md
Last active January 21, 2020 13:28
Setup TPM2.0 for full disk decryption at boot

First step: install tpm2-tss, tpm2-tools and all its depedencies.

# Install dependencies
sudo apt-get update && sudo apt-get -y install autoconf autoconf-archive automake libtool pkg-config gcc libssl-dev libcurl4-gnutls-dev doxygen

# Install tpm2-tss
git clone https://github.com/tpm2-software/tpm2-tss.git
cd tpm2-tss
git checkout e05d28ec  # I used this particular commit
./bootstrap
@stengoes
stengoes / gist:d307e1a1969894a5e4a32effcebac6f3
Last active January 10, 2020 15:08
Benchmarking write performance harddisk

Linux command for benchmarking write performance hdd

Single file write performance

# dd if=/dev/zero of=/nvme/test.bla bs=4096k count=1000
1000+0 records in
1000+0 records out
4194304000 bytes (4.2 GB, 3.9 GiB) copied, 2.15929 s, 1.9 GB/s
@stengoes
stengoes / resizeBicubic.js
Created February 7, 2020 14:11
Bicubic resize function on float array
// Conversion functions
function convert1Dto2D(image)
{
const tmp = []
let offset = 0;
for(let y = 0; y < image.height; y++)
{
tmp.push([]);
for(let x = 0; x < image.width; x++)
{
@stengoes
stengoes / index.html
Created February 13, 2020 08:37
Example using html5 canvas tags to display rgb arrays.
<html>
<body>
<canvas id="mycanvas" width="2048" height="512"></canvas>
</body>
</html>
<script>
const height = 512;
@stengoes
stengoes / demosaic.js
Last active February 17, 2020 14:04
Demosaic images with Uint8ClampedArray
function demosaic(raw) {
// Demosaics a Color Filter Array (CFA) into a RGBA color array.
// For implementation details see: http://research.microsoft.com/pubs/102068/demosaicing_icassp04.pdf
// Validate inputs
const raw_size = raw.height * raw.width * raw.depth;
if (raw.data.length != raw_size) {
console.log("Error: raw image dimensions do not match raw buffer size!");
return null;
}
@stengoes
stengoes / resize.js
Created March 2, 2020 09:22
resizeBicubic
function resizeBicubic(image, newHeight, newWidth) {
/* Helper functions */
function extrapolateImageBoundaries(image) {
const height = image.length;
const width = image[0].length;
// Linearly extrapolate top and bottom of the image
image[-2] = [];
@stengoes
stengoes / balance.js
Last active June 9, 2020 10:40
Balance recordings
function distribute_recordings_over_lines(num_recordings, distribution, lines) {
// This function distributes number of recordings optimally
// given the current distribution and the lines on which you want to record.
function find_level(n, distribution, lines, low, high) {
// Compute the level
const level = (low + high) / 2;
// Compute search statistic
let s = 0;
@stengoes
stengoes / example_dynamic_library_in_c++.md
Last active July 4, 2020 17:51
A minimal example for creating, compiling and using a dynamic library in C++.

A minimal example for creating, compiling and using a dynamic library in C++.

1. Create a test library

// test.h
#pragma once 
int add(int a, int b);
int mult(int a, int b);
@stengoes
stengoes / example_static_library_in_c++.md
Last active July 4, 2020 17:51
A minimal example for creating, compiling and using a static library in C++.

A minimal example for creating, compiling and using a static library in C++.

1. Create a test library

// test.h
#pragma once 
int add(int a, int b);
int mult(int a, int b);
@stengoes
stengoes / zeropad.js
Last active August 31, 2020 13:32
Pads an image with a specified amount of zeros on the top, left, bottom and right.
function zeropad(image, top, bottom, left, right) {
// Pads an image with a specified amount of zeros on the top, left, bottom and right.
// Validate inputs
const image_size = image.height * image.width * image.depth;
if (image.data.length != image_size) {
console.log("Error: image dimensions do not match rgba buffer size!");
return null;
}
if (image.data.constructor !== Uint8ClampedArray && image.data.constructor !== Float32Array) {