Skip to content

Instantly share code, notes, and snippets.

View selfsame's full-sized avatar

Joseph Parker selfsame

  • Clover Food Lab
View GitHub Profile
@nasser
nasser / doarray.clj
Created October 4, 2015 14:32
doarray clojure iteration
(defmacro doarray [[variable array] & body]
(let [i (with-meta (gensym "i") {:tag Int64})
var-type (or (-> variable meta :tag) 'Object)
arr-type (symbol->array-type var-type)
arr (with-meta (gensym "array") {:tag arr-type})]
`(let [~arr ~array]
(loop [~i 0]
(if (= ~i (.Length ~arr))
nil
(let [~variable (aget ~arr ~i)]
@CornuAmmonis
CornuAmmonis / splittwit.sh
Last active June 17, 2018 17:08
Shell script that uses twurl to upload a chunked native video to Twitter.
file=""
tweet=""
if [ -n "$1" ]
then
file="$1"
else
echo "Usage: splittwit /path/to/video.mp4 \"My tweet goes here!\""
exit
fi
@nasser
nasser / README.md
Last active August 29, 2015 14:22
Execution of range function, implemented in pure Rejoyce

Rejoyce

Rejoyce is a purely functional, persistent, concatenative language

It maintains an In queue and an Out stackThe In queue represents code yet to be executed, and is initially populated with the program to run

The Out stack represents data to be manipulated, and is initially empty

The two record the complete state of execution at any time

To evaluate a token, Rejoyce returns a completely new In and Out stack

@vizanto
vizanto / Function.hx
Last active January 14, 2017 15:41
Haxe / Clojure interop experiments
//
// Nasty code below:
//
package java.internal;
import java.internal.Runtime;
/**
* These classes are automatically generated by the compiler. They are only
* here so there is an option for e.g. defining them as externs if you are compiling
* in modules (untested)
(ns sliders)
(defmacro slider [l]
(let [dashes (vec (repeat l "-"))]
`(do ~@(map (fn [i]
`(defn
~(symbol (clojure.string/join (assoc dashes i "*")))
[]
~(/ i (- l 1))))
(range l)))))
@nasser
nasser / curve.clj
Last active August 29, 2015 14:18
Experimenting with graphics as data
(ns curve)
(defn power [x a]
(Math/Pow x a))
(defmacro v* [a b] `(Vector2/op_Multiply ~a ~b))
(defmacro v+
([a] a)
([a b] `(Vector2/op_Addition ~a ~b))
([a b & vs] (reduce
@nasser
nasser / chance.clj
Created February 8, 2015 22:21
chance macro
(defmacro chance [& body]
(let [r (gensym "chance")
pairs (sort-by first (partition 2 body))
odds (map first pairs)
exprs (map last pairs)
sum (apply + odds)
fracs (map #(float (/ % sum)) odds)
frac-pairs (partition 2 (interleave fracs exprs))]
`(let [~r (rand)]
(cond
@timsgardner
timsgardner / fuzzy_finder_fn.clj
Created February 5, 2015 04:10
fuzzy-finder-fn
(defn fuzzy-finder-fn [name-fn resource-fn]
(fn [string-or-regex]
(let [f (if (instance? System.Text.RegularExpressions.Regex string-or-regex)
#(re-find string-or-regex (name-fn %))
(let [^String s string-or-regex]
#(let [^String n (name-fn %)]
(.Contains n s))))]
(filter f (resource-fn)))))
;; example:
@alandipert
alandipert / paths.clj
Last active September 17, 2015 12:04
Enumerate paths into a nested map
;; Copyright (c) Alan Dipert. All rights reserved.
;; The use and distribution terms for this software are covered by the
;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
;; By using this software in any fashion, you are agreeing to be bound by
;; the terms of this license.
;; You must not remove this notice, or any other, from this software.
(defn paths
"Enumerate paths into a nested map."
([root]
@nasser
nasser / retrieve.rb
Created January 4, 2015 00:59
Minimal git-style hash database
#!/usr/bin/ruby
puts open("db/#{ARGV.first}").read