Skip to content

Instantly share code, notes, and snippets.

View Lifelovinglight's full-sized avatar

Bo Victor Natanael Fors Lifelovinglight

  • Linköping, Sweden
View GitHub Profile
(defun prompt (handler)
(princ #\Newline)
(princ "> ")
(finish-output)
(funcall handler
(read-prompt (split-at #\Space
(coerce (string-upcase (read-line)) 'list))))
(prompt handler))
(defun main ()
(defparameter *database*
(make-hash-table :test 'equal))
(defparameter *id-index* 0)
(defun new-index ()
(let ((n *id-index*))
(incf *id-index*)
n))
@Lifelovinglight
Lifelovinglight / Sexp.hs
Created July 3, 2016 14:56
S-expression de/serializer using typeclasses
module Sexp (Sexp, parseSexp) where
import Text.Parsec
import Text.Parsec.Char
import Data.Char
import Data.Text (Text)
import qualified Data.Text as Text
import Data.Map (Map)
import qualified Data.Map as Map
@Lifelovinglight
Lifelovinglight / ae.scm
Last active August 22, 2016 14:57
Improved implementation of space intercalation for chatbot
(use-modules (srfi srfi-1))
(define (ae string)
(if (string-null? string)
string
(let loop ((result (make-string (1- (* 2 (string-length string)))))
(index 0)
(len (string-length string))
(blank-line #t))
(if (= index len)
(defun parse-ftp-traffic (str)
(case (parse-integer str :junk-allowed t)
((220) 'helo)
((230) 'login-successful)
((331) 'password-requested)
((332) 'no-anonymous-logins)
((530) 'login-failed)
(otherwise nil)))
(defun speak (str)
@Lifelovinglight
Lifelovinglight / lispexample.lisp
Created December 29, 2016 23:33
sbcl not returning a fixnum in this scenario without specifying the explicit type of the return value breaks the model of type signatures as compiler promises
(locally
(declaim
(optimize (speed 3)
(space 3)
(safety 0)
(debug 0)
(compilation-speed 0))
(ftype (function (fixnum) fixnum)
dec-fixnum
dec-fixnum-fixnum))
@Lifelovinglight
Lifelovinglight / mac-changer.sh
Last active January 25, 2017 13:33
Tiniest mac changer, keeps your manufacturer hardware prefix.
#!/bin/bash
if [ "$#" -lt 1 ]; then
echo "Usage: $0 <interface label>"
else
NEW_MAC=$(ip link show $1 | tail -n1 | grep -Po 'link/ether \K[[:xdigit:]:]{8,8}')
for i in {0..2}; do
printf -v BYTE "%02x" $(($RANDOM%256))
NEW_MAC=$NEW_MAC:$BYTE
@Lifelovinglight
Lifelovinglight / hippie-prompt.cl
Created January 24, 2017 05:38
bit ugly but simplest possible example of a meaningful pushdown automata parser
(defpackage :hippie-prompt
(:use :common-lisp)
(:export :prompt
:set-prompt))
(in-package :hippie-prompt)
(defun symbolize (ln)
(intern (string-upcase (coerce ln 'string))))
@Lifelovinglight
Lifelovinglight / Lib.hs
Created February 7, 2017 22:23
Sexp parser example
{-# LANGUAGE DataKinds #-}
module Lib
( primitiveRead
, LispType ( Nil
, LispInteger
, LispString
, LispSymbol
, LispTrue
, LispList )

Keybase proof

I hereby claim:

  • I am lifelovinglight on github.
  • I am whiteline (https://keybase.io/whiteline) on keybase.
  • I have a public key ASBIgyRmAwkwYiQjNxDTfM5xu8wMU99PIy0pWH0XPazj8Ao

To claim this, I am signing this object: