This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Calculate Pi in Clojure | |
; https://rosettacode.org/wiki/Pi | |
; https://en.wikipedia.org/wiki/Spigot_algorithm | |
(defn pi-digits [& {:keys [q r t k n l]}] | |
(if (< (- (+ (* 4 q) r) t) (* n t)) | |
(cons n | |
(lazy-seq | |
(pi-digits :q (* q 10) | |
:r (* 10 (- r (* n t))) | |
:t t |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; This one is really nice and compact but it quickly runs out of stack space: | |
(defn primes [i] (cons i (lazy-seq (filter #(not (zero? (mod % i))) (primes (inc i)))))) | |
(take 100 (primes 2)) | |
; (2 3 5 7 ...) | |
(take 1000 (primes 2)) | |
; Error printing return value (StackOverflowError) at user/primes (NO_SOURCE_FILE:1). | |
; This one is slightly less elegant but works for large numbers: | |
(defn primes [i p] | |
(if (some #(zero? (mod i %)) p) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(import '[magick MagickImage ImageInfo ColorspaceType]) | |
(defn spit-image [file-name width height data] | |
"Save an RGB image" | |
(let [info (ImageInfo.) | |
image (MagickImage.)] | |
(.constituteImage image width height "RGB" data) | |
(.setSize info (str width \x height)) | |
(.setDepth info 8) | |
(.setColorspace info ColorspaceType/RGBColorspace) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use-modules (system base lalr)) | |
(define csv-parse | |
(lalr-parser | |
(CELL COMMA NEWLINE RETURN) | |
(csv () : '() | |
(csv row) : (cons $2 $1)) | |
(row (nl) : (list "") | |
(COMMA row) : (cons "" $2) | |
(CELL nl) : (list $1) | |
(CELL COMMA row) : (cons $1 $3)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
embed | |
base.c | |
.*.un~ | |
*.3m.c | |
*.o |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use-modules (oop goops) (ice-9 binary-ports) (rnrs bytevectors) (aiscm core) (system foreign) (aiscm xorg) (ice-9 format) | |
; http://yann.lecun.com/exdb/mnist/ | |
(define f (open-file "train-labels-idx1-ubyte" "rb")) | |
(define magic (bytevector-u32-ref (get-bytevector-n f 4) 0 (endianness big))) | |
(define n (bytevector-u32-ref (get-bytevector-n f 4) 0 (endianness big))) | |
(define bv (get-bytevector-n f n)) | |
(define labels (make (multiarray <ubyte> 1) #:memory (bytevector->pointer bv) #:shape (list n))) | |
(define f (open-file "train-images-idx3-ubyte" "rb")) | |
(define magic (bytevector-u32-ref (get-bytevector-n f 4) 0 (endianness big))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Minimal OpenGL shader example using OpenGL directly | |
#include <math.h> | |
#include <stdio.h> | |
#include <GL/glew.h> | |
#include <GL/glut.h> | |
const char *vertexSource = "#version 130\n\ | |
in mediump vec3 point;\n\ | |
in mediump vec2 texcoord;\n\ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# http://blog.aloni.org/posts/backprop-with-tensorflow/ | |
import random | |
import pickle | |
import gzip | |
import numpy as np | |
import tensorflow as tf | |
import cv2 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# http://blog.aloni.org/posts/backprop-with-tensorflow/ | |
import random | |
import numpy as np | |
import tensorflow as tf | |
import pickle | |
import gzip | |
import cv2 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import sys | |
import numpy as np | |
import tensorflow as tf | |
class CharVec: | |
def __init__(self, text): | |
self.chars = np.array([ord(c) for c in sorted(set(text))]) |