Skip to content

Instantly share code, notes, and snippets.

(ns gumball.core)
(defn xy-coords [x-max y-max word-len]
(for [x (range (inc (- x-max word-len)))
y (range (inc (- y-max word-len)))]
(for [n (range word-len)]
[(+ x n) (+ y n)])))
(defn yx-coords [x-max y-max word-len]
(for [x (range word-len x-max)
<?php
class Bomb {
function disarm() {
echo "Disarming...\n";
}
function __call($method, $args) {
echo "Bomb::__call('$method', ...)\n";
}
}
<?php
$a = array();
$vals = [
['"" ', ""],
['0 (int) ', 0],
['0.0 (float) ', 0.0],
['"0" (string) ', "0"],
['FALSE ', false],
['NULL ', null],
(ns dining-philosophers)
(def log-agent (agent 0))
(defn do-log [msg-id message]
(println message)
(inc msg-id))
(defn log [& strs]
(send-off log-agent do-log (apply str strs)))
--------------------------------------------------------------------------------
-- PHP-style serialization in PostgreSQL
-- Making a better situation of someone else's bad decision
-- See examples at bottom
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- Serialization function per type
CREATE OR REPLACE FUNCTION php_serialize(boolean) RETURNS text
@loganlinn
loganlinn / with-channels.cljs
Created May 2, 2014 21:58
WithChannelsMixin
(ns with-channels
(:require
[om.core :as om]
[cljs.core.async :as async]))
(defn get-channels [owner]
(assert (.-state owner) "Component state not found. Are you calling from getInitialState?")
(aget (.-state owner) "__with-channels_channels"))
(defn chan
@loganlinn
loganlinn / core.cljs
Created May 13, 2014 22:08
Test case for omcljs/om#179 (modified examples/unmount/src/core.cljs)
(ns examples.unmount.core
(:require [om.core :as om :include-macros true]
[om.dom :as dom :include-macros true]))
(enable-console-print!)
(def app-state (atom {:widget :a}))
(defn widget-a [data owner]
(reify
@loganlinn
loganlinn / tests.cljs
Created May 15, 2014 16:58
Demonstrates behavior of mult bug
(deftest ops-test
(testing "mult with closed tap"
(go
(let [a (chan 4)
b (chan 4)
src (chan 1)
m (async/mult src)]
(async/tap m a)
(async/tap m b)
@loganlinn
loganlinn / history.cljs
Last active November 19, 2017 20:13
history.cljs
(ns history
"Light wrappers and utils for js/history")
(defn back! [] (.back js/history))
(defn forward! [] (.forward js/history))
(defn go! [idx] (.go js/history idx))
(defn replace-state!
@loganlinn
loganlinn / gist:edd1f79bd94e4c80d1e1
Last active August 29, 2015 14:01
defcomponent ideas
(defmixin async-widget
(will-mount [] ...))
(defcomponent widget [data owner]
(:mixins [async-widget])
(render [_] ... ))
;; constructor calls om/build
(->widget widget-data)
(->widget widget-data widget-opts)