This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"image" | |
"image/color" | |
"os" | |
"math" | |
"path/filepath" | |
_ "image/gif" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Arrays | |
// Three-way radix quicksort aka Multi-key quicksort | |
// | |
// Fast Algorithms for Sorting and Searching Strings | |
// http://www.cs.princeton.edu/~rs/strings/paper.pdf | |
object RadixQuicksort { | |
def sort(arr: Array[String]) = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object XMLSW { | |
private val f = XMLOutputFactory.newInstance | |
def document(encoding: String = "utf-8", version: String = "1.0")(body: XMLSW => Unit) = { | |
val out = new StringWriter() | |
val w = f.createXMLStreamWriter(out) | |
val ww = new XMLSW(w) | |
ww.document(encoding, version)(body) | |
w.flush() | |
w.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.util.matching.Regex | |
import java.util.regex.Matcher | |
def replaceAllByString(r: Regex, s: String, f: Matcher => String) = { | |
val m = r.pattern.matcher(s) | |
m.reset() | |
var lastAppendPos = 0 | |
var result = m.find() | |
if (result) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def parseLine(l: String) = { | |
def march(l: String, pos: Int, ch: Char): Int = { | |
var i = pos; while (i < l.length) { | |
if (l.charAt(i) == ch) return i | |
i += 1 | |
} | |
sys.error("") | |
} | |
def marchUntilStringEnds(l: String, pos: Int): Int = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use React\Promise\Deferred; | |
function timeout($time, $promise, $loop) { | |
$defer = new Deferred; | |
$r = $defer->resolver(); | |
$sig = $loop->addTimer($time, function() use($r) { | |
$r->reject('timeout'); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val matchAll = new Regex(".*") | |
matchAll.replaceAllIn("I have no money", m => m.matched) | |
// I have no money | |
matchAll.replaceAllIn("I have $0", m => m.matched) | |
// I have I have $0 | |
matchAll.replaceAllIn("I have $1", m => m.matched) | |
// java.lang.IndexOutOfBoundsException: No group 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import std.range; | |
import std.parallelism; | |
import core.atomic; | |
import gcc.builtins; | |
T[] parallelRadixsort(T)(T[] arr, T[] tmparr) { | |
assert(arr.length == tmparr.length, "lengths"); | |
alias Histo = int[256]; | |
alias Histo4 = int[256][T.sizeof]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
T[] radixsort(T)(T[] arr, T[] tmparr) { | |
assert(arr.length == tmparr.length); | |
int[256][T.sizeof] counts; | |
foreach (v; arr) { | |
foreach (b; 0 .. T.sizeof) { | |
uint c = (v >> (b * 8)) & 0xff; | |
counts[b][c] += 1; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// really really fast loop (0.008s) | |
$arr = range(1, pow(2, 24)+1); | |
for ($i = 1; $i < 200000; $i++) { | |
unset($arr[$i]); | |
$arr[] = 1; | |
} |
NewerOlder