Skip to content

Instantly share code, notes, and snippets.

View phoe's full-sized avatar
🤔
:thonk:

Michał "phoe" Herda phoe

🤔
:thonk:
View GitHub Profile
@phoe
phoe / on_stateful_code.txt
Created March 9, 2016 22:42 — forked from josteink/on_stateful_code.txt
On why stateful code is bad
On why stateful code is bad
===========================
STUDENT: Sir, can I ask a question?
TEACHER: Yes!
STUDENT: How do you put an elephant inside a fridge?
TEACHER: I don't know.
STUDENT: It's easy, you just open the fridge and put it in. I have another question!
TEACHER: Ok, ask.
STUDENT: How to put a donkey inside the fridge?

Keybase proof

I hereby claim:

  • I am phoe on github.
  • I am phoe (https://keybase.io/phoe) on keybase.
  • I have a public key whose fingerprint is DF25 B517 A75E 2BBC 08CC B16B 2463 9CD1 4EE8 FB35

To claim this, I am signing this object:

@phoe
phoe / add-slot-to-defclass.lisp
Created January 25, 2017 18:40
How to add slot to defclass
(defclass foo-class (standard-class) ;; we first create a metaclass
()) ;; no slots required
(defmethod initialize-instance :before ((class foo-class) &key my-argument)
(print my-argument)) ;; when we first define the class, just print the arguments
(defmethod reinitialize-instance :before ((class foo-class) &key my-argument)
(print my-argument)) ;; when we later redefine the class, just print the arguments again
(defmethod validate-superclass ((class foo-class) (super standard-class))
@phoe
phoe / lzma_sample.cpp
Created July 7, 2017 10:55 — forked from Treeki/lzma_sample.cpp
simple LZMA SDK compression/decompression example
// note: -D_7ZIP_ST is required when compiling on non-Windows platforms
// g++ -o lzma_sample -std=c++14 -D_7ZIP_ST lzma_sample.cpp LzmaDec.c LzmaEnc.c LzFind.c
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <memory>
#include "LzmaEnc.h"
#include "LzmaDec.h"
@phoe
phoe / lzma.lisp
Last active July 17, 2017 19:22
LZMA wrapper for Common Lisp
#|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; CFFI LZMA Wrapper
;; © Michał "phoe" Herda 2017
;; public domain
;; Use the attached lzma.so file, which is a x64 Linux shared
;; object. To compile the shared library file yourself:
;; 1. Install the official LZMA SDK from Igor Pavlov.
@phoe
phoe / split-list.lisp
Last active July 22, 2017 13:32
Fast destructive list splitting in Common Lisp
(let* ((list (list 1 2 3 4 5 6 7 8 9 0))
(first list)
(second (cdr list)))
(do ((left list (cdr left))
(right (cdr list) (cdr right)))
((and (null (cdr left))
(null (cdr right))))
(setf (cdr left) (cddr left)
(cdr right) (cddr right)))
(values first second))
;; thanks, beach!
(defun split-list-if (predicate list)
"Destructively splits the provided list into two lists: one contains the
elements of the original list that satisfy the predicate, the other contains
elements that do not satisfy the predicate. The order of the original elements
is preserved."
(loop with result1 = '()
with result2 = '()
with rest = list
@phoe
phoe / bknr.multistore.lisp
Created July 31, 2017 11:56
BKNR multistore sketch
;; unfinished - I'll think of finishing this some other time mayhaps
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; BKNR.MULTISTORE
;;;; © Michał "phoe" Herda 2017
;;;; bknr.multistore.lisp
(defpackage #:bknr.multistore
(:shadowing-import-from #:closer-mop
#:standard-generic-function #:defmethod #:defgeneric
@phoe
phoe / hmmm.lisp
Last active October 6, 2017 15:01
Common Lisp that makes you go hmmm
"This one should be fairly obvious."
(defun the-answer-to-life-the-universe-and-everything ()
(+(*(+(*)(*))(+(*)(*)(*)))(*(*(+(*)(*))(+(*)(*)(*)))(*(+(*)(*))(+(*)(*)(*))))))
"The advanced version of the above."
(defun rick (
) (
+ (+
) ( *) (
*) (+) ( *)
@phoe
phoe / pprint-plist.lisp
Last active August 6, 2017 09:19
Pretty-printing function for config-like plists
(defun pprint-plist (*standard-output* list)
"Pretty-prints a plist with newlines after each key-value pair.
This will break if not called at toplevel, but works well enough for my use case."
(pprint-logical-block (*standard-output* list :prefix "(" :suffix ")")
(loop for cell on list by #'cddr
do (write (first cell))
(write-char #\Space)
(write (second cell))
(when (cddr cell)
(terpri *standard-output*)