Skip to content

Instantly share code, notes, and snippets.

const std = @import("std");
pub fn main() !void {
const stdout = try std.io.getStdOut();
var direct_allocator = std.heap.DirectAllocator.init();
defer direct_allocator.deinit();
var arena = std.heap.ArenaAllocator.init(&direct_allocator.allocator);
defer arena.deinit();
@ljmccarthy
ljmccarthy / removeable_drives_wmi.ps1
Created March 25, 2019 14:38
List removeable drives using WMI query
Get-WmiObject -query "SELECT * FROM Win32_DiskDrive WHERE MediaType = 'Removable Media'" | Select-Object *
@ljmccarthy
ljmccarthy / writable_removeable_drives.ps1
Last active March 25, 2019 10:53
List removable writable drives on Windows
Get-WmiObject -Class Win32_DiskDrive |
Where-Object {$_.Capabilities -contains 3 -and $_.MediaType -eq "Removable Media"} |
Select-Object Caption, Size, SerialNumber, InterfaceType, DeviceID, Status
@ljmccarthy
ljmccarthy / det386.asm
Last active December 9, 2018 01:15
Detect 32-bit processor
format MZ
entry main:start
use16
segment main
start:
call detect_i386
mov dx, strings.error
jnc .print
@ljmccarthy
ljmccarthy / detcpu.asm
Last active March 30, 2019 07:14
Detect x86 CPU Type (8086, i286, i386, i486, Pentium, Pentium Pro)
format MZ
entry main:start
use16
segment main
start:
call detect_cpu
mov dx, strings
mov ds, dx
@ljmccarthy
ljmccarthy / detect.asm
Last active December 29, 2024 14:46
Detect CGA, EGA, VGA or VESA BIOS in DOS.
format MZ
entry main:start
use16
segment main
start:
; detect EGA BIOS
mov ah, 0x12
mov bl, 0x10
#!/usr/bin/env python3
import os
import re
import sys
def incbin(filename):
with open(filename, 'rb') as f:
data = f.read()
name = os.path.splitext(os.path.basename(filename))[0]
@ljmccarthy
ljmccarthy / varint.c
Last active October 16, 2018 11:43
Variable-sized integer encoding (32-bit)
#include <assert.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
size_t varint_size(uint32_t value) {
return value < 0x80 ? 1 :
value < 0x4000 ? 2 :
value < 0x200000 ? 3 :
value < 0x10000000 ? 4 : 5;
@ljmccarthy
ljmccarthy / selfcompilerun.c
Created October 11, 2018 10:55
Self-compile and run C file. chmod +x and ./run it!
#if 0
set -e
[ -z "$CC" ] && CC=$(which tcc clang gcc cc | head -1)
out="$(tempfile -p $(echo $(basename $0) | cut -f 1 -d '.'))"
$CC -pipe -x c -std=c99 -g -ftrapv -o $out "$0"
exec $out "$@"
#endif
#include <stdio.h>
#!/usr/bin/env python
#
# Displays the average line length from a directory of source files.
#
# Luke McCarthy 2018
from __future__ import print_function
import argparse
import os
import re