Skip to content

Instantly share code, notes, and snippets.

(ns drag.core
(:use [jayq.core :only [$ bind]]
[cljs.core.async :only [chan put! <!]])
(:require-macros [cljs.core.async.macros :refer [go]]))
(defn create-canvas
[& {:keys [width height]}]
(let [canvas ($ "<canvas>")
context (-> canvas (aget 0) (.getContext "2d"))]
(doto canvas
#include <iostream>
template<class T, size_t N>
struct Vector { };
template<class T>
struct Vector <T,1>
{
union {
T e[1];
import os, sys
markdown_name = sys.argv[1]
name = markdown_name.split(".")[0]
latex_name = name + ".tex"
os.system("pandoc -f markdown -t latex %s -o %s" % (markdown_name, latex_name))
with open(latex_name, "r") as latex_file:
latex_content = latex_file.read()
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()
@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)
@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 / 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 / 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 / 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,
(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)