Skip to content

Instantly share code, notes, and snippets.

@Beyamor
Beyamor / gist:4141059
Created November 24, 2012 19:15
Java Map
import java.util.*;
public class Main {
public static class Map {
public static interface Fn<IN, OUT> {
public OUT call(final IN in);
}
@Beyamor
Beyamor / argument-inferencer-source
Created December 14, 2012 06:55
Argument inferencer source.
(ns infer-arg.core
(:use [clojure.core.incubator :only [-?>]]))
(defn make-wrapper-fn
[symbolic-arg-list]
(eval
`(fn [f# {:keys ~symbolic-arg-list}]
(f# ~@symbolic-arg-list))))
(defn inference-wrapper
@Beyamor
Beyamor / argument-inferencer-tests
Created December 14, 2012 06:56
Argument inferencer tests.
(ns infer-arg.test.core
(:use [infer-arg.core])
(:use [clojure.test]))
(deftest fn-without-arg-list-not-wrapped
(is (= 2 ((inference-wrapper (fn [x] (inc x))) 1))))
(deftest fn-with-arg-list-is-wrapped
(is (= 2
((inference-wrapper
(ns break.rules
(:require [ame.entities.sets :as ent-sets]
[ame.input :as input])
(:use [ame.util :only [contains-all? +-when]]))
(input/define :up :vk-w :vk-up)
(input/define :down :vk-s :vk-down)
(input/define :left :vk-a :vk-left)
(input/define :right :vk-d :vk-right)
@Beyamor
Beyamor / MapLang1
Created February 8, 2013 05:32
A thought experiment involving an associative array-oriented language.
// Lisp, for reference
(if something?
(if something-else?
"double true"
"true and false")
"just false")
// Let's try something javascript-y
{tag: if,
what: something,
@Beyamor
Beyamor / gist:5485808
Created April 30, 2013 00:15
A CFG-y thing for story generation.
(ns grammar.core)
(defprotocol LHS
(=> [this rules] "Returns a vector of terminal elements according to the provided rules."))
(extend-protocol LHS
; Simply returns a singleton vector containing itself
String
(=> [this _] [this])
@Beyamor
Beyamor / gist:5485812
Created April 30, 2013 00:17
CFG story generation results.
Your story begins. You wake up. Reach the village. Cross the volcano. You defeat the dragon. You save the prince! Your story ends.
Your story begins. Your father dies. Reach the village. Find the three mages. You defeat the sorcerer. You save the world! Your story ends.
Your story begins. Your father dies. Reach the village. Find the sage. Find the three mages. You defeat the dragon. You save the prince! Your story ends.
Your story begins. Your father dies. Reach the village. Find the one orbs. Find the island. You defeat the witch. You save the princess! Your story ends.
Your story begins. You wake up. Reach the village. Cross the forest. Find the island. You defeat the witch. You save the prince! Your story ends.
@Beyamor
Beyamor / nameGenerator.js
Created June 23, 2013 00:43
Twitter name generator
$(function() {
var adjectives = [],
nouns = [];
var any = function(coll) {
var index = Math.floor(Math.random() * coll.length);
return coll[index];
};
@Beyamor
Beyamor / vtn.hs
Created June 30, 2013 19:30
Verb the Noun generator in Haskell
import Data.Char (toUpper)
import Control.Monad (liftM, mapM_)
import System.Random
readLines :: String -> IO [String]
readLines = liftM lines . readFile
boundaries :: [a] -> (Int, Int)
boundaries xs = (0, length xs - 1)
def is_operator(symbol):
return isinstance(symbol, basestring)
def to_infix(postfix):
stack = []
for symbol in postfix:
if is_operator(symbol):
operand2 = stack.pop()
operand1 = stack.pop()