Skip to content

Instantly share code, notes, and snippets.

View fogus's full-sized avatar
💭
attempting to learn how to better learn

Fogus fogus

💭
attempting to learn how to better learn
View GitHub Profile
;; Still haven't found a brief + approachable overview of Clojure 1.7's new Transducers
;; in the particular way I would have preferred myself - so here goes:
;;; Transducers recap
;; * (fn reducer-fn [] [accumulation] [accumulation next-input]) -> val [1].
;; * (fn transducer-fn [reducer-fn]) -> new-reducer-fn.
;; * So a transducer-fn is a reducer-fn middleware[2], and composes like it.
;; * All (numerous!) benefits[4] fall out of this simple +
;; not-particularly-impressive-looking[3] definition.
;;
import re
def markdown_to_bbcode(s):
links = {}
codes = []
def gather_link(m):
links[m.group(1)]=m.group(2); return ""
def replace_link(m):
return "[url=%s]%s[/url]" % (links[m.group(2) or m.group(1)], m.group(1))
def gather_code(m):
(ns tumblrsearch.core
(:require-macros [cljs.core.async.macros :refer [go]])
(:require [clojure.browser.repl]
[cljs.core.async :as async :refer [put! chan <!]]
[om.core :as om :include-macros true]
[om.dom :as dom :include-macros true]
[figwheel.client :as fw :include-macros true]
)
(:import [goog.net Jsonp]
[goog Uri]
(ns schema->gen
"Functions for generating test data from schemas."
(:require [four.stateful :as four]
[re-rand :refer [re-rand]]
[schema.core :as sch]
[simple-check.generators :as gen]))
(defn ^:private re-randify-regex
"schema requires ^$ while re-rand forbids them"
[re]
;; Datomic example code
(use '[datomic.api :only (db q) :as d])
;; ?answer binds a scalar
(q '[:find ?answer :in ?answer]
42)
;; of course you can bind more than one of anything
(q '[:find ?last ?first :in ?last ?first]
"Doe" "John")
(import 'clojure.lang.ExceptionInfo)
(defn call-cc [f]
(let [v (promise)
e (ex-info "cc" {:v v})]
(try (f #(do (deliver v %) (throw e)))
(catch ExceptionInfo ex
(if (identical? ex e)
@(:v (ex-data ex))
(throw ex))))))
@fogus
fogus / lenses.md
Created January 24, 2014 19:48 — forked from bigs/lenses.md

Cole Brown

SPJ recently gave a fantastic talk on Edward Kmett's wildly useful lens library. Simon,a brilliant programmer and one of Haskell's designers, had little to no experience with lens prior to this talk and, resultingly, is able to offer a shockingly fresh perspective.

In his talk, he walks the audience through his deconstruction of the library — an illuminating journey. There is a lot of insight exposed, but there was one (perhaps unspoken) sentiment that struck me:

Functional programmers tend to prefer simple, versatile data structures like lists and trees. The reasoning is often times simple: simple data types yield powerful abstractions. One can implement a mind-boggling number of algorithms using maps and folds over lists (and associative lists).

While Haskell caters to this simplified model of programming, Haskell's type system and record syntax also encourage the use of abstract data ty

/**
* so here the thing ... you go in your github page
* as example I go here: https://github.com/WebReflection
* you open your console
* you copy and paste this shit
* then you write and execut in the console
* write("Hi There!");
* NOTE: Pixel Font from a 2006 project of mine :-) http://devpro.it/pixelfont/
*/
function write(text, color) {
My thoughts on writing tiny reusable modules that each do just one
thing. These notes were adapted from an email I recently sent.
***
If some component is reusable enough to be a module then the
maintenance gains are really worth the overhead of making a new
project with separate tests and docs. Splitting out a reusable
component might take 5 or 10 minutes to set up all the package
overhead but it's much easier to test and document a piece that is