Skip to content

Instantly share code, notes, and snippets.

@shunghsiyu
shunghsiyu / vmtest.Containerfile
Created December 18, 2024 05:13
Example container description for building and running BPF selftests of stable 6.6 kernel
FROM debian:11-slim
ARG pahole_branch=master
ENV PAHOLE_BRANCH=$pahole_branch
ARG pahole_origin=https://git.kernel.org/pub/scm/devel/pahole/pahole.git
ENV PAHOLE_ORIGIN=$pahole_origin
ARG llvm_version=17
ENV LLVM_VERSION=$llvm_version
ENV CLANG=clang-$llvm_version
ENV LLVM_STRIP=llvm-strip-$llvm_version
@shunghsiyu
shunghsiyu / tnum_scast_check.py
Last active October 4, 2024 06:37
z3-based model checking of tnum_scast() implementation from @dkanaliev
#!/usr/bin/python3
from uuid import uuid4
from z3 import And, BitVec, BitVecRef, BitVecVal, Implies, prove, ULT, Extract, SignExt, ZeroExt
SIZE = 64 # Working with 64-bit integers
class Tnum:
"""A model of tristate number use in Linux kernel's BPF verifier.
https://github.com/torvalds/linux/blob/v5.18/kernel/bpf/tnum.c
"""
#!/bin/bash
set -eEuxo pipefail
export PATH="$HOME/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
export LD_LIBRARY_PATH="$HOME/.local/lib64"
trap 'exit -1' ERR
pushd "$HOME/llvm-project"
rm -r ./build || true
@shunghsiyu
shunghsiyu / model-checking-bpf-verifier-presentation.ipynb
Last active August 11, 2022 05:24
Fix description of tnum.mask, and use C-style comment
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@shunghsiyu
shunghsiyu / work_history.py
Created February 15, 2022 05:49
Python script for review usage history
#!/usr/bin/env python3
#
# Output both history of bash commands and Firefox visits in reverse
# chronological order.
import configparser
import logging
import os
import re
import shutil
import sqlite3
@shunghsiyu
shunghsiyu / README.md
Last active June 7, 2021 07:37 — forked from somic/udp_hole_punch_tester.py
Scripts to setup mosh connection with server behind firewall

mosh-nat

Scripts to setup mosh connection with server behind firewall

Setup

  • Install the stuntman package to get the stunclient binary both locally and on the server
  • Place the udp_hole_punch script inside a directory that is in $PATH so that it can be called; both locally and on the server
  • Compile mosh-nat-bind.c into mnb.so and place it inside $HOME/bin/ locally (don't need it on server)
@shunghsiyu
shunghsiyu / README.md
Created July 12, 2020 08:14
PyCon TW 2020 Fixtures

How to import

python manage.py loaddata $PATH_TO_FIXTURES_JSON

How to create

The fixtures.json is created by running python manage.py dumpdata --indent=2 users proposals events

Reference

@shunghsiyu
shunghsiyu / graph.html
Created January 21, 2018 10:14
Show Analytic Data
This file has been truncated, but you can view the full file.
<html><head><meta charset="utf-8" /></head><body><script type="text/javascript">/**
* plotly.js v1.31.2
* Copyright 2012-2017, Plotly, Inc.
* All rights reserved.
* Licensed under the MIT license
*/
@shunghsiyu
shunghsiyu / index.html
Created October 19, 2017 08:13
ThaiWebpage1
<!DOCTYPE html>
<html lang="zh-TW">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link rel="stylesheet" href="https://code.getmdl.io/1.3.0/material.teal-orange.min.css" />
<script src="https://code.getmdl.io/1.3.0/material.min.js"></script>
<style>
@shunghsiyu
shunghsiyu / app.js
Last active August 23, 2017 09:41
Show the query URL
const express = require('express')
const app = express()
app.get('*', function (req, res) {
res.send(`<body style="white-space: pre-wrap" width="100%" height="100%">
You are visiting: ${req.path}
You send the following query:
${JSON.stringify(req.query, null, 4)}