Skip to content

Instantly share code, notes, and snippets.

View tstout's full-sized avatar

Todd Stout tstout

View GitHub Profile
@tstout
tstout / college.clj
Created September 15, 2023 18:55
[college calc] #clojure
(def cost-year
(+
14000 ; tuition
10000 ; dorm
(* 2 2400) ; meal plan
))
(* 4 cost-year)
@tstout
tstout / clj-install.sh
Created August 23, 2023 00:02
deploy local lib #clojure
clojure -X:deps mvn-install :jar '"project.jar"'
@tstout
tstout / sh-exec.clj
Last active August 21, 2023 23:35
shell exec checking for errors #clojure
(ns an.example
(:require [clojure.java.shell :as shell]
(defn sh-exec [arg-vec]
(let [{:keys [exit err]}
(shell/with-sh-dir (mk-staging-dir)
(apply shell/sh arg-vec))]
(when-not (zero? exit)
(throw (Exception. err)))))
@tstout
tstout / close-socket.sh
Last active September 22, 2020 15:30
close-socket #bash
#!/bin/bash
IFS=$'\n'
for socket in $(lsof -p 361 | grep IPv | grep -v LISTEN)
do
IFS=' ' read -r pname pid host fd _ <<< $socket
echo "close(${fd%?}) for process $pid"
gdb --batch-silent -p $pid --eval-command="call close(${fd%?})"
done
@tstout
tstout / 00_script.clj
Created June 2, 2020 19:25 — forked from ericnormand/00_script.clj
Boilerplate for running Clojure as a shebang script
#!/bin/sh
#_(
#_DEPS is same format as deps.edn. Multiline is okay.
DEPS='
{:deps {clj-time {:mvn/version "0.14.2"}}}
'
#_You can put other options here
OPTS='
@tstout
tstout / inline-tests.clj
Last active May 13, 2020 19:06
inline-tests #clojure
(defn divisble?
"Is `n` divisble by `d`?"
{:test (fn []
(is (divisble? 49 7))
(is (not (divisble? 48 7)))
(is (divisble? 5 0)))}
[n d]
(zero? (try (mod n d)
(catch Exception _ 0))))
@tstout
tstout / FgDataRetrieverTest.groovy
Last active June 9, 2021 21:22
Mocking ResultSet #spock #groovy
package
receipt.service.persistence
import org.springframework.jdbc.core.JdbcTemplate
import spock.lang.Specification
import javax.sql.DataSource
import java.sql.*
import java.time.LocalDate
@tstout
tstout / to-xml.clj
Created February 25, 2020 20:54
convert clojure maps to xml #clojure
;; :require [clojure.data.xml :as xml]
(defn to-xml
"Convert an arbitrary map to xml."
[root-element x]
(xml/emit-str
(xml/element
root-element {}
(map (fn make-node [[f s]]
(cond
@tstout
tstout / clj-Dockerfile
Created February 21, 2020 18:58
Clojure Docker #docker
FROM clojure:tools-deps AS builder
ARG VERSION=0.0.0-0-0000000
ENV TZ=America/Chicago
RUN mkdir -p /home/builder
WORKDIR /home/builder
COPY deps.edn /home/builder
RUN mkdir resources
RUN clojure -Spom
@tstout
tstout / SofmToggleLockStateTest.groovy
Created December 10, 2019 15:26
Mocking DataSource #groovy #spock
package com.containerstore.order.service
import org.joda.time.LocalDate
import org.springframework.jdbc.core.JdbcTemplate
import spock.lang.Specification
import spock.lang.Unroll
import javax.sql.DataSource
import java.sql.Connection
import java.sql.DatabaseMetaData