Skip to content

Instantly share code, notes, and snippets.

K. kaja47

Block or report user

Report or block kaja47

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@kaja47
kaja47 / rachel-riley.scala
Last active Aug 29, 2015
Contdown's number game solver for all freaks who like me watched too much British panel shows.
View rachel-riley.scala
sealed trait Tree {
def eval: Option[Int]
}
case class Leaf(n: Int) extends Tree {
override def toString = n.toString
def eval = Some(n)
}
case class Node(op: String, l: Tree, r: Tree) extends Tree {
@kaja47
kaja47 / gist:482a80a4054bb4572cc5
Last active Aug 29, 2015
scala vs. swift (round 1)
View gist:482a80a4054bb4572cc5
let yetAnotherPoint = (1, -1)
switch yetAnotherPoint {
case let (x, y) where x == y:
println("(\(x), \(y)) is on the line x == y")
case let (x, y) where x == -y:
println("(\(x), \(y)) is on the line x == -y")
case let (x, y):
println("(\(x), \(y)) is just some arbitrary point")
}
@kaja47
kaja47 / matcher-obvious.php
Last active Aug 29, 2015
Matcher examples
View matcher-obvious.php
<?php
$m = Matcher::multi('//table[@id="egmFixtureList"]/tr[@class]', [
'datum' => 'td[@colspan]',
'spielnr' => 'td[1]',
'anpfiff' => 'td[2]',
'team1' => 'td[3]/a/text()',
'team2' => 'td[5]/a/text()',
'spielbericht' => 'td[7]/a/@href',
])->fromHtml()->map(function ($rows) {
@kaja47
kaja47 / branch-test.c
Last active Aug 29, 2015
branch prediction test
View branch-test.c
#include <stdio.h>
#include <stdlib.h>
#include <immintrin.h>
// gcc -std=c99 -D IS_RAND=0 branch-test.c ; for i in -1 -2 1 3 2 4 8 16; do echo '### ' $i; perf stat -r5 -o _stats_pred_base --append ./a.out $i; echo; done
// gcc -O3 -std=c99 -D IS_RAND=0 branch-test.c ; for i in -1 -2 1 3 2 4 8 16; do echo '### ' $i; perf stat -r5 -o _stats_pred_o3 --append ./a.out $i; echo; done
// gcc -std=c99 -D IS_RAND=1 branch-test.c ; for i in 8 16 32 64 128 256; do echo '### ' $i; perf stat -r5 -o _stats_rand_base --append ./a.out $i; echo; done
// gcc -O3 -std=c99 -D IS_RAND=1 branch-test.c ; for i in 8 16 32 64 128 256; do echo '### ' $i; perf stat -r5 -o _stats_rand_o3 --append ./a.out $i; echo; done
View gist:be5cfe0f261146de3960
./ext/date/lib/parse_date.c:10272
./Zend/zend_language_scanner.c:1533
./Zend/zend_ini_scanner.c:1350
./ext/sqlite3/libsqlite/sqlite3.c:636
./sapi/phpdbg/phpdbg_lexer.c:373
./ext/date/lib/parse_iso_intervals.c:250
./ext/standard/var_unserializer.c:189
./ext/mbstring/oniguruma/regexec.c:157
./ext/pcre/pcrelib/pcre_compile.c:119
./ext/standard/url_scanner_ex.c:100
View runize.scala
val runes = "ᚨᛒᚳᛞᛖᚠᚷᚺᛁᛃᚲᛚᛗᚾᛟᛈᛩᚱᛋᛏᚣᚢᚹᛤᛣᛉ"
def runize(str: String) = str.toLowerCase map (l => if (runes.isDefinedAt(l-'a')) runes(l-'a') else ' ')
@kaja47
kaja47 / gist:bddc1403d6a182264029
Created Jan 2, 2015
little matcher css selector example
View gist:bddc1403d6a182264029
<?php
Matcher::multi('div.article', [
'title' => 'h2'
'date' => 'span.date'
])->fromHtml(new CssMatcherContext)
View gist:8951883af057590bc28b
try {
throw new Exception("E2")
} catch {
case ex: Exception if ex.getMessage == "E1" =>
println("caught E1")
case ex: Exception if ex.getMessage == "E2" =>
println("caught E2")
}
View gist:fd426c8c21ddb07bb617
$size = 512*1024;
$keys = range(1, $size);
//shuffle($keys);
$arr = [];
foreach ($keys as $k) {
$arr[$k] = $k;
}
$s = microtime(1);
View sepukku.scala
val boardStr = """
53 7 |
6 195 |
98 6 |
8 6 3|
4 8 3 1|
7 2 6|
6 28 |
419 5|
8 79|
You can’t perform that action at this time.