Skip to content

Instantly share code, notes, and snippets.

View felher's full-sized avatar

felher felher

  • Olyro GmbH
View GitHub Profile
@felher
felher / cancel-after-a-works.txt
Created March 17, 2019 21:49
bracket and cancel
starting A
^Cstarting B
stopping B
stopping A

The Mysterious Case of The Missing flatMap

When you're starting to use functional programming libraries in scala there is something which might not feel right to you. But you suppress that feeling because everything seems to work just a fine. You try to move on, but a question is racing through your head. I'm talking of course about:

Why the hell can I call flatMap and map on my data types, even though it isn't implemented on my data types?

Consider a small example. We will write our own mirror of the Option data type. The original Option has two cases, Some(a) if there is a value and None if there is none. Let's call our data type Maybe which the cases Just(a) and Empty.

sealed trait Maybe[+A]
@felher
felher / problem.txt
Last active March 16, 2016 20:04
Keeping long lived branches with only a few commits
I keep some of my config files in a git repository.
I have multiple machines and on some machines I have to
change some parts of the config file, while keeping the
other parts unchangend and up to date.
I created branches for the different machines and merged
the main branch back into the machine branches, which
makes it look like that:
Maschine1: o-o-o-o-o...
/ / / / /
Master: o-o-o-o-o-...
@felher
felher / Main.pm
Last active December 20, 2015 22:39
I have a Perl6-Project with ah file 'main.pl' and a subdirectory 'lib/' containing the file 'Main.pm'. The contents of the files are shown below. If I run 'nom main.pl' within that project, I get the correct output shown in 'output_when_not_compiled_to_pir.txt'. If I do 'nom --output=lib/Main.pir --target=pir lib/Main.pm' before running 'nom mai…
use v6;
constant %ah = (^10).categorize: *%3;
say %ah.perl;
@felher
felher / gist:5373428
Last active December 16, 2015 03:59
What do you think about this layout? It's pretty useless for big grammars or grammars with more complex layout of course, but it might be good for some small grammars like this. One immediately sees the hierarchical layout. I'm not sure I like the layout myself.
grammar Rules {
token TOP { <line>* }
token line { <empty-line> | <field-specification-line> | <tag-line> }
token empty-line { [ '#' \V* ]? \v }
token field-specification-line { '!' <field-name> \v }
token field-name { 'to' | 'from' | 'subject' }
token tag-line { <tag-command> \h+ <conjunction>+ % [\h* '|' \h*] \v }
token tag-command { <sign> <tag-name> }
token sign { ['+' | '-'] }
token tag-name { <alnum>+ }
@felher
felher / gist:4365641
Last active December 10, 2015 02:09 — forked from anonymous/gist:4358598
X und Y sind zwei verschiedene ganzzahlen, groesser als 1, deren Summe kleiner 100 ist. S und P sind zwei matehmatiker;
S kennt sie Summe X+Y, P kennt das Produkt X*Y, und beide kennen die Informationen in diesen Saetzen.
Dann passiert die folgende Unterhaltung:
P sagt "Ich kann die Zahlen nicht finden."
S sagt "Ich war mir sicher, dass du die Zahlen nicht finden konntest. Ich kann sie auch nicht finden."
P sagt "Dann habe ich diese Zahlen gefunden."
S sagt "Wenn du sie gefunden hast, dann hab ich sie auch gefunden."
Um welche zwei Zahlen handelt es sich?
@felher
felher / haskell.hs
Last active December 10, 2015 01:58
puzzle
type MT = (Int, Int)
allTuples :: [MT]
allTuples = [ (x, y) | x <- [2 .. 97], y <- [2 .. 97], x >= y, x + y < 100]
isPrime :: Int -> Bool
isPrime x = null [d | d <- [2 .. x - 1], x `rem` d == 0]
primeTuples :: [MT]
primeTuples = filter isPrimeTuple allTuples where
# we use the [] reduction meta operator along with the Cartesian Product
# operator X to create the Cartesian Product of four times [1..9] and then get
# all the elements where the number of unique digits is four.
my @candidates = ([X] [1..9] xx 4).tree.grep: *.uniq == 4;
repeat {
my $guess = @candidates.pick;
my ($bulls, $cows) = read-score;
@candidates .= grep: &score-correct;
@felher
felher / multi_sub_problem
Created August 10, 2012 14:44
multi sub problem
multi sub a(Int $x) { ... };
multi sub a('list', *@array) { ... };
&a.candidates_matching();
@felher
felher / Temporal.patch
Created August 2, 2012 21:20
Patch for Date. Otherwise Date.new(year => 2012) fails because $month/$day are of type Any by default and therefore not compatible with their Int-typed instance variables and because they'd be uninitialized
From 6beffa8d2f4b18fcabd0c83a93310bc70a122ea3 Mon Sep 17 00:00:00 2001
From: Felix Herrmann <felix@herrmann-koenigsberg.de>
Date: Thu, 2 Aug 2012 20:07:03 +0200
Subject: [PATCH] [Temporal] change constructor of Date to use default values
for year/month/day
---
src/core/Temporal.pm | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)