Serve files in the current directory over HTTP:
python -m SimpleHTTPServer 8000
Start a simple SMTP server that prints messages to stdout
:
python -m smtpd -n -c DebuggingServer localhost:25
Serve files in the current directory over HTTP:
python -m SimpleHTTPServer 8000
Start a simple SMTP server that prints messages to stdout
:
python -m smtpd -n -c DebuggingServer localhost:25
@RunWith(JUnit4.class) | |
public class TerminalViewTest extends TicTacToeTest { | |
private final PrintStream stdout = System.out; | |
private final ByteArrayOutputStream output = new ByteArrayOutputStream(); | |
private TerminalView terminalview; | |
@Before | |
public void setUp() throws UnsupportedEncodingException { | |
terminalview = new TerminalView(); |
(ns keylistener.core | |
(:require [clojure.java.io :as io]) | |
(:import [jline.console ConsoleReader]) | |
(:gen-class)) | |
(def console (ConsoleReader.)) | |
(defn keypress-loop [] | |
(let [char (.readCharacter console)] | |
(if (not (nil? char)) |
;; Figure 6.2 – Representation and definition of nodes | |
(def nodes (atom {})) | |
(defn defnode [name contents & [yes no]] | |
(swap! nodes assoc name {:contents contents :yes yes :no no})) | |
;; Figure 6.3 – Sample network | |
(defn make-nodes [node-maker] | |
(node-maker :people "Is the person a man?" :male :female) | |
(node-maker :male "Is he living?" :live :dead) |
(require '[cascalog.io :refer [with-log-level]) | |
(defmacro ?<-- [& forms] `(with-log-level :fatal (?<- ~@forms))) |
#lang racket/base | |
(require rackunit) | |
(define simple-q '((1 2 3) (6 5 4))) | |
(define empty-queue '(()())) | |
(check-equal? empty-queue '(() ()) | |
"An empty queue is a list containing two empty lists.") |
My solution to Chris Okasaki's functional pearl: given a tree, reproduce a tree with the same structure with nodes numbered in breadth-first order (using only immutable data structures, of course).
For more on streams and lazy lists, check out chapter 3 of SICP. For more on pure functional queues, see this other paper by Chris Okasaki.
I'm not completely happy with my solution. On the plus side, it generalizes to non-binary trees. But performing a breadth-first search to calculate node numbers and a depth-first map to apply them is inefficient. I tried to construct my solution from the
(describe "Converting hex to base64" | |
(it "parses hex values from two-character strings" | |
(should= 0x2f (parse-hex "2f"))) | |
(it "splits hex strings to sequences of strings" | |
(should= ["00" "1a" "2b" "88"] | |
(split-hex-string "001a2b88"))) | |
(it "converts hex strings into sequences of hex values" |
(ns crypto-challenges.core | |
(:require [clojure.edn :refer [read-string]] | |
[clojure.string :refer [lower-case]])) | |
(def alphabet "ABCDEFGHIJKLMNOPQRSTUVWXYZ") | |
(def base64-values (str alphabet | |
(lower-case alphabet) | |
"0123456789+/")) |