Skip to content

Instantly share code, notes, and snippets.

@josephcsible
josephcsible / q73762024.hs
Last active September 19, 2022 13:12
Using the C preprocessor with single quotes where C wouldn't allow them
{-# LANGUAGE CPP #-}
#define MAIN_FN_NAME main
#define puts putStrLn hello'world
hello'world :: String
hello'world = "Hello, World!"
MAIN_FN_NAME = puts
@josephcsible
josephcsible / README.md
Last active July 19, 2022 04:05
Masquerade one Wi-Fi network to another from a Mac
  • Boot with a USB drive with an image from https://github.com/marcosfad/mbp-ubuntu
  • Hold Option at the chime and pick the last one
  • echo high > /sys/bus/pci/drivers/amdgpu/0000:??:??.?/power_dpm_force_performance_level
  • apt install /usr/src/iso-firmware.deb
  • modprobe -r brcmfmac
  • modprobe brcmfmac
  • systemctl restart network-manager
  • Add this to /etc/NetworkManager/NetworkManager.conf:
[device]
global memcpy64, _memcpy64
section .text
memcpy64:
_memcpy64:
push edi
push esi
call 0x33:.heavensgate
pop esi
pop edi
@josephcsible
josephcsible / parentconsole.c
Created June 3, 2022 17:47
Write to the parent's console regardless of process creation flags
#include <windows.h>
#include <stdio.h>
int main(void) {
FreeConsole();
AttachConsole(ATTACH_PARENT_PROCESS);
freopen("CONOUT$", "w", stdout);
puts("This will go to the parent's console no matter what process creation flags were used");
}
@josephcsible
josephcsible / DebianVersionString.hs
Last active May 27, 2022 03:58
A comparator for upstream_version and debian_revision strings, as described at https://www.debian.org/doc/debian-policy/ch-controlfields.html#version
{-# LANGUAGE DerivingStrategies, GeneralizedNewtypeDeriving, TypeApplications #-}
import Data.Char
import Data.Function
newtype DebianVersionString = DebianVersionString String deriving newtype Show
instance Eq DebianVersionString where
x == y = compare x y == EQ
import Control.Monad.State
import Data.Traversable
{-
>>> uglyMap (,,) "abc"
[('a',0,"abc"),('b',1,"abc"),('c',2,"abc")]
-}
uglyMap :: Traversable t => (a -> Int -> t a -> b) -> t a -> t b
uglyMap f xs = flip evalState 0 $ for xs $ \x -> do
i <- get
@josephcsible
josephcsible / Main.hs
Last active June 2, 2020 21:05
"Obvious" refactors can be wrong
{-# OPTIONS -Werror=type-defaults #-}
import Data.Maybe (isJust)
import Data.Word (Word16, byteSwap16)
default ()
oneNumTup :: Num a => (a, a)
oneNumTup = (2, 300)
Var ::= [a-zA-Z]+
;
PrimaryTerm ::= Var
| '(' Term ')'
;
ApplyTerm ::= PrimaryTerm
| ApplyTerm PrimaryTerm
;
@josephcsible
josephcsible / Counterexample.hs
Last active December 29, 2019 18:48
Something like STRef but usable in a monad transformer
{-# LANGUAGE RankNTypes #-}
-- Adapted from https://gist.github.com/Lysxia/18fce5d4ce8ff7eb7117dfb827770187 to work on StatesT
import Control.Monad
import Control.Monad.Trans.Class
import Data.Void
import StatesT
-- Demonstration that StatesT is unsafe
@josephcsible
josephcsible / combinatory.c
Last active June 16, 2020 21:06
Combinatory logic with C, using raw function pointers as closures
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#include <string.h>
#include <sys/mman.h>
typedef void *(*f)(void *);
f make_function_with_state(f code, size_t code_len, void *state, size_t state_len) {
f mem = mmap(NULL, code_len + state_len, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);