Skip to content

Instantly share code, notes, and snippets.

@mmzsource
mmzsource / core.clj
Last active Dec 29, 2020
coding dojo - maze solving
View core.clj
#!/usr/bin/env bb
;; To run this file:
;;
;; * Install Babashka: https://github.com/borkdude/babashka
;; (for mac users: `brew install borkdude/brew/babashka`)
;;
;; * If needed make sure babashka `bb` is on your PATH
;; (so the hash-bang at the start of this file will work)
;;
@mmzsource
mmzsource / cljs-quil-emacs-figwheel-setup.md
Last active Sep 13, 2020
Setup dynamic Clojurescript and Quil environment with emacs and figwheel
View cljs-quil-emacs-figwheel-setup.md

My environment

  • emacs 26.3
  • cider 0.25.0
  • leiningen 2.9.4 on Java 11.0.2
  • ~/.lein/profiles.clj : {:user {:plugins []}}

Project setup

In a terminal, run these commands:

View maze-generation
(require '[clojure.string :as s])
(declare print-maze)
;; Maze GENERATION
(defn create-grid [rows cols]
(vec (repeat rows (vec (repeat cols #{})))))
(defn north-of [[row col]] [(dec row) col])
(defn south-of [[row col]] [(inc row) col])
View diskusage
#!/bin/bash
#
# This is a script to log (and eventually monitor) diskusage on a filesystem.
# It will write the disk usage to a logfile.
# The logfile will never grow larger than MAX_LINES number of lines.
#
# The script is 'gnu awk' specific. GNU AWK is available on mac (brew)
# and ubuntu (apt-get) as the package 'gawk'.
#
@mmzsource
mmzsource / bezier-in-clojure.clj
Last active Jun 30, 2017
Code belonging to and explained in my "Bézier in Clojure" blog
View bezier-in-clojure.clj
;;
;; Assume leiningen + lein-try plugin installed and working
;;
;; Fire up a repl with:
;;
;; lein try incanter "1.5.7"
;;
(require '[incanter.core :as incanter])
(require '[incanter.charts :as charts])
@mmzsource
mmzsource / soccer-bets-spec-test.clj
Last active Apr 20, 2017
Trying clojure.spec to check, document & generate a league-table datastructure
View soccer-bets-spec-test.clj
;; REPL session to play around with clojure.spec
;; ------------- START INITIAL SETUP -------------
;; assume these dependencies are specified in the repl environment:
;; [org.clojure/clojure "1.9.0-alpha15"]
;; [org.clojure/test.check "0.9.0"]
;; My leiningen setup:
;; cat ~/.lein/profiles.clj
@mmzsource
mmzsource / CalculateDurationInWeeks.clj
Last active Feb 18, 2017
Clojure Boot repl session - Calculate number of weeks between 2 dates
View CalculateDurationInWeeks.clj
boot repl
(set-env! :dependencies '[[clojure.java-time "0.2.2"]])
(require '[java-time :as t])
(t/time-between (t/local-date 2014 9 27) (t/local-date 2017 2 18) :weeks)
@mmzsource
mmzsource / gist:84e3ad3e854420148348d71507fd6512
Last active Feb 6, 2017
League Tables with clojure boot
View gist:84e3ad3e854420148348d71507fd6512
#!/usr/bin/env boot
(set-env! :dependencies '[[clj-http "2.3.0"] [cheshire "5.7.0"]])
(require '[clj-http.client :as client])
(require '[clojure.pprint :as pp])
;; Fifa country codes - https://en.wikipedia.org/wiki/List_of_FIFA_country_codes
(def countries [
{:id 426 :key :ENG :description "England"}
{:id 436 :key :ESP :description "Spain"}
View gist:f58c77e8fc813a82f21fd32335210732
;; Running this script in bash:
curl -s http://api.football-data.org/v1/competitions/436/leagueTable | jq '.' | tr -d , | grep teamName | awk -F":" 'BEGIN {print "{\n"} {print NR, $2} END {print "\n}"}'
;; Results in a clojure map:
{
1 "Real Madrid CF"
2 "FC Barcelona"
3 "Sevilla FC"
You can’t perform that action at this time.