Skip to content

Instantly share code, notes, and snippets.

@dopefishh
dopefishh / scc.dcl
Created March 18, 2019 14:14
Tarjan's strongly connected components algorithm implemented in Clean
definition module scc
from StdOverloaded import class <, class ==
from StdClass import class Ord, class Eq
/*
* Find all strongly connected components using tarjan's algorithm
* see: https://en.wikipedia.org/wiki/Tarjan's_strongly_connected_components_algorithm
*
* @param list of nodes together tupled with their successors
@dopefishh
dopefishh / pdflatexi
Created June 21, 2017 12:01
Automatic tlmgr package installation in pdflatex
#!/usr/bin/expect
spawn pdflatex {*}$argv
set latexpid $spawn_id
set oldresult ""
expect -re "^.*File .(.*). not found.*$|^.*language definition file (.*) was not foun" {
set result $expect_out(1,string)
send_user "\nTrying to install missing package\n"
if {$oldresult == $result} {
send_user "$result has been tried twice with no results\n"
send_user "Is this not an image? Aborting...\n"
@dopefishh
dopefishh / resize.bash
Created January 22, 2017 13:33
Bash+convert to resize an image to a desired filesize
#!/bin/bash
set -e
if [[ "$#" -ne 2 ]] || ! [[ -e "$1" ]] ||\
! [[ "$2" =~ ^[0-9]+[eEpPtTgGmMkKbB]?$ ]]; then
echo "Usage: $0 FILE TGT"
echo " TGT is in bytes. Allowed suffixes: bB,kK,mM,gG,tT,pP,eE" >&2
echo " The result will be outputted to stdout. The progress to stderr" >&2
exit
fi
@dopefishh
dopefishh / fastclean
Last active November 1, 2016 17:27
Clean to shell compiler (faster than the standard compiler)
#!/bin/bash
of=a.out
if [ "$#" -ge 3 ] && [ "${@: -2:1}" = "-o" ]; then
of=${@: -1:1}
fi
clm "$@"
tf="$(mktemp -tp. "$(basename $0)XXXXX")"
mv "$of" "$tf"
echo -e "#!/bin/sh\ntail -n +3 \"\$0\" | base64 -d | gunzip" > "$of"
"$tf" -nt | gzip -9 | base64 >> "$of"
@dopefishh
dopefishh / bliep.sh
Last active July 15, 2016 11:34
Crawl bliep telephone data
#!/bin/bash
set -e
# You can find your password by logging in to the webinterface and inspecting the password parameter.
# Alternatively you can dive in the javascript and figure out which hashing technique they use...
# You can create the table by running:
# CREATE TABLE IF NOT EXISTS `data` (
# `amount` int(11) NOT NULL,
# `date` datetime NOT NULL,
# `description` text NOT NULL,
implementation module while
import StdOverloaded, StdInt, StdString, StdBool, StdClass, StdList
import Control.Monad
import Control.Monad.Trans
import Control.Monad.State
import Data.Functor
import Data.Either
@dopefishh
dopefishh / ftitable.py
Last active August 29, 2015 14:14
Frequency table to integer compression
#!/bin/env python
# -*- coding: utf-8 -*-
class ftitable:
"""Class that implements the frequencytable to integer compression data
structure that holds a frequency table in a single integer. It supports
indexing to get a specific frequency and iterating over the keys.
"""
@staticmethod
@dopefishh
dopefishh / kdc.py
Created June 23, 2014 15:31
Kraak de Code solver
#/usr/bin/env python
# -*- coding: utf-8 -*-
import itertools
import re
import time
def check(expr, answer, **kwargs):
for k, v in kwargs.iteritems():
@dopefishh
dopefishh / BinaryClock.java
Created October 31, 2012 17:28
Binary Clock using GPIOLibrary.java
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
public class BinaryClock
{
public static int[] HOURS = {0, 1, 4, 14, 15};
public static int[] MINUTES = {17, 18, 21, 22, 23, 24};
public static GPIOLibrary gpio;
@dopefishh
dopefishh / GPIOLibrary.java
Created October 31, 2012 13:12
Java library for gpio raspberry
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
/**
* Easy to use GPIO library for raspberry pi
*