Skip to content

Instantly share code, notes, and snippets.

View thomascothran's full-sized avatar

Thomas thomascothran

View GitHub Profile
@thomascothran
thomascothran / inquest.clj
Last active November 17, 2023 01:24
Inquest
(ns tech.thomascothran.inquest
"A quest for the perf and security benefits of parameterized queries
with the feel of inquery
Usage with deps:
```
{:deps {tech.thomascothran.inquest {:git/url <this-url>
:git/sha <this-sha>}}}
```")
@thomascothran
thomascothran / eog.org
Created May 18, 2022 17:16
Existence of God Class Brainstorms

Atheism

Lay out the standard atheistic perspectives: materialism/atomism, naturalism, empiricism, and moral indignation. Students generally will be Christians, so the purpose is to see the existence of God as a problem.

Relevant readings

  • Hume: Dialogue on Natural Religion
  • Lucretius:
  • Russel Why I am not a Christian
  • Dostoevsky: Ivan’s challenge
@thomascothran
thomascothran / mysql-docker.sh
Created September 4, 2018 21:23 — forked from spalladino/mysql-docker.sh
Backup and restore a mysql database from a running Docker mysql container
# Backup
docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql
# Restore
cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE
@thomascothran
thomascothran / index.html
Created May 29, 2018 17:41 — forked from fcingolani/index.html
How to render a full PDF using Mozilla's pdf.js
<html>
<body>
<!-- really dirty! this is just a test drive ;) -->
<script type="text/javascript" src="https://raw.github.com/mozilla/pdf.js/gh-pages/build/pdf.js"></script>
<script type="text/javascript">
function renderPDF(url, canvasContainer, options) {
var options = options || { scale: 1 };
@thomascothran
thomascothran / coinChange.clj
Created October 25, 2017 00:07
Coin Change Algorithm
; Answer to the challenge at https://www.hackerrank.com/challenges/coin-change
(use '[clojure.string :only (split triml)])
; Put our input into a form we can use
(def input (let [i (line-seq (java.io.BufferedReader. *in*))]
(-> i
(#(clojure.string/join " " %))
(#(split % #" "))
(#(map read-string %)))))
@thomascothran
thomascothran / pascalsTriangle.scm
Created May 2, 2017 22:58
Pascal's Triangle Solution in Scheme Lisp
; Numering rows and indices starting at 1
(define (cell-value row index)
(if (or (= row 1)
(= index 1)
(= index row))
1
(+ (cell-value (- row 1) (- index 1))
(cell-value (- row 1) index))))
@thomascothran
thomascothran / arabify2.js
Last active April 29, 2017 22:18
Roman Numerals to Arabic Numerals with Tail Calls
const nums = {I: 1, V: 5, X: 10, L: 50, C: 100, M: 1000};
const arabify2 = (romNum, sum=0) => {
const [fst, snd, rest] = [romNum[0], romNum[1], romNum.slice(2)];
if (!snd) {return nums[fst] ? nums[fst] + sum : sum;}
else if (nums[snd] > nums[fst]) {
return arabify2(rest, nums[snd] - nums[fst] + sum);
} else {return arabify2(snd + rest, nums[fst] + sum);}
}
@thomascothran
thomascothran / romToArabic_noTailCall.js
Created April 29, 2017 21:38
Roman To Arabic Numerals - W/O Tail Call
const nums = {I: 1, V: 5, X: 10, L: 50, C: 100, M: 1000};
const arabify = (romNum) => {
if (romNum.length === 0) {
return 0;
} else if (nums[romNum[0]] < nums[romNum[1]]) {
return (nums[romNum[1]] - nums[romNum[0]] + arabify(romNum.slice(2)));
} else {
return (nums[romNum[0]] + arabify(romNum.slice(1)));
}
@thomascothran
thomascothran / romNum.js
Created April 29, 2017 20:45
Roman Numeral to Arabic
function deromanize (str) {
var str = str.toUpperCase(),
validator = /^M*(?:D?C{0,3}|C[MD])(?:L?X{0,3}|X[CL])(?:V?I{0,3}|I[XV])$/,
token = /[MDLV]|C[MD]?|X[CL]?|I[XV]?/g,
key = {M:1000,CM:900,D:500,CD:400,C:100,XC:90,L:50,XL:40,X:10,IX:9,V:5,IV:4,I:1},
num = 0, m;
if (!(str && validator.test(str)))
return false;
while (m = token.exec(str))
num += key[m[0]];