Skip to content

Instantly share code, notes, and snippets.

View camdez's full-sized avatar

Cameron Desautels camdez

View GitHub Profile
(ns zip-file-entries
(:require
[clojure.java.io :as io])
(:import
(java.io BufferedInputStream ByteArrayOutputStream)
(java.util.zip ZipInputStream)))
(defn zip-file-seq [^ZipInputStream zin]
(when-let [entry (.getNextEntry zin)]
(if (.isDirectory entry)
@camdez
camdez / card_game.clj
Last active November 19, 2023 06:40
Example code shape for a functional card game in Clojure
(ns card-game
(:require [clojure.string :as str]))
(def deck
(for [suit ["♣" "♦" "♥" "♠"]
rank ["1" "2" "3" "4" "5" "6" "7" "8" "9" "J" "Q" "K" "A"]]
(str rank suit)))
(defn new-game [player-count hand-size]
{:deck deck
@camdez
camdez / core.clj
Created July 30, 2017 21:09
Experimenting with extending Transit to truncate Doubles and Floats
(ns transit-ex-test.core
(:gen-class)
(:require [cognitect.transit :as transit])
(:import [java.io ByteArrayOutputStream]
[com.cognitect.transit.impl
WriteHandlers
WriteHandlers$DoubleWriteHandler
WriteHandlers$FloatWriteHandler]))
(defn truncate-double [^Double d]
@camdez
camdez / leaderboard.sh
Created August 24, 2016 18:20
Small Business App Showdown Leaderboard
#!/bin/bash
# leaderboard.sh - Small Business App Showdown leaderboard
#
# Author: Cameron Desautels <[email protected]>
# Date: 2016-08-24 13:09:48
DATA_URL='https://intuit.promo.eprize.com/v1/developer/contest/gallery.json?count=1000'
HIGHLIGHT='collbox'
curl $DATA_URL \
(defn table [cols vals]
(->> vals
(partition (count cols))
(map (partial zipmap cols))))
(defn table2 [cols & rest]
(map (partial zipmap cols) rest))
(table
[:this :that :another]
@camdez
camdez / breaktime.el
Last active August 29, 2015 14:28
/u/joeheyming's Emacs break timer (modified)
;;; See: https://www.reddit.com/r/emacs/comments/3icpo7/take_a_break_every_3_hours/
(defvar breaktime-timer nil
"Holds the running break timer (if any).")
(defvar breaktime-interval (* 3 60 60)
"How often to take a break, in seconds.")
(defun breaktime--take-a-break ()
(interactive)
(switch-to-buffer (get-buffer-create "*breaktime*"))
(let ((inhibit-read-only t))
@camdez
camdez / pairs.org
Last active August 29, 2015 14:21
Pairing Sessions

Remote Pairing Sessions

I’m open to pairing programming with anyone on anything. I’m interested in exposure to other people’s coding / problem solving styles, and I’m happy to share what I know. Need another pair of eyes on something? Leave a comment below, or email me at [email protected].

WhenWhoWhatWith
@camdez
camdez / experimental.el
Created May 6, 2015 16:02
Play sound in Emacs when mark is pushed. Interesting for discovering which commands push mark. (If not using OS X, insert appropriate sound file path.)
;; $ ls /System/Library/Sounds/
;; Basso.aiff Bottle.aiff Funk.aiff Hero.aiff Ping.aiff Purr.aiff Submarine.aiff
;; Blow.aiff Frog.aiff Glass.aiff Morse.aiff Pop.aiff Sosumi.aiff Tink.aiff
(defun camdez/push-mark--play-sound (&optional location nomsg activate)
(play-sound-file "/System/Library/Sounds/Pop.aiff" 20))
(advice-add 'push-mark :after #'camdez/push-mark--play-sound)
@camdez
camdez / epigrams-on-programming.md
Last active January 10, 2024 18:35
Alan Perlis' "Epigrams on Programming"

Epigrams on Programming

Alan J. Perlis, Yale University

This text has been published in SIGPLAN Notices Vol. 17, No. 9, September 1982, pages 7 - 13. I'm offering it here online until ACM stops me.

The phenomena surrounding computers are diverse and yield a surprisingly rich base for launching metaphors at individual and group activities. Conversely, classical human endeavors provide an inexhaustible source of metaphor for those of us who are in labor within computation. Such relationships between society and device are not new, but the incredible growth of the computer's influence (both real and implied) lends this symbiotic dependency a vitality like a gangly youth growing out of his clothes within an endless puberty.

The epigrams that follow attempt to capture some of the dimensions of this traffic in imagery that sharpens, focuses, clarifies, enlarges and beclouds our view of this most remarkable of all mans' artifacts, the computer.

@camdez
camdez / experimental.el
Last active August 29, 2015 14:17
Add new Emacs experiment
(defun camdez/add-experiment ()
(interactive)
(find-file camdez/experiments-file)
(goto-char (point-min))
(re-search-forward ";;; Code:")
(insert "\n\n")
(camdez/lisp-insert-hr)
(insert ";; ")
(insert-date-and-time)
(insert "\n\n"))