Skip to content

Instantly share code, notes, and snippets.

View JustusAdam's full-sized avatar

Justus Adam JustusAdam

View GitHub Profile
@JustusAdam
JustusAdam / StripDirPrefixes.hs
Last active April 13, 2017 11:18
Renames all direcories in the working directory by stripping a prefix. Leaves those who dont match the prefix unchanged.
-- Renames all direcories in the working directory by stripping a prefix
-- Leaves those who dont match the prefix unchanged.
import System.Directory
import Data.List
import System.Environment
import Control.Monad.Extra
main = getArgs >>= \[prefix] ->
listDirectory "." >>= filterM doesDirectoryExist >>= mapM_ (maybe (return()) (renameDirectory <$> (prefix++) <*> id) . stripPrefix prefix)
<html>
<head>
<script src="main.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
function reset_geschlecht () {
var frau_input = document.getElementById("frau-input");
var mann_input = document.getElementById("mann-input");
frau_input.labels[0].style.color = "black";
mann_input.labels[0].style.color = "black";
@JustusAdam
JustusAdam / imgsort.py
Last active October 19, 2015 08:26
Sort images into directories by date taken/modified
#!/usr/bin/env python3
import pathlib
import sys
import exifread
from datetime import datetime
from itertools import count
image_exts = [
".jpg",
#!/usr/bin/env python3
from subprocess import check_call, CalledProcessError, STDOUT
import os
import json
import io
import sys
APP_DIR = ""
@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.
-- 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 / 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
module Lychrel where
import System.Environment
import Data.Foldable
iterateUntil f v =
maybe
[]
((:) <$> id <*> iterateUntil f)
@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)
import Network.Browser
main =
browse $ do
setAuthorityGen (\_ _ -> return $ Just ("username", "password"))
request $ getRequest "http://github.com"