Skip to content

Instantly share code, notes, and snippets.

<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
#fixednode { background-color: red; color: white; }
#item1 { background-color: blue; color: white; }
</style>
<style type="text/x-pbpl">
@Jared314
Jared314 / core.cljs
Created February 18, 2014 07:44
Om with core.async
(ns processtest.core
(:require [cljs.core.async :as async
:refer [<! >! chan put! timeout]]
[om.core :as om :include-macros true]
[om.dom :as dom :include-macros true])
(:require-macros [cljs.core.async.macros :refer [go]]))
(defn cell1 [data owner]
(reify
om/IInitState
@Jared314
Jared314 / core.cljs
Created February 18, 2014 19:11
Om with core.async (1 channel per target)
(ns processtest.core
(:require [cljs.core.async :as async
:refer [<! >! chan put! timeout]]
[om.core :as om :include-macros true]
[om.dom :as dom :include-macros true])
(:require-macros [cljs.core.async.macros :refer [go]]))
(defn cell1 [data owner]
(reify
om/IInitState
@Jared314
Jared314 / core.cljs
Created February 18, 2014 21:05
Om with core.async cleanup
(ns processtest.core
(:require [cljs.core.async :refer [<! >! chan timeout]]
[om.core :as om :include-macros true]
[om.dom :as dom :include-macros true])
(:require-macros [cljs.core.async.macros :refer [go]]))
(defn cell1 [data owner]
(reify
om/IInitState
(init-state [_] {:value 0 :class ""})
@Jared314
Jared314 / gist:1443201
Created December 7, 2011 15:23
Parslet Transform Mod
require 'parslet'
class Parslet::Transform
def transform_elt(elt, context) # :nodoc:
rules.each do |pattern, block|
if bindings=pattern.match(elt, context)
# Produces transformed value
return call_on_match({:node => elt}.merge(bindings), block)
end
end
@Jared314
Jared314 / gist:1918865
Created February 26, 2012 20:36
Z-Type Game Backbone.js Custom Dictionary
//Run this while at the main menu
WORDS={2:[],3:[],4:[],5:[],6:[],7:[],8:[],9:[],10:[],11:[],12:[]};
var w = 'at el id on add cid get has off set url make save sort sync clear clone fetch model parse pluck reset route start unset create escape extend length models remove render router routes setdom tojson changed destroy emulate history isvalid library trigger urlroot defaults delegate getbycid navigate previous validate attributes collection comparator haschanged initialize noconflict setelement undelegate constructor idattribute'
.toLowerCase().split(' ');
for (var i = w.length - 1; i >= 0; i--) { if(w[i].length < 13 && w[i].length > 1) WORDS[w[i].length].push(w[i]); }
@Jared314
Jared314 / gist:1928789
Created February 28, 2012 02:34
Z-Type Game Clojure.Core Custom Dictionary
//Run this while at the main menu
ig.game.registerTarget=function(letter,ent){if(this.targets[letter]===undefined)this.targets[letter]=[];this.targets[letter].push(ent);};
ig.game.unregisterTarget=function(letter,ent){(this.targets[letter]||[]).erase(ent);};
window.removeEventListener('keydown',ig.game.keydown.bind(ig.game));
ig.game.keydown=function (event){if(event.target.type=='text'||event.ctrlKey||event.altKey||this.mode!=ZType.MODE.GAME||this.menu){return true;}var c=event.which;if(c==189)c=45;if(event.shiftKey&&c==191)c=63;if(event.shiftKey&&c==56)c=42;if(event.shiftKey&&c==49)c=33;if(c==187)c=61;if(!((c>64&&c<91)||(c>96&&c<123)||(c==45||c==33||c==63||c==42||c==61))||c==16){return true;} event.stopPropagation();event.preventDefault();var letter=String.fromCharCode(c).toLowerCase();if(!this.currentTarget){var potentialTargets=this.targets[letter];var nearestDistance=-1;var nearestTarget=null;for(var i=0;i<potentialTargets.length;i++){var distance=this.player.distanceTo(potentialTargets[i]);if(distance<n
@Jared314
Jared314 / gist:5028617
Last active December 14, 2015 04:29
Basic CSS3 Selector to Clojure Enlive vector format converter
;[org.jodd/jodd-lagarto "3.4.2"]
;(:import [jodd.csselly CSSelly CssSelector Combinator Selector$Type])
(defn format-attr-selector [x]
(case (.getName x)
"id" (str "#" (.getValue x))
"class" (str "." (.getValue x))
""))
(defn format-selector [x]
@Jared314
Jared314 / get-indent.clj
Last active December 14, 2015 11:28
A get-indent function to get the amount of indention for the next line of clojure code, based on the previous line.
(def closing {\) \(
\} \{
\] \[})
(def opening [\( \{ \[])
(defn zero-or-more [x] (if (>= x 0) x 0))
(defn indent-exception? [[a b]] (not (and (= a \') (= b \())))
; warning: Very basic clojure language parsing. It does not handle strings.
(defn reverse-parse
([data] (reverse-parse data []))
@Jared314
Jared314 / TreeIterator.clj
Last active December 17, 2015 18:49
Storing a parse tree, or AST, in a git repository with Clojure and JGit
(ns gittree.TreeIterator
(:import [org.eclipse.jgit.lib Repository FileMode]
[org.eclipse.jgit.treewalk WorkingTreeIterator WorkingTreeIterator$Entry WorkingTreeOptions]
[java.io ByteArrayInputStream])
(:gen-class :extends org.eclipse.jgit.treewalk.WorkingTreeIterator
:init init2
:post-init postinit
:state state
:constructors {[org.eclipse.jgit.lib.Repository Object] [org.eclipse.jgit.treewalk.WorkingTreeOptions]
[org.eclipse.jgit.lib.Repository Object org.eclipse.jgit.treewalk.WorkingTreeIterator] [org.eclipse.jgit.treewalk.WorkingTreeIterator]}))