This file contains hidden or 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
class FixedSizeQueue[A](limit: Int) extends scala.collection.mutable.Queue[A] { | |
override def +=(elem: A) = { | |
super.+=(elem) | |
while (size > limit) { dequeue } | |
this |
This file contains hidden or 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
scala> import maze._ | |
import maze._ | |
scala> val m = Mazes.load(new java.io.File("maze.txt")) | |
m: maze.Maze = maze.Maze@20ccb51 | |
scala> Mazes.encodeRunLength(m.solve.get) | |
res0: List[(maze.Direction.Value, Int)] = List((S,1), (E,10), (S,2), (W,31), (N,4), (E,2), (S,2), (E,2), (N,4), (E,7), (N,1)) |
This file contains hidden or 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
// modified from http://d.hatena.ne.jp/alpha_neet/20110706/1309901375 | |
import processing.core._ | |
import processing.core.PConstants._ | |
trait Application extends PApplet { | |
def main(args: Array[String]) { | |
PApplet.runSketch(Array("title"), this) | |
} | |
} |
This file contains hidden or 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
lazy val hadoopHomePath = | |
Properties.envOrNone("HADOOP_HOME").map { file }.getOrElse(error("please set HADOOP_HOME")) | |
lazy val main = Project(groupName, file("."), | |
settings = defaultSettings ++ Seq( | |
unmanagedClasspath in Compile <<= (unmanagedClasspath in Compile, baseDirectory) map { | |
(cp, bd) => cp ++ Attributed.blankSeq(hadoopHomePath ** "*.jar" get) | |
} | |
) | |
) |
This file contains hidden or 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
(defun unhtml (start end) | |
(interactive "r") | |
(save-excursion | |
(save-restriction | |
(replace-string "&" "&" nil start end) | |
(replace-string "<" "<" nil start end) | |
(replace-string ">" ">" nil start end)))) | |
(defun html (start end) | |
(interactive "r") |
This file contains hidden or 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
#!/bin/sh | |
# Usage: | |
# ./any2pdf index.html | |
# ./any2pdf main.go | |
# | |
# Requirements: | |
# - Pygments | |
# - ImageMagick | |
# - wkhtmltopdf |
This file contains hidden or 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 numpy as np | |
import chainer | |
from chainer import cuda, Function, gradient_check, report, training, utils, Variable, Chain | |
from chainer import datasets, iterators, optimizers, serializers | |
from chainer import Link, Chain, ChainList | |
import chainer.functions as F | |
import chainer.links as L | |
from chainer.training import extensions | |
This file contains hidden or 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 xml.etree.ElementTree as ET | |
import argparse | |
arg_parser = argparse.ArgumentParser() | |
arg_parser.add_argument('in_file') | |
args = arg_parser.parse_args() | |
def main(args): | |
with open(args.in_file) as f: | |
parser = ET.XMLPullParser(['start', 'end']) |
This file contains hidden or 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
String a = "𠮷"; | |
System.out.println("original: " + a); | |
System.out.println("length: " + a.length()); | |
System.out.println("decoded: " + a.codePoints().mapToObj(Character::toChars).map(String::valueOf).collect(Collectors.joining(","))); |
This file contains hidden or 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
# https://github.com/stedolan/jq/issues/243#issuecomment-48470943 | |
jqpath () { | |
jq '[path(..)|map(if type=="number" then "[]" else tostring end)|join(".")|split(".[]")|join("[]")]|unique|map("."+.)|.[]' | |
} |