Skip to content

Instantly share code, notes, and snippets.

@Jacobboogiebear
Jacobboogiebear / build-swtpm.sh
Created March 13, 2022 07:10
A quick script to build swtpm and libtpm on Ubuntu 20.04 (created for WSL2 and WSLg)
sudo apt-get install git g++ gcc automake autoconf libtool make gcc libc-dev libssl-dev pkg-config libtasn1-6-dev libjson-glib-dev expect gawk socat libseccomp-dev -y
cd ~
git clone https://github.com/stefanberger/swtpm.git
git clone https://github.com/stefanberger/libtpms.git
cd libtpms
./autogen.sh --prefix=/usr --with-tpm2 --with-openssl
make
sudo make install
cd ../swtpm
./autogen.sh --prefix=/usr
@PurpleBooth
PurpleBooth / Dockerfile
Last active March 21, 2024 09:33
Create a static binary in go and put it in a from scratch docker container
FROM golang:1.9
WORKDIR /go/src/github.com/purplebooth/example
COPY . .
RUN go build -ldflags "-linkmode external -extldflags -static" -a main.go
FROM scratch
COPY --from=0 /go/src/github.com/purplebooth/example/main /main
CMD ["/main"]
@mcastelino
mcastelino / Simple vsock setup for QEMU.md
Last active January 16, 2024 13:35
using qemu with vsock

Simple vsock setup for QEMU

Configuration

Host Kernel: rawhide 4.13.0-0.rc6.git4.2.fc28.x86_64 (on Fedora 24)

QEMU is mainline built from sources: QEMU emulator version 2.10.50 (v2.10.0-105-g223cd0e)

Guest: clear-17460-kvm.img (which has vsock support)

@mcastelino
mcastelino / qemu_vhost.md
Last active February 23, 2024 08:59
QEMU Tips and Tricks

How to launch QEMU from command line without libvirt with macvtap and vhost support

This sets up a host local bridge with a macvlan interface for VM to host communication. The macvtap is setup with vhost support.

The command line options to note are

-netdev tap,fd=3,id=hostnet0,vhost=on,vhostfd=4 3<>$"$tapdev" 4<>/dev/vhost-net -device virtio-net-pci,netdev=hostnet0,id=net0,mac=$(< /sys/class/net/testtap/address)

This sets up two different fd's. The first for macvtap and the second for vhost-net.

@Elecon-rou
Elecon-rou / if.c
Created January 26, 2017 22:32
List all network interfaces with netlink
#include <stdio.h>
#include <unistd.h>
#include <memory.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <linux/types.h>
#include <linux/netlink.h>
#include <linux/rtnetlink.h>
#define BUF_SIZE 8192
@george-hawkins
george-hawkins / arm64.md
Last active March 24, 2024 14:36
Running virtualized x86_64 and emulated arm64 Ubuntu cloud images using QEMU

QEMU arm64 cloud server emulation

This is basically a rehash of an original post on CNXSoft - all credit (particularly for the Virtio device arguments used below) belongs to the author of that piece.

Download the latest uefi1.img image. E.g. ubuntu-16.04-server-cloudimg-arm64-uefi1.img from https://cloud-images.ubuntu.com/releases/16.04/release/

Download the UEFI firmware image QEMU_EFI.fd from https://releases.linaro.org/components/kernel/uefi-linaro/latest/release/qemu64/

Determine your current username and get your current ssh public key:

@kingluo
kingluo / processes.erl
Last active July 7, 2023 08:19
erlang noshell
$ erlc processes.erl
$ erl -noshell -s processes test -s init stop
the max processes is 262144
the proecess time is 2.0:3.57
$ erl -noshell -s processes test2 100000 -s init stop
the max processes is 262144
{"init terminating in do_boot",{system_limit,[{erlang,spawn,[erlang,apply,[#Fun<processes.2.26012808>,[]]],[]},{erlang,spawn,1,[]},{processes,for,3,[{file,"processes.erl"},{line,24}]},{processes,for,3,[{file,"processes.erl"},{line,24}]},{processes,max,1,[{file,"processes.erl"},{line,10}]},{init,start_it,1,[]},{init,start_em,1,[]}]}}
# program freeze here...
# Ctrl+C not work
@CMCDragonkai
CMCDragonkai / http_streaming.md
Last active May 7, 2024 16:35
HTTP Streaming (or Chunked vs Store & Forward)

HTTP Streaming (or Chunked vs Store & Forward)

The standard way of understanding the HTTP protocol is via the request reply pattern. Each HTTP transaction consists of a finitely bounded HTTP request and a finitely bounded HTTP response.

However it's also possible for both parts of an HTTP 1.1 transaction to stream their possibly infinitely bounded data. The advantages is that the sender can send data that is beyond the sender's memory limit, and the receiver can act on

@scottslowe
scottslowe / ubuntu-1404-preseed
Created May 20, 2015 17:49
This is a preseed file, written for Ubuntu Server 14.04.2, that provides a fully automated installation (assuming the presence of a PXE boot infrastructure and a local HTTP server to provide the installation files).
# Ubuntu Server automated installation
# by Scott Lowe (scott.lowe@scottlowe.org)
d-i debian-installer/locale string en_US
d-i console-setup/ask_detect boolean false
d-i keyboard-configuration/layoutcode string us
d-i netcfg/choose_interface select eth0
d-i netcfg/get_hostname string hostname
d-i netcfg/get_domain string domain.com
d-i netcfg/wireless_wep string
@mbaldessari
mbaldessari / ethtool-speed-test.c
Created April 19, 2015 08:08
Get the speed of a network interface via the ethtool interface
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <net/if.h>
#include <ctype.h>
#define ETHTOOL_GSET 0x1
#define SIOCETHTOOL 0x8946