Skip to content

Instantly share code, notes, and snippets.

/**
* 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 June 28, 2011 09:28
stripbot source
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"
@kaja47
kaja47 / gist:1056244
Created June 30, 2011 13:32
CPS Fibonnacci
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)
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 October 16, 2011 15:26
Boolean function composition
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 November 30, 2011 06:37
linkuj.cz crawler
<?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) {
@kaja47
kaja47 / scrabble.scala
Created December 11, 2011 20:07
Scrabble
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
@kaja47
kaja47 / scrabble.php
Created January 23, 2012 21:40
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 February 13, 2012 09:59
czechiatwitter.com crawler
<?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; }
(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
})