Skip to content

Instantly share code, notes, and snippets.

View halgari's full-sized avatar

Timothy Baldridge halgari

View GitHub Profile
class Delay(object):
def __init__(self, f):
self._f = f
self._evaled = False
self._val = None
def deref(self):
if self._evaled == False:
self._val = f()
self._f = None
# Simplistic explination of Transducers:
# Map can be defined thusly:
def map(f, coll):
result = []
for v in coll:
append(result, f(v))
return result
def swap(ref, f, *args):
with atomic:
ref.val = f(ref.val, *args)
@halgari
halgari / gist:78d44aabc6adc3b6ff56
Created April 14, 2015 21:31
impementation of when with fexprs
(defexpr $when [test & body]
(if (eval test)
(eval (cons 'do body))
nil))
;; Common Protocol
(defprotocol IMutatingEntity
(eset! [this v e]))
;; Single entity object, tp is purely for debugging
(deftype Entity [tp mappings uuid state persister-fn]
ILookup
(-val-at [this k] (dget uuid state (k mappings)))
IMutatingEntity
(reduce
(fn [_ i]
(when (key-matches? i :_yx_rk)
(reduced i)))
nil
(:fields coll))
(try (apply evt-fn state args)
(catch :default ex
(console/error "Component CSP Exception: " ex " when processing " evt-fn " with " args)))))
[translation:info] Error:
[translation:info] File "/Users/tim/oss-not-dropbox/pixie/externals/pypy/rpython/translator/goal/translate.py", line 318, in main
[translation:info] drv.proceed(goals)
[translation:info] File "/Users/tim/oss-not-dropbox/pixie/externals/pypy/rpython/translator/driver.py", line 551, in proceed
[translation:info] return self._execute(goals, task_skip = self._maybe_skip())
[translation:info] File "/Users/tim/oss-not-dropbox/pixie/externals/pypy/rpython/translator/tool/taskengine.py", line 114, in _execute
[translation:info] res = self._do(goal, taskcallable, *args, **kwds)
[translation:info] File "/Users/tim/oss-not-dropbox/pixie/externals/pypy/rpython/translator/driver.py", line 279, in _do
[translation:info] res = func()
[translation:info] File "/Users/tim/oss-not-dropbox/pixie/externals/pypy/rpython/translator/driver.py", line 385, in task_backendopt_lltype
(defn search-log [log term]
(with-open [rdr (java.io.BufferedReader.
(java.io.FileReader. log ))]
(filter #(not (= -1 (.indexOf % term))
(line-seq rdr))))
@halgari
halgari / gist:3181861
Created July 26, 2012 12:54
example image downloader with global scope
public static class ImageDownloader
{
public static string Server = "http://foo.bar.com/images";
public static GetImage(string id)
{
return DownloadURL(url + "/" + id);
}
}