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
View Json.php
/**
* Decodes a JSON string.
* @param string
* @param boolean
* @param integer
* @return mixed
*/
public static function decode($json, $assoc = FALSE, $depth = 512)
{
$json = (string) $json;
@kaja47
kaja47 / build.sbt
Created Jun 28, 2011
stripbot source
View build.sbt
scalaVersion := "2.9.0-1"
libraryDependencies += "commons-codec" % "commons-codec" % "1.4"
libraryDependencies += "oauth.signpost" % "signpost-core" % "1.2.1.1"
libraryDependencies += "org.jdom" % "jdom" % "1.1"
libraryDependencies += "rome" % "rome" % "0.9"
View gist:1056244
def fib[A](n: Int, k: Int => A): A = {
if (n < 2) k(1)
else fib(n-1, (x: Int) =>
fib(n-2, (y: Int) =>
k(x+y)))
}
fib(10, println)
View repl.scala
import java.io.{File, FileWriter}
/*
usage:
=====
:power // switch power mode on
:load repl.scala // load this file
ReplHistory.save // save history
*/
@kaja47
kaja47 / gist:1291030
Created Oct 16, 2011
Boolean function composition
View gist:1291030
trait F[T] extends Function1[T, Boolean] {
def apply(t: T): Boolean
def &&(g: T => Boolean) = (a: T) => apply(a) && g(a)
def ||(g: T => Boolean) = (a: T) => apply(a) || g(a)
def ^ (g: T => Boolean) = (a: T) => apply(a) ^ g(a)
def unary_! = (a: T) => !apply(a)
}
implicit def toF[T](a: T => Boolean) = new F[T] { def apply(x: T) = a(x) }
@kaja47
kaja47 / gist:1408271
Created Nov 30, 2011
linkuj.cz crawler
View gist:1408271
<?php
// for i in $(seq 1 200000); do wget -nv -O "$i.html" "http://linkuj.cz/?id=show&viewnr=4&typ=0&par=$i"; done;
error_reporting(E_ALL);
$fs = glob("*.html");
//$fs = array_slice($fs, 0, 1000);
function xpath($dom, $path) {
View scrabble.scala
val letters = Map(
'a' -> 1, 'é' -> 3, 'k' -> 1, 'r' -> 1, 'ů' -> 4,
'á' -> 2, 'ě' -> 3, 'l' -> 1, 'ř' -> 4, 'v' -> 1,
'b' -> 3, 'f' -> 5, 'm' -> 2, 's' -> 1, 'x' -> 10,
'c' -> 2, 'g' -> 5, 'n' -> 1, 'š' -> 4, 'y' -> 2,
'č' -> 4, 'h' -> 2, 'ň' -> 6, 't' -> 1, 'ý' -> 4,
'd' -> 1, 'i' -> 1, 'o' -> 1, 'ť' -> 7, 'z' -> 2,
'ď' -> 8, 'í' -> 2, 'ó' -> 7, 'u' -> 2, 'ž' -> 4,
'e' -> 1, 'j' -> 2, 'p' -> 1, 'ú' -> 5) withDefaultValue 0
View scrabble.php
<?php
$letters = array(
'a' => 1, 'é' => 3, 'k' => 1, 'r' => 1, 'ů' => 4,
'á' => 2, 'ě' => 3, 'l' => 1, 'ř' => 4, 'v' => 1,
'b' => 3, 'f' => 5, 'm' => 2, 's' => 1, 'x' => 10,
'c' => 2, 'g' => 5, 'n' => 1, 'š' => 4, 'y' => 2,
'č' => 4, 'h' => 2, 'ň' => 6, 't' => 1, 'ý' => 4,
'd' => 1, 'i' => 1, 'o' => 1, 'ť' => 7, 'z' => 2,
'ď' => 8, 'í' => 2, 'ó' => 7, 'u' => 2, 'ž' => 4,
@kaja47
kaja47 / czechiatwitter.php
Created Feb 13, 2012
czechiatwitter.com crawler
View czechiatwitter.php
<?php
$users = array();
foreach (range(1, 897) as $page) {
$dom = new DOMDocument();
@$dom->loadHtmlFile("http://www.czechiatwitter.com/?page=$page");
$xpath = new DOMXPath($dom);
$res = $xpath->query('//strong/a');
foreach ($res as $r) { $users[] = $r->nodeValue; }
View scrabble.clojure
(def letters {
\a 1 \é 3 \k 1 \r 1 \ů 4
\á 2 \ě 3 \l 1 \ř 4 \v 1
\b 3 \f 5 \m 2 \s 1 \x 10
\c 2 \g 5 \n 1 \š 4 \y 2
\č 4 \h 2 \ň 6 \t 1 \ý 4
\d 1 \i 1 \o 1 \ť 7 \z 2
\ď 8 \í 2 \ó 7 \u 2 \ž 4
\e 1 \j 2 \p 1 \ú 5
})
You can’t perform that action at this time.