Skip to content

Instantly share code, notes, and snippets.

@taku0
taku0 / EscapeTest.java
Created May 3, 2012 04:44
Re: 平成24年度春期情報セキュリティスペシャリスト試験のXSS問題 / 単引用符のエスケープだけではだめな場合
public class EscapeTest {
protected static String escape(String word) {
return word.replaceAll("'", "\\u0027"); // '等のエスケープは省略
}
public static void main(String [] args) {
String word = "\" onmouseover=\"alert(document.cookie)\" onmousedown=\"";
System.out.println("<a name=\"#\" onclick=\"alert('" + escape(word) + "')\">");
System.out.println("previous search word");
@taku0
taku0 / inverseIrrationalFizzBuzz.hs
Created July 6, 2012 16:25
naïve implementation of irrational FizzBuzz and inverse irrational FizzBuzz
import Data.List
data FizzBuzz a = Num a | Word String deriving (Eq, Show)
instance Functor FizzBuzz where
fmap f (Num a) = Num $ f a
fmap f (Word s) = Word s
irrationalFizzBuzz =
map f [0..]
@taku0
taku0 / Main.scala
Created December 16, 2012 04:53
Scalaでirof式。varianceを使って少し簡潔に。
object Main extends App {
class irof[+A](val condition: Boolean)(block: => A) {
lazy val value = block
def elof[B >: A](elsePart: => B): B = {
if (condition) value else elsePart
}
}
object irof {
function buildArray(initial, getNext, getElement) {
var current = initial;
var next = getNext(current);
var array = [];
while (current !== next) {
array.push(getElement(current, next));
current = next;
next = getNext(current);
}
{ stdenv, fetchurl
, gconf
, alsaLib
, at_spi2_atk
, atk
, cairo
, cups
, curl
, dbus_glib
, dbus_libs
def part(n, k)
if k == 1
[[n]]
else
0.upto(n).flat_map do |i|
part(n - i, k - 1).map do |partition|
partition.unshift(i)
end
end
end
import Control.Applicative
part n 1 = [[n]]
part n k = [0..n] >>= \i -> (i:) <$> part (n - i) (k -1)
main :: IO ()
main = mapM_ print (part 7 4)
@taku0
taku0 / test.swift
Created January 21, 2015 14:07
Informal swift indentation tests
1 +
2 + 5 *
3
1 +
2 + 5
+ 3
let foo: Foo<A> =

Expected:

let x = 1
        + 1

or

import scala.collection.mutable
object Main extends App {
0.until(100).foreach { _ =>
val start = System.nanoTime()
val map = compute5()
val time = (System.nanoTime() - start) / 1000.0 / 1000.0
println(s"${map.size} $time ms")
}