Skip to content

Instantly share code, notes, and snippets.

@masak
masak / corpus-visualized.txt
Last active December 13, 2015 18:19
My corpus, visualized
$ perl -Mautodie -Mstrict -wE '
my @l;
for (<hvh/*>, <hvm/*>, <mvm/*>) {
open my $IN, "<", $_;
my @lines = <$IN>;
push @l, sprintf "%12s %s", $_, join "", map {
/swaps/ ? "S"
: /resigns/ ? "R"
: /times out/ ? "T"
: "."
@masak
masak / corpus.md
Last active December 12, 2015 10:49
A corpus of littlegolem games

Collected on 2013-02-12 and 2013-02-13.

Hotshots vs hotshots

The ten best players against each other.

  1. Maciej Celuch
  2. Daniel Sepczuk
  3. Naked Face
  4. Frode Lillevold
@masak
masak / problem.txt
Last active December 12, 2015 08:09
swarley's problem
<swarley> Two point charges, q1 and q2 are placed 0.30m apart on the x-axis, as show in the figure above. Charge
q1 has a value of -3e-9 C. The net electric field at point P is zero. Calculate the magnitude and charge
of q2.
<masak> swarley: where's point P?
<swarley> 0.1m left of point q1
Formula:
|E| = 1/(4 pi e0) |q|/r**2
@masak
masak / sieve-decoration.pl
Last active December 11, 2015 22:49
Sieve of Eratosthenes, using roles and decoration
role Filter[Int $factor] {
method next { repeat until $.value % $factor { callsame } }
}
class Stream {
has Int $.value is rw = 1;
method next { ++$.value }
method filter { self but Filter[$.value] }
}
@masak
masak / sieve-lambdas.pl
Created January 29, 2013 23:27
Sieve of Eratosthenes, using only lambdas
$_ = sub ($_) {
state $value = 1;
when 'value' { $value }
when 'next' { ++$value; &?ROUTINE }
when 'filter' {
sub (&substream, $factor) {
sub ($_) {
state $value = 0;
when 'value' { $value }
when 'next' { $value = &substream('next')('value') until $value % $factor; &?ROUTINE }
@masak
masak / sieve.pl
Last active December 11, 2015 22:08
Sieve of Eratosthenes in Perl 6, using streams
class FilteringStream { ... }
role Stream {
method next { ... }
method value { ... }
method filter {
return FilteringStream.new(:factor($.value), :substream(self));
}
}
@masak
masak / datetime-delta.pl
Last active December 11, 2015 15:38
DateTime.delta implementation
use MONKEY_TYPING;
enum TimeUnit <
second seconds minute minutes hour hours
day days week weeks month months year years
>;
augment class DateTime {
method delta($amount, TimeUnit $unit) {
my ($hour, $minute) = $!hour, $!minute;
@masak
masak / sierpinski.pl
Last active December 11, 2015 12:19
Solution to the Sierpinski mini-challenge
sub MAIN($n) {
whole($n, node());
}
my $counter = 0;
sub node(*@parents) {
my $node = "node " ~ ++$counter;
say "Creating $node", @parents && " with parents " ~ @parents.grep(&defined).join(', ');
return $node;
}
@masak
masak / sierpinski.txt
Last active December 11, 2015 12:08
Sierpinski triangles and node creation order
# o
# 1
# |\
# | 2
# |/
# 3
# 1
# |\
@masak
masak / presentation.html
Last active December 11, 2015 03:38
A simple presentation framwork in HTML and jQuery
<!doctype html>
<html lang=en>
<head>
<meta charset=utf-8>
<titleExample presentation</title>
<link href='http://fonts.googleapis.com/css?family=IM+Fell+DW+Pica+SC' rel='stylesheet' type='text/css'>
<style>
body {
font-family: "IM Fell DW Pica SC", arial, serif;
font-size: 500%;