Skip to content

Instantly share code, notes, and snippets.

View serialhex's full-sized avatar
😸
Pondering language design...

serialhex

😸
Pondering language design...
View GitHub Profile
#include "dir.h"
#include <arrayfire.h>
std::vector<std::string> get_tiff_files(std::string dir) {
std::regex re ("*\\.tiff?");
return Dir::re_filter(Dir::get_files_in_dir(dir), re);
}
@serialhex
serialhex / Makefile
Created October 12, 2016 15:00
Makefiles on Windows!!!
#define macros
EXE = executable.exe
SRC = src
BIN = bin
INT = obj
INCL = include
OCV_INC = "$(OPENCV_DIR)\..\..\include"
OCV_LIB = "$(OPENCV_DIR)\lib\opencv_world310.lib"

# Change the definition of CCL_DEFAULT_DIRECTORY below to refer to
# your Clozure CL installation directory. The lisp will use this
# environment variable to set up translations for the CCL: logical
# host.
# Any definition of CCL_DEFAULT_DIRECTORY already present in the
# environment takes precedence over definition made below.
if( ! $CCL_Default_Directory ) {
@serialhex
serialhex / using-case.lisp
Created September 12, 2016 20:19
FizzBuzz...
(defun fizzbuzz (n)
(fizzbuzz-helper 1 n ))
(defun fizzbuzz-helper (n x)
(case (mod n 15)
(0 (princ "FizzBuzz"))
((3 6 9 12) (princ "Fizz"))
((5 10) (princ "Buzz"))
(otherwise (princ n)))
(fresh-line)
@serialhex
serialhex / normal-random.lisp
Last active September 14, 2022 15:51
Generate normal (gaussian) random numbers in lisp!
(defun normal-random (mean std-dev)
"Normal random numbers, with the given mean & standard deviation."
(do* ((rand-u (* 2 (- 0.5 (random 1.0))) (* 2 (- 0.5 (random 1.0))))
(rand-v (* 2 (- 0.5 (random 1.0))) (* 2 (- 0.5 (random 1.0))))
(rand-s (+ (* rand-u rand-u) (* rand-v rand-v))
(+ (* rand-u rand-u) (* rand-v rand-v))))
((not (or (= 0 rand-s) (>= rand-s 1)))
(+ mean
(* std-dev
(* rand-u (sqrt (/ (* -2.0 (log rand-s)) rand-s))))))))
all 3 plots should be the same, they are not!
https://postimg.org/image/vdcnsnafb/
@serialhex
serialhex / 0-test
Last active June 22, 2016 19:48
clasp errors
clang-linux.compile.c++.without-pth /home/justin/opensource/clasp/build/clasp/Contents/Resources/cxx/clasp/src/main/clang-linux-linux/release/gc-boehm/program-clasp/sharpEqualWrapper.o
clang version 3.9.0 (http://llvm.org/git/clang.git 15e8341db0a87789998fd828bf09c96a7821e917) (http://llvm.org/git/llvm.git 7a3e4d658c5d54e48cc6a793ee9e497ae7afc6f5)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/justin/opensource/externals-clasp/build/release/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-pc-linux-gnu/6.1.1
Found candidate GCC installation: /usr/lib64/gcc/x86_64-pc-linux-gnu/6.1.1
Selected GCC installation: /usr/lib64/gcc/x86_64-pc-linux-gnu/6.1.1
Candidate multilib: .;@m64
Selected multilib: .;@m64
@serialhex
serialhex / semver.lisp
Created June 2, 2016 13:29
Simple Semantic Versioning Tests for Common Lisp
;; This function is the only one that needs to be defined,
;; everything else can be defined in terms of this one function.
;; YAY LOGIC!
;;
;; This assumes only *simple* semvers containing only *numbers*
;; so something like "1.3.9-beta" it will barf on...
;; maybe something for an extension later?
;;
;; run it like this:
;; `(semver<= "1.2.3" "1.2.3")`
;; here is a funky little function to parse a string representing a
;; number with any base (radix) from 2 upto 36 (0-9+a-z)
;;
;; it can even do floats in alternate bases!!
;; so "0.1" in binary = "0.5" in decimal! :-D
;; (2e(-1) = 1/2 = 0.5)
;; one note: you *need* split-sequence to use this function,
;; everything else is vanilla common lisp
(defun parse-number (str &optional (radix 10))
@serialhex
serialhex / struct-slots.lisp
Last active August 12, 2018 11:11
Get slots from a random struct. Can you do that in (Objective-)C(++|#)???
(defun struct-slots (struct)
"Quick & dirty hack to get the slot names of a given struct"
(let ((data (cdr (read-from-string (string-left-trim "#S" (format nil "~S" struct))))))
(labels ((pull-slot (s k)
(if s
(pull-slot (cddr s) (cons (car s) k))
k)))
(pull-slot data nil))))
;; it's not the prettiest/most efficient code, but it works!