Skip to content

Instantly share code, notes, and snippets.

View belmarca's full-sized avatar

Marc-André Bélanger belmarca

View GitHub Profile
@belmarca
belmarca / rousseau.txt
Created November 9, 2023 14:24
Rousseau contrat social
AVERTISSEMENT.
Ce petit traité est extrait d’un ouvrage plus étendu, entrepris autrefois sans avoir consulté mes forces, & abandonné depuis long-tems. Des divers morceaux qu’on pouvoit tirer de ce qui étoit fait, celui-ci est le plus considérable, & m’a paru le moins indigne d’être offert au public. Le reste n’est déja plus.
DU
CONTRACT SOCIAL ;
OU,
@belmarca
belmarca / cbdownload.js
Created March 13, 2023 17:24
Download files from a codeBoot VM from a browser console
// Download files from a codeBoot VM from a browser console
// https://stackoverflow.com/a/18197341
function download(filename, text) {
var element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
BEGIN {
FIELDWIDTHS="6 5 5 4 2 4 4 8 8 8 6 6"
}
{
if ($1 == "ATOM ")
{
if (($4 == " A") || ($4 == " G") || ($4 == " C") || ($4 == " U"))
{
print;
@belmarca
belmarca / parse-url.ss
Created July 7, 2021 20:04
parse-url.ss
(import :std/misc/string)
(def IANA-registered-schemes
["aaa://"
"aaas://"
"about://"
"acap://"
"acct://"
"acr://"
"adiumxtra://"
@belmarca
belmarca / very-very-very-hacky.ss
Created June 8, 2020 19:33
A very hacky exploratory doc macro
(import (for-syntax :std/stxutil))
(defsyntax (describe stx)
(syntax-case stx ()
((macro thing)
(with-syntax ((thing-doc (format-id #'macro "%%doc%%~a" #'thing)))
#'(displayln thing-doc)))))
(defsyntax (doc stx)
@belmarca
belmarca / in.py
Last active July 21, 2021 17:15
exploration for ober
import ast
t = ast.parse("""
def my_func(n):
return n
x = 0
x += 1
import os
from ast import parse, Assign, Name, Num, Str, \
FunctionDef, arguments, arg, Return, Tuple, \
If, Compare, NameConstant, BoolOp, And, Or, \
Gt, GtE, Lt, LtE, Eq, NotEq, BinOp, Call, \
Add, Sub, Expr
def py2scm(source):
parse_tree = parse(source)
@belmarca
belmarca / cb.ss
Created April 26, 2020 01:05
Hooking gambit's ##wr.
;; cb.ss
(defstruct ugly-struct (a b c))
(defstruct wonderful-struct (a b c))
(defmethod {:wr wonderful-struct}
(lambda (self we obj)
(with ((wonderful-struct a b c) self)
(##wr-str we "🦄<")
(##wr-str we " 🌈🌈🌈 ")
(##wr-str we (string-append
@belmarca
belmarca / x86-asm.scm
Created March 1, 2020 04:25
Gambit run time code generation.
(include "~~lib/_asm#.scm")
(include "~~lib/_x86#.scm")
(include "~~lib/_codegen#.scm")
;; Convert a u8vector containing machine code into a
;; Scheme procedure taking 0 to 3 arguments. Calling
;; the Scheme procedure will execute the machine code
;; using the C calling convention.
(define (u8vector->procedure code)
@belmarca
belmarca / disasm.ss
Created March 1, 2020 00:38
Gambit disasm
;; https://gitter.im/gambit/gambit/archives/2017/10/14
;; Marc Feeley @feeley Oct 14 2017 02:15 UTC
;; @ober A bit of a hack...
(define (peek addr)
(##u8vector-ref 0 (- (+ addr 1) 8)))
(define (copy-mem addr len)
(let ((v (make-u8vector len)))
(let loop ((i 0))
(if (< i len)