Skip to content

Instantly share code, notes, and snippets.

@jbg
jbg / panel-jd35695b.c
Last active May 6, 2023 06:24
DSI driver for the nexus 5x
// SPDX-License-Identifier: GPL-2.0-only
// Copyright (c) 2019, The Linux Foundation. All rights reserved.
#include <drm/drm_mipi_dsi.h>
#include <drm/drm_modes.h>
#include <drm/drm_panel.h>
#include <linux/backlight.h>
#include <linux/delay.h>
#include <linux/gpio/consumer.h>
#include <linux/module.h>
@jbg
jbg / sha256_tfhe.rs
Created May 6, 2023 06:12
A demonstration of calculating SHA-256 over encrypted data, producing an encrypted result, using the tfhe-rs fully homomorphic encryption library.
#![feature(iter_array_chunks)]
use std::{array, io::{Read, stdin}, iter};
use tfhe::{
ConfigBuilder, FheUint32, generate_keys, set_server_key,
prelude::{FheDecrypt, FheTryEncrypt, FheTrivialEncrypt},
};
fn main() -> Result<(), std::io::Error> {
@jbg
jbg / gpt4-doas-shell-env-var.md
Last active April 7, 2023 04:21
GPT-4 tries to discuss the behaviour of `doas` with respect to the $SHELL environment variable

jbg: Which shell does doas -s execute, the calling user's or the target user's? And what does it set the $SHELL environment variable to?

GPT-4: The doas -s command is used to execute a shell with elevated privileges. When you run this command, it will execute the target user's shell, typically the root user's shell. The target user's shell is determined by their entry in the /etc/passwd file.

The $SHELL environment variable will be set to the target user's default shell as specified in the /etc/passwd file. For example, if the target user's default shell is /bin/bash, the $SHELL variable will be set to /bin/bash during the doas -s session. Keep in mind that the actual behavior may vary slightly depending on the implementation of doas and the operating system you are using.

jbg: Your first paragraph is incorrect, it actually executes the shell in the calling user's SHELL environment variable or /etc/passwd entry.

GPT-4: You are correct, I apologize for the confusion

@jbg
jbg / lambda-edge-sigv4a-for-s3-multi-region-access-point.js
Created March 18, 2023 07:33
A Lambda@Edge function that signs the origin request with SigV4A, allowing the use of an S3 Multi-Region Access Point as a custom origin
import { CrtSignerV4 } from "@aws-sdk/signature-v4-crt";
const allowedHeaders = [
"accept-encoding",
"content-length",
"if-modified-since",
"if-none-match",
"if-range",
"if-unmodified-since",
"transfer-encoding",
#!/usr/bin/env python3
# Export your Google Maps starred places from https://www.google.com/bookmarks/
# Then pipe them through this script to get GeoJSON:
# ./gmaps_stars_to_geojson.py < GoogleBookmarks.html > features.json
# You could import the resulting GeoJSON file to a PostGIS database with:
# ogr2ogr -f PostgreSQL PG:"dbname=DBNAME user=USER password=PASSWORD host=HOST" features.json -nln TABLENAME -append
# Depends on 'geojson', 'lxml' and 'requests' from PyPI.
@jbg
jbg / Dockerfile.rust
Last active May 1, 2021 05:04
multi-stage Dockerfile for rust builds that allows building stages after `cargo fetch` without network access
# Example usage:
# docker build --target=fetcher .
# docker build --network=none -t "$TAG" .
FROM rust-builder:0.2.1 AS fetcher
COPY Cargo.toml Cargo.lock ./
RUN mkdir src \
&& touch src/main.rs \
&& cargo fetch --locked
#!ipxe
imgtrust
set release 2020.12.01
set mirrorurl http://mirror.rackspace.com/archlinux/
kernel ${mirrorurl}iso/${release}/arch/boot/x86_64/vmlinuz-linux
imgverify vmlinuz-linux ${mirrorurl}iso/${release}/arch/boot/x86_64/vmlinuz-linux.ipxe.sig
initrd ${mirrorurl}iso/${release}/arch/boot/amd-ucode.img
imgverify amd-ucode.img ${mirrorurl}iso/${release}/arch/boot/amd-ucode.img.ipxe.sig
initrd ${mirrorurl}iso/${release}/arch/boot/intel-ucode.img
imgverify intel-ucode.img ${mirrorurl}iso/${release}/arch/boot/intel-ucode.img.ipxe.sig
use std::future::Future;
use futures::future::{self, Either, FutureExt, Map, Ready};
trait AsyncOption<T> {
fn async_map<U, Fun, Fut>(
self,
f: Fun,
) -> Either<Map<Fut, &'static dyn Fn(Fut::Output) -> Option<U>>, Ready<Option<U>>>
where
#![feature(never_type)]
use std::io;
use pnet::{
packet::ip::IpNextHeaderProtocols,
transport::{ipv4_packet_iter, transport_channel, TransportChannelType},
};
fn main() -> Result<!, io::Error> {
/*
ct-logs = "0.6.0"
http = "0.1.18"
hyper = "0.12.33"
hyper-rustls = "0.17.0"
rustls = "0.16.0"
tokio = "0.1.22"
webpki-roots = "0.17.0"
*/