Skip to content

Instantly share code, notes, and snippets.

@carld
carld / lambda2.rkt
Last active August 14, 2017 03:59
scheme in one lambda, self-evaluating
#lang racket
; host eval implementation
((lambda (e env)
((lambda (eval apply)
(eval eval apply e env)) ; call eval
(lambda (eval^ apply^ e env) ; define eval
;(printf "ENV: ~a~%" env)
(printf "EXP: ~a~%" e)
(if (symbol? e)
@carld
carld / emacs-googlemail.txt
Last active July 24, 2017 22:51
send email from Emacs via googlemail
If 2FA is enabled for gmail:
1) Create an App password under Google, My Account, Sign-in and Security, App passwords
2) Copy the generated password before it disappears
In Emacs:
1) C-x m ; compose a new email in Emacs, use C-n and C-p to navigate between fields
2) C-c C-c ; send email
3) smtp ; select method of sending
@carld
carld / plisp
Created July 22, 2017 11:19
parsing lisp in lisp
#lang racket
(define (token)
(let [(c (read-char))]
;(printf "DEBUG: ~s~%" c)
c))
(define (whitespace? ch)
(case ch
((#\space #\tab #\newline #\return) #t)
/* match: search for regexp anywhere in text */
int match(char *regexp, char *text)
{
if (regexp[0] == '^')
return matchhere(regexp+1, text);
do { /* must look even if string is empty */
if (matchhere(regexp, text))
return 1;
} while (*text++ != '\0');
return 0;
@carld
carld / build.sh
Created July 15, 2017 00:22
The build script from my compiler blog article
chez --script c.scm > c.s
nasm -f macho c.s
ld c.o
./a.out
echo $?
@carld
carld / c.scm
Created July 15, 2017 00:21
The compiler from my blog article
(define emit printf)
(define (compile exp)
(cond
[(fixnum? exp) (emit "push ~a~%" exp)]
[(eq? '+ (car exp)) (begin
(compile (cadr exp))
(compile (caddr exp))
(emit "pop eax~%")
(emit "pop ebx~%")
@carld
carld / interview-questions.md
Created July 6, 2017 19:49 — forked from jvns/interview-questions.md
A list of questions you could ask while interviewing

A lot of these are outright stolen from Edward O'Campo-Gooding's list of questions. I really like his list.

I'm having some trouble paring this down to a manageable list of questions -- I realistically want to know all of these things before starting to work at a company, but it's a lot to ask all at once. My current game plan is to pick 6 before an interview and ask those.

I'd love comments and suggestions about any of these.

I've found questions like "do you have smart people? Can I learn a lot at your company?" to be basically totally useless -- everybody will say "yeah, definitely!" and it's hard to learn anything from them. So I'm trying to make all of these questions pretty concrete -- if a team doesn't have an issue tracker, they don't have an issue tracker.

I'm also mostly not asking about principles, but the way things are -- not "do you think code review is important?", but "Does all code get reviewed?".

@carld
carld / macro1.scm
Created June 5, 2017 01:17
Example of let-syntax local macro
(define-syntax section
(syntax-rules ()
[(_ type (instruction ...) ... )
(let-syntax ([b (syntax-rules ()
[(_ i) (printf "~s~%" 'i )]
[(_ i op1) (printf "~s ~s~%" 'i 'op1)]
[(_ i op1 op2) (printf "~s ~s, ~s~%" 'i 'op1 'op2)])])
(begin
(printf "~s ~s~%" 'section 'type)
@carld
carld / omg.scm
Created June 3, 2017 01:27
LLVM literal float representation from Chez Scheme
(define (float->hex fl)
(string-append "0x"
(with-output-to-string
(lambda ()
(write-ieee-float32 fl
(make-output-port
(lambda (m . args)
(case m
((write-char)
(format #t "~X" (char->integer (car args)))))) (make-string 0))
@carld
carld / ex1.c
Created May 3, 2017 02:48
machine code in c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <unistd.h>
typedef int (*factorial_func)(int);
#define X86_64_CALLING_CONVENTION 1