This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; add lein dep: | |
;; [org.bouncycastle/bcpg-jdk15on "1.51"] | |
;; export gpg public & private keys to armored files: | |
;; gpg -ao pub.asc --export XXXXXXXX | |
;; gpg -ao pk.asc --export-secret-keys XXXXXXXX | |
;; usage: | |
;; (encrypt "foo.txt" "foo.gpg" (pub-key "pub.asc")) | |
;; (decrypt "foo.gpg" (io/output-stream "foo.txt") (secret-key "ks-pk.asc") "passphrase") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn ignore-trailing-slash | |
"Modifies the request uri before calling the handler. | |
Removes a single trailing slash from the end of the uri if present. | |
Useful for handling optional trailing slashes until Compojure's route matching syntax supports regex. | |
Adapted from http://stackoverflow.com/questions/8380468/compojure-regex-for-matching-a-trailing-slash" | |
[handler] | |
(fn [{uri :uri :as request}] | |
(handler (assoc request :uri (cond (= "/" uri) uri | |
(.endsWith uri "/") (apply str (butlast uri)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.io.Source | |
// object Main extends App { | |
// hands in form of '5H 5C 6S 7S KD' | |
val ROYAL_FLUSH = "TJQKA" | |
val PROGRESSION = "23456789TJQKA" | |
def rank(hand: String): (Int, String) = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.collection.mutable.BitSet | |
def sieve_of_eratosthenes(max: Int) = { | |
val sieve = BitSet() | |
def index(k: Int): Int = (k - 3) / 2 | |
def validIdx(k: Int): Boolean = k >= 3 && (k % 2) == 1 | |
def is_composite(k: Int): Boolean = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
public class Factors { | |
public static List<Long> primeFactors(long n) { | |
List<Long> result = new ArrayList<Long>(); | |
// for each potential factor i | |
for (long i = 2; i*i <= n; i++) { | |
// if i is a factor of N, repeatedly divide it out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.BitSet; | |
import java.util.List; | |
import java.util.ArrayList; | |
public class Sieve { | |
private BitSet sieve; | |
private Sieve(int size) { | |
sieve = new BitSet((size + 1) / 2); | |
} |