Skip to content

Instantly share code, notes, and snippets.

View jeandrek's full-sized avatar

Jeandre jeandrek

  • New Zealand
View GitHub Profile
@jeandrek
jeandrek / Makefile
Last active January 20, 2022 00:51
Scratch RISC-V subset emulator programs
AS=riscv32-elf-as
CC=riscv32-elf-gcc
LD=riscv32-elf-ld
OBJCOPY=riscv32-elf-objcopy
LDFLAGS=-T riscv.ld
ASFLAGS=-march=rv32imfd
CFLAGS=$(ASFLAGS) -O2
.SUFFIXES: .s .S .txt
.text
.globl _main
_main:
call ___djgpp_nearptr_enable
testl %eax, %eax
jz err
movw $0x13, %ax
int $0x10
movl $0xa0000, %ebx
subl ___djgpp_base_address, %ebx
@jeandrek
jeandrek / io.scm
Created June 5, 2018 02:36
Haskell I/O monad in Scheme
;;;; Monads
(define (return x) (make-result x))
(define (bind m k)
(make-thunk (lambda () (execute! (k (execute! m))))))
(define (execute! m)
(cond ((result? m) (result-value m))
((thunk? m) (execute-thunk! m))))
@jeandrek
jeandrek / extract.c
Created April 9, 2018 04:46
Extract MS-DOS 8.0 disk image
#include <stdio.h>
#include <stdlib.h>
#define SECTOR 512
#define BOOTMAGIC 0xaa55
char disk[SECTOR*2880];
int
main(int argc, const char *argv[])
@jeandrek
jeandrek / uudecode.patch
Created March 4, 2018 05:31
Windows patch for 4.4BSD uudecode
--- ../Downloads/uudecode.c 1994-04-03 06:16:37 +1200
+++ uudecode.c 2018-03-04 18:23:50 +1300
@@ -50,8 +50,8 @@
#include <sys/param.h>
#include <sys/stat.h>
-#include <pwd.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
@jeandrek
jeandrek / fib.asm
Created November 19, 2017 08:06
Fibonacci for S65
@0x00
ORIGIN = 0xFF8D
==Start==
LDA #1 ; start counting at 1
{
PHA ; save A
JSR Fib
CMP 0x0200 ; if fib(A)>fib(A-1), stop
@jeandrek
jeandrek / find-function.scm
Last active November 15, 2016 04:29
Find-function – Given some input/output pairs, find a general function that works with these.
;;;; Find-function -- Given some input/output pairs, find a general function that works with these.
;;;; Copyright (C) 2016 Jeandre Kruger
;;;; All rights reserved.
;;;; Redistribution and use in source and binary forms, with or without modification,
;;;; are permitted provided that the following conditions are met:
;;;; 1. Redistributions of source code must retain the above copyright notice, this
;;;; list of conditions and the following disclaimer.
@jeandrek
jeandrek / streams.scm
Last active September 23, 2016 01:45
Streams library
;;;; Streams library
;;;; Copyright (c) 2016, Jeandre Kruger
;;;; All rights reserved.
;;;; Redistribution and use in source and binary forms, with or without modification,
;;;; are permitted provided that the following conditions are met:
;;;; 1. Redistributions of source code must retain the above copyright notice, this
;;;; list of conditions and the following disclaimer.
@jeandrek
jeandrek / RPNy McRPNface.odt
Last active July 24, 2016 00:05
RPNy McRPNface
@jeandrek
jeandrek / clickbait.js
Last active May 28, 2016 08:47
Better clickbait (more clickbaity) http://jonathan50.github.io/clickbait.html
function Words(...templates) {
this.templates = templates
}
Words.prototype.generate = function() {
return this.templates.map(generate).join(' ')
}
function generate(template) {
if(template instanceof Words)
return template.generate()