Skip to content

Instantly share code, notes, and snippets.

@AyeGill
AyeGill / sexp-to-xml
Created December 5, 2012 13:14
Converts s-expressing into xml
;(:foo ((:bar (1234))) :baz "12345") -> <foo baz="12345"><bar>1234</bar></foo>
(defgeneric make-html-indent (expr indentation))
(defmethod make-html-indent (expr indentation)
(let ((output (make-array 0
:element-type 'character
:adjustable t
:fill-pointer 0)))
(dotimes (n indentation)
@AyeGill
AyeGill / filemailer.lisp
Created December 5, 2012 16:50
Common lisp file mailing automation
;;;;Lisp file mailing automation.
;;;;Purpose: send all files in folder(recursively) by supplied email acount to supplied email account.
;;;;Requires quicklisp. Feel free to make a quicklisp-independent version.
;;;example usage:
;;;(mail-dir "directory" "example@gmail.com" "pass123" :predicate (lambda (x) (not (search "nope"))))
;;;mails all files in directory not containing nope to example@gmail.com, using example@gmail.com with the password pass123
@AyeGill
AyeGill / components.lisp
Created December 14, 2012 23:23
Component-based programming framework in Common Lisp. Incomplete.
;;;Notes:
;;;Altered message-sending code so that the function associated with message recieves as first argument the recieving component, then the passed arguments from sender.
;;;Also, need to think about issues of components that purely hold data and how they communicate it to other components. Right now, they have to broadcast it every tick(or whatever), which probably causes some overhead.
;;;Lastly, need to actually do some tests.
(defclass component ()
((parent :initarg parent :accessor parent) ;reference to the entity to which the component belongs
(message-responses :initform (make-hash-table) :accessor message-responses))) ;should hold functions that are called when various messages are recieved.
(defclass entity ()
@AyeGill
AyeGill / physics.lisp
Created January 2, 2013 07:19
physics simulation system in common lisp.
(defclass world ()
((points :initform (make-hash-table) :accessor points)
(rules :initform (make-hash-table) :accessor rules)
(attachments :initform nil :accessor attachments)))
(defclass attachment ()
((point-a :initarg :point-a :accessor point-a)
(point-b :initarg :point-b :accessor point-b)
(rule :initarg :rule :accessor rule)))
;rule is called with arguments point-a point-b to decide force applied to point-a. force applied to point-b is negation of that
@AyeGill
AyeGill / gist:5403893
Created April 17, 2013 12:35
These are the error I recieve when trying to compile the first example in https://github.com/bjz/open.gl-tutorials (c2_color_triangle.rs) The libglcore-9481761d26f186d5-0.1.so file was compiled by doing make targeted with the Makefile provided with https://github.com/bjz/glcore-rs
ayegill@analytical-engine:~/open.gl-tutorials/src$ rustc c2_color_triangle.rs -L ~/glfw-rs/lib -L ~/glcore-rs/lib
error: linking with `cc` failed with code 1
note: cc arguments: -L/usr/local/lib/rustc/x86_64-unknown-linux-gnu/lib -m64 -o c2_color_triangle c2_color_triangle.o -L/usr/local/lib/rustc/x86_64-unknown-linux-gnu/lib -lcore-c3ca5d77d81b46c1-0.6 -L/home/ayegill/glfw-rs/lib -lglfw-13f753cda49c681f-0.1 -L/home/ayegill/glcore-rs/lib -lglcore-9481761d26f186d5-0.1 -lGL -lrustrt -lrt -lpthread -L/home/ayegill/glfw-rs/lib -L/home/ayegill/glcore-rs/lib -lrt -ldl -lm -lmorestack -lrustrt -Wl,-rpath,$ORIGIN/../../../../usr/local/lib/rustc/x86_64-unknown-linux-gnu/lib -Wl,-rpath,$ORIGIN/../../glfw-rs/lib -Wl,-rpath,$ORIGIN/../../glcore-rs/lib -Wl,-rpath,/usr/local/lib/rustc/x86_64-unknown-linux-gnu/lib -Wl,-rpath,/home/ayegill/glfw-rs/lib -Wl,-rpath,/home/ayegill/glcore-rs/lib
note: /home/ayegill/glcore-rs/lib/libglcore-9481761d26f186d5-0.1.so: undefined reference to `glUniform4d'
/home/ayegill/glcore-rs/lib/lib
@AyeGill
AyeGill / Rust ICE
Last active December 17, 2015 10:28
Rust ICE backtrace.
ayegill@analytical-engine:~/projects/rust/rust-gl$ RUST_LOG=rustc=1,::rt::backtrace rustc test.rs -L ~/glfw-rs/lib -L ~/glcore-rs/lib -L . -o test
rust: task failed at 'assertion failed: def_id.crate == ast::local_crate', /home/ayegill/rust-0.6/src/librustc/middle/trans/callee.rs:286
/usr/local/bin/../lib/librustrt.so(_ZN9rust_task13begin_failureEPKcS1_m+0x4b)[0x7f2bb593ac7b]
/usr/local/bin/../lib/librustrt.so(+0x2aa69)[0x7f2bb594ba69]
/usr/local/bin/../lib/librustrt.so(upcall_fail+0x1a8)[0x7f2bb593ca68]
/usr/local/bin/../lib/libcore-c3ca5d77d81b46c1-0.6.so(+0x1055fb)[0x7f2bb74715fb]
/usr/local/bin/../lib/libcore-c3ca5d77d81b46c1-0.6.so(+0x1055a2)[0x7f2bb74715a2]
/usr/local/bin/../lib/libcore-c3ca5d77d81b46c1-0.6.so(_ZN3sys12begin_unwind17_61fe198059b9e3fc3_06E+0x71)[0x7f2bb73b9671]
/usr/local/bin/../lib/libcore-c3ca5d77d81b46c1-0.6.so(_ZN3sys11fail_assert17_10b61817f19c764b3_06E+0x228)[0x7f2bb73c2ce8]
/usr/local/bin/../lib/librustc-c84825241471686d-0.6.so(_ZN6middle5trans6callee25trans_fn_ref_with_vtables16_
@AyeGill
AyeGill / No Bug Polmorphism.rs
Last active December 17, 2015 10:28
This code failed to cause an ICE.
struct V<T>(int);
impl<T> V<T> {
fn new() -> V<T> {
V(12)
}
fn foo(self, val : T) {
let mut i = 0;
while i < *self {
println(fmt!("%?", val));
i += 1;
@AyeGill
AyeGill / wikiget.clj
Last active December 18, 2015 09:19
Simply get the text contents of wikipedia articles. Requires clj-http.
(ns wikiget.core
(:gen-class)
(:require [clj-http.client :as client]))
(defmacro pipeline
([x] x)
([x y] `(~y ~x))
([x y & more] `(pipeline (~y ~x) ~@more)))
(defn wikiget [name]
@AyeGill
AyeGill / irc.clj
Last active December 18, 2015 09:59
Simple clojure IRC interaction.
(require '(org.schwering.irc)) ;available on clojars
;;There's really no sane default for these values, but for testing purposes it's nice to not need to type them in. Laziness.
;;These are out here instead of in the function definition so you can rebind them if you want to connect several times with the same credentials
(def default-name "IRC Bot")
(def default-nick "Bot")
(def default-realname "John Robot")
(defn make-connection
"Establish a connection, returns an instance of org.schwering.irc.lib.IRCConnection. Hosts should be an int vector, not an array"
[{:keys [host pass name nick realname ports] :or {name default-name nick default-nick realname default-realname ports [6667] pass ""}}]
(defn getvals [form] (cond (seq? form) form (vector? form) (seq form) (map? form) (map second (seq form)) true false))
(defn getleaves [tree] (let [vals (getvals tree)]
(if vals (mapcat getleaves vals)
(list tree))))