Skip to content

Instantly share code, notes, and snippets.

View runjak's full-sized avatar
🍧
<- drop it.

Jakob Runge runjak

🍧
<- drop it.
View GitHub Profile
@runjak
runjak / async-stream.ts
Last active May 19, 2023 18:00
An experiment towards async push/pull streams
type AsyncCell<T> = { value: T; next: Promise<AsyncCell<T>> };
type AsyncStreamOutput<T> = () => AsyncGenerator<unknown, T, unknown>;
type AsyncStreamInput<T> = (value: T) => unknown;
const mkPromiseAndInput = <T>(): [Promise<T>, AsyncStreamInput<T>] => {
// streamInput is assigned before return because of Promise implementation
let streamInput!: AsyncStreamInput<T>;
const promise = new Promise<T>((resolve) => {
streamInput = resolve as AsyncStreamInput<T>;
});
@runjak
runjak / chaostikum.js
Last active December 31, 2021 21:15
2021-12-31.fireworks
{
const logo = [
"xxx x x xxx ### ### ### x x x x x x",
"x x x x x # # # # x x x x x xx xx",
"x xxx xxx # # ### # x xx x x x x x",
"x x x x x # # # # x x x x x x x",
"xxx x x x x ### ### # x x x xxx x x",
];
const colors = {
@runjak
runjak / context-test.js
Created November 5, 2021 15:39
Experiments towards a custom context from hell
const sleep = (t) => new Promise(resolve => setTimeout(resolve, t));
// must be function & cannot be strict mode
function withContext(context, next) {
return next();
}
const getContext = () => withContext.arguments[0];
const logContext = (label) => function () {
<?php
function parse($input) {
$formats = array(
'/^\d{1,2}\.\d{1,2}\.\d{4}$/' => 'd.m.Y',
'/^\d{8}$/' => 'dmY'
);
foreach($formats as $pattern => $format) {
if(preg_match($pattern, $input)) {
@runjak
runjak / 2016-09-04.Network.hs
Created December 28, 2019 23:16
A stub for TCP/IP handling that I did with the perspective of doing something with Pixelflut for ~1h back in 2016
module Network(
defaultPort, Connection(..), send, recv, close,
Listening(..), stopListening, serve, connect,
serve', connect'
)where
{-|
This module handles opening/accepting connections on/to an interface/ip,
to send/receive Data.Binary
|-}
import Control.Monad
@runjak
runjak / gql-sourceQuery-split.js
Created August 8, 2018 22:34
GraphQL query split experiment
const split = [
{
directives: [],
kind: "OperationDefinition",
name: {
kind: "Name", value: "t_magic",
},
operation: "query",
selectionSet: {
kind: "SelectionSet",
@runjak
runjak / Main.hs
Created November 12, 2017 13:38
Solve some cube puzzle via backtracking
module Main where
import Control.Monad
import Control.Monad.State as St
import Data.Set (Set)
import qualified Data.Set as S
import GHC.Word (Word8)
import Prelude hiding (Left, Right, last)
data Segment = Edge | Plain deriving (Show, Eq)
@runjak
runjak / Tree.hs
Created February 28, 2017 21:56
Example Haskell code on using pattern matching. Mostly comments. Also a Tree type is defined and stuff is done with it.
module Tree where
{-
This is code for a Haskell module named `Tree`.
You're currently reading a comment block in it.
Below this comment we define a data type called `Tree`.
It has two constructors, named `Leaf` and `Branch`.
The `Leaf` constructor takes one argument, which must be of type `Int`.
@runjak
runjak / printMe.py
Created January 11, 2017 12:53
A short python script to concatenate several .pdf files into one so that they can be printed duplex. Uses gs and pdfinfo.
import subprocess
fileStack = []
with open('./printMe') as f:
files = f.read().split('\n')
for file in files:
if file == '':
continue
fileStack.append(file)
@runjak
runjak / externScreen.sh
Last active May 31, 2016 08:59
Wrapper script for xrandr
#!/usr/bin/bash
intern=eDP1
extern=$(xrandr|grep " connected"|sed "s/ .*//g"|grep -v eDP1)
case $1 in
above)
xrandr --output $intern --auto --output $extern --auto --above $intern
;;
below)
xrandr --output $intern --auto --output $extern --auto --below $intern
;;