Skip to content

Instantly share code, notes, and snippets.

View taichi's full-sized avatar
😸
shaving...

taichi taichi

😸
shaving...
View GitHub Profile
import java.util.regex.Pattern;
import org.junit.Assert;
import org.junit.Test;
public class Under66536 {
@Test
public void under65536() {
assertUnder65536("0");
assertUnder65536("065");
@taichi
taichi / AddressUtil.java
Created January 31, 2011 09:30
convert from IP address text presentation to InetSocketAddress
import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @see <a href="http://tools.ietf.org/html/rfc4291">[RFC4291] IP Version 6
* Addressing Architecture</a>
* @see <a href="http://tools.ietf.org/html/rfc5952">[RFC5952] A Recommendation
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import org.junit.Before;
import org.junit.Test;
@taichi
taichi / YamlEventParser.java
Created February 2, 2011 13:41
Json pull event parser. this implementation is incomplete.
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Deque;
import java.util.LinkedList;
import java.util.List;
import org.yaml.snakeyaml.events.Event;
import org.yaml.snakeyaml.events.Event.ID;
import org.yaml.snakeyaml.parser.Parser;
public class Callee {
public void execute(int i) {
System.out.println(i);
}
}
@taichi
taichi / junit4_template.xml
Last active September 24, 2015 23:48
Junit4 template for eclipse4.5
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<templates>
<template autoinsert="true" context="java-statements" deleted="false"
description="assertEquals - JUnit 4" enabled="true" name="ase">${:importStatic(org.junit.Assert.assertEquals)}assertEquals(${expected:var(java.lang.Object)},
${actual:var(java.lang.Object)});${cursor}</template>
<template autoinsert="true" context="java-statements" deleted="false"
description="assertTrue - JUnit 4" enabled="true" name="astrue">${:importStatic(org.junit.Assert.assertTrue)}assertTrue(${actual:var(boolean)});${cursor}
</template>
<template autoinsert="true" context="java-statements" deleted="false"
description="assertFalse - JUnit 4" enabled="true" name="asfalse">${:importStatic(org.junit.Assert.assertFalse)}assertFalse(${expected:var(boolean)});${cursor}
@taichi
taichi / WindowsSelectorImpl.c
Created February 18, 2011 15:47
From OpenJDK7
/*
* Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
@taichi
taichi / LockFree.java
Created February 24, 2011 10:25
ConcurrentMap contains Set. feel easy but not.
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ConcurrentSkipListSet;
import java.util.concurrent.ExecutorService;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class ArrayCompare {
public static int compare(byte[] lefts, byte[] rights) {
if (lefts == rights) {
return 0;
}
@taichi
taichi / maskdata.sql
Created March 21, 2011 09:50
data masking queries.
USE ushahidi;
SET NAMES utf8;
CREATE TABLE IF NOT EXISTS `maskdatas` (
`id` int(11) unsigned NOT NULL auto_increment,
`fromdata` varchar(255) default NULL,
`todata` varchar(255) default NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;