Skip to content

Instantly share code, notes, and snippets.

@swlkr
swlkr / static-site-generator.clj
Last active August 8, 2021 14:08
A very naive static site generator in clojure
(ns core
(:require [clojure.string :as string]
[markdown.core :as md]
[clojure.java.io :as io]
[clojure.data.xml :as xml]))
(def pattern #"__([\w-]+)__")
(defn replacement [match m]
(let [fallback (first match)
@frankbe
frankbe / egpg.sh
Last active August 18, 2017 13:05
bash script to edit a pgp encrypted file with the default editor
#!/usr/bin/env bash
# edit an pgp(gpg) encryped text file vith the default editor
# (1. decrypt to temp file; 2. edit temp file; 3. encrypt temp file to orgininal file; 4. delete the temp file
ORG_FILE=$1 && test -f "$ORG_FILE" || exit 1
TMP_FILE=$(mktemp)
gpg -d $ORG_FILE>$TMP_FILE && TMP_DATE=$(stat -c %y $TMP_FILE) && $EDITOR $TMP_FILE &&
test "$TMP_DATE" != "$(stat -c %y $TMP_FILE)" && gpg --yes -o $ORG_FILE -c $TMP_FILE
rm $TMP_FILE && echo done;
@xuwei-k
xuwei-k / Macros.scala
Last active September 11, 2019 08:36
compile time regex check and string interpolators
import scala.reflect.macros.Context
import scala.util.matching.Regex
import java.util.regex.PatternSyntaxException
object Macros{
implicit class RegexContext(val c: StringContext) {
def r(): Regex = macro regexImpl
}
@stonegao
stonegao / gist:1044641
Created June 24, 2011 11:59 — forked from leifwickland/gist:1013460
MD5 in scala
object MD5 {
def hash(s: String) = {
val m = java.security.MessageDigest.getInstance("MD5")
val b = s.getBytes("UTF-8")
m.update(b, 0, b.length)
new java.math.BigInteger(1, m.digest()).toString(16)
}
}