Skip to content

Instantly share code, notes, and snippets.

View christianromney's full-sized avatar
🏠
Working from home

Christian Romney christianromney

🏠
Working from home
View GitHub Profile
@christianromney
christianromney / abstraction.clj
Last active August 29, 2015 13:55
An example of how to define abstractions in Clojure
;; BinOp ::= [Symbol Operand Operand]
;; Operand ::= Number | BinaryOperation
(defprotocol Numerical
"A thing which has a numerical value"
(value [this]))
(defprotocol PrintableMathExpression
"A mathematical expression which can be printed
using infix or prefix notation"
(defn filter-col [a]
(filter (juxt #(< 30 %) odd?) a))
(defn report-results [col]
(println col)
col)
(-> (range 100)
filter-col
report-results)
@christianromney
christianromney / sum.rkt
Created December 24, 2013 18:39
Accompany mex.pdf
#lang racket
;; Non-tail
(define sum1
(λ (n)
(if (= n 0) n
(+ n (sum1 (- n 1))))))
(sum1 10)
/*
Hi, I'm Reservation.
I dont need an interface because I am a carrier of data.
Like a good carrier, I can be instantiated in any layer and used
in any other layer.
If you need to do stuff with me you should know to instantiate the correct
service and pass me to it.
Makes sense too since I you might need other classes to instantiate service
@christianromney
christianromney / core.clj
Last active December 20, 2015 01:09
Without comments to test Adrian
(ns async.core
(:require [clojure.core.async :as async :refer :all]
[clojure.data.generators :as gen])
(:gen-class))
(defrecord SyncMessage [text wake])
(defmacro forever [& body]
`(while true
~@body))
(ns async.core
(:require [clojure.core.async :as async :refer :all]
[clojure.core.async.lab :as lab]
[clojure.data.generators :as gen])
(:gen-class))
;; A Message carries some text to be communicated
;; and a wake channel which notifies the originator
;; that it may transmit again.
(defrecord Message [text wake])
(ns circuito.core
(:require [clojure.core.async :as async :refer :all])
(:gen-class))
(def ^:dynamic *timeout* 300)
;; Like defn, but executes body in a go block, allowing at most *timeout* milliseconds for completion
(defmacro defcommand [name args & body]
`(defn ~name ~args
(let [t# (timeout *timeout*)
NameVirtualHost *:80
<Directory "/Users/christian/src/work/ncl/drupal">
AllowOverride all
Order allow,deny
Allow from all
</Directory>
<Location /balancer-manager>
SetHandler balancer-manager
(ns async.core
(:require [clojure.core.async :as async :refer :all])
(:gen-class))
;; Based on http://talks.golang.org/2012/concurrency.slide#30
;;
;; The Go semantics don't quite translate the same way to core.async
;; I've swapped the talk and wait channels so that each "boring"
;; goroutine creates its own _private_ wait channel / semaphore.
;;

Emacs Cheatsheet

C-c C-s +show source code for function C-c C-d +show documentation for function C-c C-j +show Javadoc for symbol at point

C-c C-k +compile Clojure file C-c M-n +change nrepl namespace to current C-c M-o +clear nrepl C-x C-e +send sexp to nrepl