Skip to content

Instantly share code, notes, and snippets.

View iximeow's full-sized avatar
🐟
you can tune a piano but you can't tuna fish

iximeow iximeow

🐟
you can tune a piano but you can't tuna fish
View GitHub Profile
@iximeow
iximeow / main.c
Last active February 21, 2021 20:01
how to download more ram
/*
* if you need more memory, add some to your program with this cool trick
*/
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
#include <stddef.h>
#include <stdio.h>
#include <sys/mman.h>
@iximeow
iximeow / main.rs
Created October 10, 2020 04:19
rust is good at vtables
trait Person {
fn greeting(&self) -> StateOfMind;
fn name(&self) -> &'static str;
}
struct Ixi { }
struct Katie { }
#[derive(Debug)]
enum StateOfMind {
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/ucontext.h>
#include <stdint.h>
void interpret(char op) {
printf("interpreting %02x\n", op);
}
@iximeow
iximeow / the_good_rust.rs
Created July 1, 2020 19:23
monkeypatching in rust
trait Person {
fn greeting(&self) -> StateOfMind;
fn name(&self) -> &'static str;
}
struct Ixi { }
struct Katie { }
#[derive(Debug)]
enum StateOfMind {
@iximeow
iximeow / segment_heccery.asm
Created December 29, 2019 11:20
what does Sz bit do in protected mode
; build and run: `nasm segment_heccery.asm -f bin -o img.bin && qemu-system-x86_64 img.bin -s -S`
[BITS 16]
[ORG 7c00h]
init:
cli
lgdt [gdtr]
mov eax, cr0
or al, 1
@iximeow
iximeow / bootloader.asm
Created December 12, 2017 06:41
x86 totally supports read/write to 0
; assemble like `nasm bootloader.asm` (will produce a flat binary output by default)
; run like `qemu-system-x86_64 bootloader`
[BITS 16]
[ORG 7c00h]
init:
mov cx, 0xB800
mov gs, cx
call clr_vga
mov si, HELLO
@iximeow
iximeow / bad_csharp.cs
Last active September 7, 2017 10:28
i challenge you to explain why this: 1: prints "What was null???" 2: throws an NRE 3: DOES NOT THROW IF YOU REMOVE ANY LINE IN mangler()
using System.Runtime.InteropServices;
using System.Reflection;
using System;
public class lol {
internal delegate void lolwut();
static Delegate d;
static MethodInfo info;
static unsafe byte* rawptr;
public static void Main(System.String[] args) {
@iximeow
iximeow / pf.asm
Created March 22, 2017 22:21
x86 parity flag
; nasm -f macho -o pf.o
; ld pf.o
; ./a.out
;
; this probably works on linuxes too, i think exit and write should be the same.
;
; should produce:
; tears (2)
; 00000246 <-- eax = 0, xor by 0
; 00000206 <-- xor ax, 0x0100
@iximeow
iximeow / build.sbt
Last active November 16, 2015 22:38
scalac-checked restricting recursion
name := "sbt_playground"
scalaVersion := "2.11.7"
scalaSource in Compile := baseDirectory.value / "src"
scalaSource in Test := baseDirectory.value / "test"
libraryDependencies ++= Seq(
"com.chuusai" %% "shapeless" % "2.2.5"
@iximeow
iximeow / CompileChecks.scala
Created November 14, 2015 08:44
macros to test for does-it-compile-ness
import scala.reflect.macros.{Context, TypecheckException}
import scala.reflect.runtime.universe._
import scala.language.experimental.macros
import scala.util.{Success, Failure}
import java.util.regex.Pattern
/*
* Heavily inspired by ShouldNotTypecheck (from slick) and