Skip to content

Instantly share code, notes, and snippets.

View JustusAdam's full-sized avatar

Justus Adam JustusAdam

View GitHub Profile
@JustusAdam
JustusAdam / WatchSlides.hs
Last active August 29, 2015 14:24
Haskell watcher for compiling markdown to reveljs scripts and tex automatically.
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE UnicodeSyntax #-}
import Control.Concurrent (threadDelay)
import Control.Monad (forever)
import Filesystem
import Filesystem.Path.CurrentOS
import Prelude hiding (FilePath)
import Prelude.Unicode
@JustusAdam
JustusAdam / StyleAll.hs
Created July 21, 2015 07:39
Let stylish-haskell loose on a directory and all its subdirectories.
{-# LANGUAGE UnicodeSyntax #-}
module StyleAll where
import Control.Monad
import Control.Monad.Unicode
import Data.Bool
import Prelude.Unicode
import System.Directory
import System.Environment
#!/usr/bin/env python3
import re
from urllib.request import urlopen
import json
from itertools import chain
linkregex = re.compile(r'(https?://([\w\.-]*)?\.sz-online\.de)(/[\w/-]*\.html)')
import Network.Browser
main =
browse $ do
setAuthorityGen (\_ _ -> return $ Just ("username", "password"))
request $ getRequest "http://github.com"
@JustusAdam
JustusAdam / format_letter.py
Last active August 29, 2015 14:26
What I use to format personalised bulk mails. Works on any text though.
#!/usr/bin/env python3
from string import Template
import sys
import collections
import pathlib
def from_yaml(file):
import yaml
return yaml.load(file)
module Lychrel where
import System.Environment
import Data.Foldable
iterateUntil f v =
maybe
[]
((:) <$> id <*> iterateUntil f)
@JustusAdam
JustusAdam / FilterFile.hs
Last active September 26, 2015 08:31
Added second version
{- read a file, filter out all words in quotes that are at the beginning of a line, and print the resulting words. Using functions from Prelude only -}
main = readFile "input.txt" >>= mapM (putStrLn . (('\"' :) . (++ "\"") . takeWhile (/= '\"') . tail)) . filter ((== '\"') . head) . lines
{- here's another version, that's a bit more hacky in my opinion, but closer to the original (and shorter than the ruby code ;) -}
main=readFile"input.txt">>=mapM(putStrLn.takeWhile(/=' ')).filter((=='\"').head).lines
-- User.signup = function(user) {
-- return new Promise(function(resolve, reject) {
-- User.validate(user).then(function() {
-- return Bcrypt.genSalt(10);
-- }).then(function(salt) {
-- return Bcrypt.hash(user.password, salt, null);
-- }).then(function(saltedHashedPassword) {
-- return User.insertIntoDatabase(user, saltedHashedPassword);
-- }).then(function(userRecord) {
-- resolve(userRecord);
@JustusAdam
JustusAdam / bulk_mail.py
Last active March 1, 2022 12:24
Send a bunch of formatted emails using python templates and YAML/JSON data.
#!/usr/bin/env python3
"""
If you, like me, often have to send a bunch of very similer emails to a bunch of
people you may have got tired of copy pasting and resending as well.
This is my proposed solution:
This script reads a template file, using the simple python templating language
that substitutes vaules like $this with data from a dictionary.
#!/usr/bin/env python3
from subprocess import check_call, CalledProcessError, STDOUT
import os
import json
import io
import sys
APP_DIR = ""