Skip to content

Instantly share code, notes, and snippets.

View johannes-riecken's full-sized avatar

Johannes Riecken johannes-riecken

View GitHub Profile
use v5.10;
use warnings;
use Data::Dumper;
my %h;
sub wrap {
my ($str, $re,$replace) = @_;
unless (%h) {
END {say Dumper %h}
@johannes-riecken
johannes-riecken / vectTake.idr
Created February 22, 2018 01:33
vectTake implementation
vectTake : (n : Fin (m)) -> Vect m a -> LTE (cast n) m -> Vect (cast n) a
vectTake FZ (y :: xs) LTEZero = []
vectTake (FS y) (z :: xs) (LTESucc x) = z :: vectTake y xs x
@johannes-riecken
johannes-riecken / Fact.cs
Created October 20, 2018 09:44
Factorial in pure LINQ
private class Wrap<T>
{
public readonly Func<Wrap<T>, T> It;
public Wrap(Func<Wrap<T>, T> it)
{
It = it;
}
}
@johannes-riecken
johannes-riecken / rest-api.go
Created November 26, 2018 21:13
Partial implementation of github trending RESTful API
package main
import (
"encoding/json"
"github.com/gorilla/mux"
"log"
"net/http"
)
type Repository struct {
module Main where
import Prelude
import Control.Comonad
import Control.Lazy
import Data.Array ((:))
import Data.Distributive
import Data.Lens.Grate
import Data.Lens
@johannes-riecken
johannes-riecken / my_random.m
Last active July 11, 2020 14:43
Reproducing random floating point number generation in different languages
rand('state', 0);
rand();
rand();
// Output:
// 0.84442
// 0.75795
@johannes-riecken
johannes-riecken / my_random0.cpp
Last active August 18, 2020 19:12
Reproducing random integer generation in different languages
#include <iostream>
#include <chrono>
#include <random>
#include <iomanip>
int main ()
{
std::mt19937 generator (0);
std::cout << generator() << std::endl;
@johannes-riecken
johannes-riecken / urxvt_op_get_next.pl
Created August 21, 2020 19:46
Emulates bash's Ctrl-O for any console app
my $last_cmd = '';
my $up_cnt;
sub up {
if ($last_cmd ne 'up') {
$up_cnt = 0;
}
`sleep 0.2s;xte 'key Up'`;
$last_cmd = 'up';
$up_cnt++;
@johannes-riecken
johannes-riecken / anagrams.xsl
Last active September 5, 2020 17:56
Anagram finder written in XSLT 1.0
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template name="sort">
<xsl:param name="w"/>
<!-- position in word -->
<xsl:param name="i" select="1"/>
<!-- position in output -->
<xsl:param name="j" select="1"/>
<xsl:param name="out"/>
<xsl:variable name="alpha" select="'01a02b03c04d05e06f07g08h09i10j11k12l13m14n15o16p17q18r19s20t21u22v23w24x25y26z'"/>
@johannes-riecken
johannes-riecken / GoParser.g4
Last active November 11, 2020 08:35
Grammar that runs too slowly when converted to Perl6. See https://github.com/drforr/perl6-ANTLR4/issues/16
grammar GoParser;
sourceFile
: packageClause eos (importDecl eos)* ((functionDecl | methodDecl | declaration) eos)*
;
packageClause
: 'package' IDENTIFIER
;