├── README ├── node └── HelloNode.js ├── Prediction ├── check-training.sh ├── train.sh ├── predict.sh └── get-auth-token.sh ├── java └── com │ └── siddique │ └── stackoverflow │ ├── StackOverflowLimitTest.java │ ├── StackOverflowLimitWithThreadTest.java │ └── ChainedMethodCallSimulator.java └── sidgit.iml /README: -------------------------------------------------------------------------------- 1 | Yes, its README file with nothing on it :) -------------------------------------------------------------------------------- /node/HelloNode.js: -------------------------------------------------------------------------------- 1 | console.log("Hello Node!"); -------------------------------------------------------------------------------- /Prediction/check-training.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | DATA=$1 4 | 5 | AUTH=`cat auth-token` 6 | 7 | # encode model name 8 | model=`echo $DATA | perl -pe 's:/:%2F:'` 9 | 10 | # get model meta-data 11 | curl -k \ 12 | -H "Authorization: GoogleLogin auth=$AUTH" \ 13 | "https://www.googleapis.com/prediction/v1.1/training/$model" 14 | echo -------------------------------------------------------------------------------- /Prediction/train.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | DATA=$1 4 | 5 | AUTH=`cat auth-token` 6 | 7 | # encode model name 8 | model=`echo $DATA | perl -pe 's:/:%2F:'` 9 | 10 | # train a model 11 | curl -k -X POST \ 12 | -H "Content-Type:application/json" \ 13 | -H "Authorization: GoogleLogin auth=$AUTH" \ 14 | -d "{data:{}}" \ 15 | https://www.googleapis.com/prediction/v1/training?data=$model 16 | echo -------------------------------------------------------------------------------- /java/com/siddique/stackoverflow/StackOverflowLimitTest.java: -------------------------------------------------------------------------------- 1 | package com.siddique.stackoverflow; 2 | 3 | public class StackOverflowLimitTest { 4 | 5 | private static int recursionLimit = 0; 6 | 7 | public static void main(String[] args) { 8 | try { 9 | recursionLimit++; 10 | main(args); 11 | } catch (StackOverflowError e) { 12 | System.out.println("recursionLimit = " + recursionLimit); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /java/com/siddique/stackoverflow/StackOverflowLimitWithThreadTest.java: -------------------------------------------------------------------------------- 1 | package com.siddique.stackoverflow; 2 | 3 | public class StackOverflowLimitWithThreadTest { 4 | private static int recursionLimit = 0; 5 | public static void main(final String[] args) { 6 | new Thread(new Runnable(){ 7 | public void run() { 8 | System.out.println("recursionLimit++ = " + recursionLimit++); 9 | main(args); 10 | } 11 | }).start(); 12 | } 13 | } -------------------------------------------------------------------------------- /Prediction/predict.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | DATA=$1 4 | INPUT="$2" 5 | 6 | AUTH=`cat auth-token` 7 | 8 | # encode model name 9 | model=`echo $DATA | perl -pe 's:/:%2F:'` 10 | data="{data: {\"input\" : { \"text\" : [ \"$INPUT\" ]}}}}" 11 | 12 | echo $data 13 | 14 | # get a prediction 15 | curl -k -X POST \ 16 | -H "Content-Type:application/json" \ 17 | -H "Authorization: GoogleLogin auth=$AUTH" \ 18 | -d "$data" \ 19 | https://www.googleapis.com/prediction/v1.1/training/$model/predict 20 | echo -------------------------------------------------------------------------------- /Prediction/get-auth-token.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | email=$1 4 | password=$2 5 | 6 | # get authorization 7 | curl -k \ 8 | -X POST \ 9 | -d accountType=HOSTED_OR_GOOGLE \ 10 | -d Email=$email \ 11 | --data-urlencode Passwd=$password \ 12 | -d source=companyName-applicationName-versionID \ 13 | -d service=xapi \ 14 | -H 'Content-Type: application/x-www-form-urlencoded' \ 15 | https://www.google.com/accounts/ClientLogin 2>/dev/null | \ 16 | grep 'Auth' | perl -pe 's/^Auth=//' > auth-token 17 | -------------------------------------------------------------------------------- /sidgit.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /java/com/siddique/stackoverflow/ChainedMethodCallSimulator.java: -------------------------------------------------------------------------------- 1 | package com.siddique.stackoverflow; 2 | 3 | import javax.tools.JavaCompiler; 4 | import javax.tools.JavaFileObject; 5 | import javax.tools.StandardJavaFileManager; 6 | import javax.tools.ToolProvider; 7 | import java.io.File; 8 | import java.io.FileWriter; 9 | import java.io.IOException; 10 | import java.lang.reflect.InvocationTargetException; 11 | import java.lang.reflect.Method; 12 | import java.net.URL; 13 | import java.net.URLClassLoader; 14 | import java.util.*; 15 | 16 | public class ChainedMethodCallSimulator { 17 | private static String mainClassHeader = "" + 18 | "public class $MAIN$ {\n" + 19 | " public void main() {\n" + 20 | " System.out.println(\"main\");\n" + 21 | " method_0();\n" + 22 | " }\n"; 23 | 24 | 25 | public static void main(String[] args) throws IOException, ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, InstantiationException { 26 | try { 27 | String className = "ChainedMethodClass"; 28 | 29 | File file = generateJavaFile(className, 7000); 30 | compileJavaFile(file); 31 | Class javaClass = loadClass(new File("."), className); 32 | Object obj = javaClass.newInstance(); 33 | Method method = javaClass.getMethod("main"); 34 | if (method != null) { 35 | method.setAccessible(true); 36 | method.invoke(obj); 37 | } 38 | } catch (Throwable e) { 39 | e.printStackTrace(); 40 | } 41 | } 42 | 43 | 44 | private static void compileJavaFile(File file) throws IOException { 45 | JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); 46 | StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null); 47 | 48 | Iterable compilationUnits1 = 49 | fileManager.getJavaFileObjectsFromFiles(Arrays.asList(file)); 50 | compiler.getTask(null, fileManager, null, null, null, compilationUnits1).call(); 51 | fileManager.close(); 52 | } 53 | 54 | private static File generateJavaFile(String javaClassName, int methodCount) throws IOException { 55 | File javaFile = new File(javaClassName + ".java"); 56 | FileWriter fileWriter = new FileWriter(javaFile); 57 | fileWriter.write(mainClassHeader.replace("$MAIN$", javaClassName)); 58 | for (int i = 0; i < methodCount; i++) { 59 | fileWriter.write("public void method_" + i + "(){\n"); 60 | fileWriter.write(" System.out.println(\" I'm method " + i + " calling method " + (i + 1) + "!\");\n"); 61 | if (i != methodCount - 1) { 62 | fileWriter.write(" method_" + (i + 1) + "();\n"); 63 | } 64 | fileWriter.write("}\n"); 65 | } 66 | fileWriter.write("}"); 67 | fileWriter.flush(); 68 | fileWriter.close(); 69 | return javaFile; 70 | } 71 | 72 | private static Class loadClass(File rootDir, String fullyQualifiedClassName) { 73 | try { 74 | URL url = rootDir.toURI().toURL(); 75 | URL[] urls = new URL[]{url}; 76 | ClassLoader cl = new URLClassLoader(urls); 77 | return cl.loadClass(fullyQualifiedClassName); 78 | } catch (Exception e) { 79 | e.printStackTrace(); 80 | } 81 | return null; 82 | } 83 | } 84 | --------------------------------------------------------------------------------