Skip to content

Instantly share code, notes, and snippets.

@nathanjackson
nathanjackson / boot.sh
Created September 20, 2022 13:23
Fedora 36 ARM in QEMU
#!/bin/bash
qemu-system-arm \
-M virt \
-m 3G \
-device virtio-gpu-pci \
-drive if=none,file=os.qcow2,id=hd0 \
-device virtio-blk-device,drive=hd0 \
-device virtio-net-device \
-kernel vmlinuz-5.17.5-300.fc36.armv7hl \
@nathanjackson
nathanjackson / istreambuf_ex.cpp
Created April 27, 2022 05:18
read file using istreambuf
#include <fstream>
#include <iterator>
#include <vector>
int main(int argc, char** argv)
{
std::ifstream ifs(argv[1], std::ios::binary);
std::istreambuf_iterator<char> begin(ifs), end;
std::vector<uint8_t> data(begin, end);
@nathanjackson
nathanjackson / fpe.c
Created April 25, 2022 16:04
floating point exception example
#define _GNU_SOURCE
#include <stdio.h>
#include <fenv.h>
int main()
{
feenableexcept(FE_DIVBYZERO);
double x = 12.34;
@nathanjackson
nathanjackson / interview.py
Created March 18, 2022 17:41
Python Refactoring/Testing Interview Question
# This script requests the RSS feed for phoronix.com and outputs the latest
# news items into a CSV file.
#
# It is not particularly well written, and if it were part of a real project,
# it would be awkward to test in an automated way.
#
# How would you refactor (change) this code to make it more testable for fuzzing or unit testing?
#
@nathanjackson
nathanjackson / gist:c561813eac6a645882a66965bc1852f1
Created August 23, 2021 18:15
Completely Poweroff NVIDIA on MSI GS65 Stealth
# For some reason, the native power management features of the NVIDIA card in the MSI GS65 Stealth don't seem to completely
# power down the card. This sucks because the GPU still consumes lots of power even when idle, reducing the battery life
# to about an hour.
# My workaround on Fedora 32/34 is this:
# 1. Install RPMFusion NVIDIA drivers.
# 2. Install the bbswitch driver (https://copr.fedorainfracloud.org/coprs/chenxiaolong/bumblebee/)
# 3. Configure bbswitch module to shutdown card on load.
# 4. Blacklist all nvidia drivers in the GRUB boot menu.
mkisofs -iso-level 3 -o <ISO Filename> -V <Disc Title> <File 1> .. <File N>
growisofs -speed 16 -Z /dev/sr0=<ISO Filename>
@nathanjackson
nathanjackson / gist:04ccbd496e4f2a13a9c282c664929a1d
Created April 19, 2020 17:53
Fix corrupt background in gnome shell after sleeping with an nvidia gpu
dbus-send --type=method_call --dest=org.gnome.Shell /org/gnome/Shell org.gnome.Shell.Eval "string:global.reexec_self()"
# Install wimlib
dnf install wimlib-utils wimlib
# Mount Windows 10 ISO
mkdir /tmp/winiso
mount <path to windows 10 iso> /tmp/winiso
# Create Split WIM files
wimsplit /tmp/winiso/sources/install.wim install.swm 2048
@nathanjackson
nathanjackson / detect_cycle.c
Created December 16, 2018 02:14
Tortise and Hare Algorithm
#include <assert.h>
#include <stddef.h>
#include <limits.h>
#include <stdio.h>
struct node {
int value;
struct node *next;
};
# A minimal config for samba to share with Windows 2000.
# This is insecure... don't run this config on a production system.
[global]
workgroup = SAMBA
security = user
lanman auth = yes
ntlm auth = yes
[public]