Skip to content

Instantly share code, notes, and snippets.

import sys
import math
import random
debug = False
if debug: fo = open("random10.txt", "r")
def read():
if debug:
import sys
import math
import random
import time
debug = False
if debug: fo = open("./2ndSample2.txt", "r")
if debug: foOut = open("./2ndSample2out.txt", "r")
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.stream.Stream;
public class Main {
private boolean debug = true;
static public class Node {
@kentan
kentan / Main.java
Created April 18, 2017 22:11
Reinforcement Learning Sample
import java.util.Arrays;
import java.util.Random;
/**
* Reinforcement Learning Sample
* Monte Carlo Version.
* Based on(https://gist.github.com/Hiromi-Ayase/3e88a34c80ec496b70a765b9a907bc69)
*
*/
@kentan
kentan / gist:f1bdc74871debd9de789
Created November 25, 2014 01:10
Sample code for CodingErrorAction.IGNORE,CodingErrorAction.REPLACE and CodingErrorAction.REPORT
public void sampleCodingErroAction(String hex, CodingErrorAction actionOnMalformedInput, CodingErrorAction actionOnUnmappableCharacter){
ByteBuffer buff = ByteBuffer.allocate(hex.length()/2);
for (int i = 0; i < hex.length(); i+=2) {
buff.put((byte)Integer.parseInt(hex.substring(i, i+2), 16));
}
buff.rewind();
Charset cs = Charset.forName("shift-jis");
CharBuffer cb = null;
try {
cb = cs.newDecoder()
@kentan
kentan / RegExp Quantifiers Sample.2
Created August 25, 2014 21:03
Sample code for the performance difference among the regular expression quantifiers .
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegExpTest2 {
private static String str = "xfooxxxxxxfoo";
private static int LIMIT = 9;
private static long[] arrGreedy = new long[LIMIT];
private static long[] arrReluctant = new long[LIMIT];
private static long[] arrPossessive = new long[LIMIT];
@kentan
kentan / RegExpTest1.java
Last active August 29, 2015 14:05
Sample code for the performance difference among the regular expression quantifiers .
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegExpTest1 {
private static String str = "xfooxxxxxxfoo";
private static int max = 10000000;
public static void main(String args[]){
runGreedy();
@kentan
kentan / gist:64a5962a16f8036b7290
Created July 24, 2014 00:52
JNDI sample code using file system service provider.
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NameClassPair;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import java.util.Hashtable;
import com.sun.jndi.fscontext.RefFSContext;
class JNDIFileLookup {
public static void main(String[] args) {
<!DOCTYPE html>
<html>
<head>
<script language="javascript">
var radius = 150;
var center_x = 200;
var center_y = 150;
function draw_polygon(){
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
@Path("sample/{samplePathParam}")
public class Main {