Skip to content

Instantly share code, notes, and snippets.

View pbpl_example.html
<!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 Feb 18, 2014
Om with core.async cleanup
View core.cljs
(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 / core.cljs
Created Feb 18, 2014
Om with core.async
View core.cljs
(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 Feb 18, 2014
Om with core.async (1 channel per target)
View core.cljs
(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 / gist:1443201
Created Dec 7, 2011
Parslet Transform Mod
View gist:1443201
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 Feb 26, 2012
Z-Type Game Backbone.js Custom Dictionary
View gist:1918865
//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 Feb 28, 2012
Z-Type Game Clojure.Core Custom Dictionary
View gist:1928789
//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 Dec 14, 2015
Basic CSS3 Selector to Clojure Enlive vector format converter
View gist:5028617
;[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 Dec 14, 2015
A get-indent function to get the amount of indention for the next line of clojure code, based on the previous line.
View get-indent.clj
(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 Dec 17, 2015
Storing a parse tree, or AST, in a git repository with Clojure and JGit
View TreeIterator.clj
(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]}))