[
  {
    "path": ".gitignore",
    "content": ".*.swp\nimgs\ndst.png\n"
  },
  {
    "path": "LICENSE",
    "content": "MIT License\n\nCopyright (c) 2016\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE."
  },
  {
    "path": "README",
    "content": "Time to learn the go language.\nWe crack the recaptcha because it's Christmas.\nWe want the Merry Christmas for all!\n\nSorry I am golang noob and code is low quality and shit\nWill eventually use handcoded low quality convnet maybe\n\nAnyone have clever ideas to get ground truth?\nMaybe we unsupervised cluster and then write a paper\nBecause to date that will be the #1 use of unsupervised learning\n\nI go on some dates in NYC tomorrow so maybe we finish this today?\n--> Probs not dawg it takes 2 hours in golang what takes you 5 minutes in Python\n--> Maybe breaking recaptcha will be a fun date activity? Will ask. Very cheap!\n\nGoal is breaking the demo @ https://www.google.com/recaptcha/api2/demo\n\nAlso I realize clicking street signs is probably training the Google Self Driving Car\nCheaters.\n\n== Project Updates ==\n\nChristmas afternoon:\n* Lots of people in my house. It is loud. The fetcher is working.\n\nChristmas night:\n* Been in battle to get more data. Google loves data and hates sharing. Got blocked.\n* Made threads to get fast data. I now have 50842 alleged street sign pictures.\n* They are alleged only though. We need to train a binary classifier.\n\nMorning after christmas:\n* Got bagels. I love bagels\n\n== Project Bullshit ==\n\n* WE ARE ON HACKER NEWS\nhttps://news.ycombinator.com/item?id=13256266\n* OMG THIS IS LITERALLY A BIGGER JOKE THAN SHIA LABEOUF\n* (jkjkjk Shia LaBeouf is way more famous than I will ever be)\n\nDyingLlama is my hero, I found his youtube last night and got inspired\nhttps://www.youtube.com/channel/UC88oKpyXNid09t1m_PZlvfQ\n\n"
  },
  {
    "path": "fetch.go",
    "content": "package main\n\nimport (\n\t\"bytes\"\n\t\"crypto/md5\"\n\t\"encoding/hex\"\n\t\"fmt\"\n\t\"github.com/disintegration/imaging\"\n\t\"golang.org/x/net/html\"\n\t\"image\"\n\t\"image/jpeg\"\n\t\"image/png\"\n\t\"io\"\n\t\"io/ioutil\"\n\t\"log\"\n\t\"math/rand\"\n\t\"net/http\"\n\t\"net/url\"\n\t\"os\"\n\t\"strings\"\n\t\"time\"\n)\n\nconst apiKey string = \"6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-\"\n\nfunc fetchImg(ck string) image.Image {\n\t// fetch the image\n\tu, err := url.Parse(\"http://google.com/recaptcha/api2/payload\")\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\tq := u.Query()\n\tq.Set(\"c\", ck)\n\tq.Set(\"k\", apiKey)\n\tu.RawQuery = q.Encode()\n\n\t// do fetch\n\timgresponse, err := http.Get(u.String())\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\timg, err := jpeg.Decode(imgresponse.Body)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\treturn img\n}\n\nfunc getChallengeKey() (string, string, image.Image) {\n\t// build the request\n\tu, err := url.Parse(\"http://google.com/recaptcha/api/fallback\")\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\tq := u.Query()\n\tq.Set(\"k\", apiKey)\n\tu.RawQuery = q.Encode()\n\t//fmt.Println(u)\n\n\t// fetch the webpage\n\tresponse, err := http.Get(u.String())\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\tdefer response.Body.Close()\n\n\t// print it\n\tbodyBytes, _ := ioutil.ReadAll(response.Body)\n\n\tz := html.NewTokenizer(ioutil.NopCloser(bytes.NewBuffer(bodyBytes)))\n\ttmparr := []string{}\n\tck := \"\"\n\tfor {\n\t\ttt := z.Next()\n\t\tswitch tt {\n\t\tcase html.ErrorToken:\n\t\t\treturn ck, tmparr[3], fetchImg(ck)\n\t\tcase html.StartTagToken, html.SelfClosingTagToken:\n\t\t\ttn, attr := z.TagName()\n\t\t\tif string(tn) == \"img\" && attr {\n\t\t\t\tfor {\n\t\t\t\t\tk, v, attr := z.TagAttr()\n\t\t\t\t\tif string(k) == \"src\" {\n\t\t\t\t\t\t//fmt.Println(string(v))\n\t\t\t\t\t\tu, err := url.Parse(string(v))\n\t\t\t\t\t\tif err != nil {\n\t\t\t\t\t\t\tlog.Fatal(err)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tq := u.Query()\n\t\t\t\t\t\t//fmt.Println(q)\n\t\t\t\t\t\tif q[\"k\"][0] != apiKey {\n\t\t\t\t\t\t\tlog.Fatal(\"apiKey doesn't match\")\n\t\t\t\t\t\t}\n\t\t\t\t\t\tck = q[\"c\"][0]\n\t\t\t\t\t}\n\t\t\t\t\tif !attr {\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\tcase html.TextToken:\n\t\t\t//fmt.Println(z.Token())\n\t\t\ttmparr = append(tmparr, z.Token().String())\n\t\t}\n\t}\n}\n\nfunc downloader() {\n\tbigcnt := 0\n\tfor {\n\t\t// parse it\n\t\tck, typ, img := getChallengeKey()\n\n\t\th := md5.New()\n\t\tio.WriteString(h, ck)\n\t\thh := hex.EncodeToString(h.Sum(nil))\n\t\ttyp = strings.Replace(typ, \" \", \"_\", -1)\n\t\t//fmt.Println(ck, typ, img.Bounds())\n\t\tfmt.Println(bigcnt, hh, typ, img.Bounds())\n\n\t\tif img.Bounds() != image.Rect(0, 0, 300, 300) {\n\t\t\tlog.Fatal(\"IMAGE IS THE WRONG SIZE\")\n\t\t}\n\n\t\t// write it\n\t\tos.MkdirAll(\"imgs/\"+typ, 0755)\n\n\t\tcnt := 0\n\t\tfor h := 0; h < 300; h += 100 {\n\t\t\tfor w := 0; w < 300; w += 100 {\n\t\t\t\tlilimg := imaging.Crop(img, image.Rect(w, h, w+100, h+100))\n\n\t\t\t\tfn := fmt.Sprintf(\"imgs/%s/%s_%d.png\", typ, hh, cnt)\n\t\t\t\tf, err := os.OpenFile(fn, os.O_CREATE|os.O_WRONLY, 0644)\n\t\t\t\tif err != nil {\n\t\t\t\t\tlog.Fatal(err)\n\t\t\t\t}\n\t\t\t\tpng.Encode(f, lilimg)\n\t\t\t\tf.Close()\n\n\t\t\t\tcnt += 1\n\t\t\t}\n\t\t}\n\t\tbigcnt += 1\n\t\ttime.Sleep(time.Duration(rand.Intn(2000)) * time.Millisecond)\n\t}\n}\n\nfunc main() {\n\tfmt.Println(\"my first golang program\")\n\n\t/*for i := 0; i < 8; i += 1 {\n\t  go downloader()\n\t}*/\n\tdownloader()\n\n\t// move on\n\tfmt.Println(\"still alive!\")\n}\n"
  },
  {
    "path": "loader.go",
    "content": "package main\n\n/*\nso like wow there's no neural networks for go, CNN anyone?\nidea is this and if you cheat and use python you are a big cheater\ngive all alleged street sign images 0.4 of street sign\nand give all other images 0.01 chance of street sign\nand maybe with the magic of neural networks we will learn?\n\nTODO: don't be cheater and use python only golang pull request accepted\n*/\n\nimport (\n\t\"fmt\"\n\t\"github.com/disintegration/gift\"\n\t_ \"github.com/disintegration/imaging\"\n\t\"image\"\n\t\"image/png\"\n\t\"log\"\n\t\"math/rand\"\n\t\"os\"\n\t\"path/filepath\"\n\t\"strings\"\n\t//\"github.com/NOX73/go-neural\"\n\t//\"github.com/NOX73/go-neural/learn\"\n\t//\"github.com/sajari/random-forest/RF\"\n)\n\nfunc randomArray(n int) []float32 {\n\tret := make([]float32, n)\n\tfor i := 0; i < n; i++ {\n\t\tret[i] = (rand.Float32() - 0.5) * 5\n\t}\n\treturn ret\n}\n\nfunc main() {\n\tlog.Print(\"use log so we don't have to put an underscore before the import\")\n\n\ttype Example struct {\n\t\tfeatures []float32\n\t\tcategory string\n\t}\n\n\tpaths := make(chan string)\n\tprocessed := make(chan Example)\n\n\t// the Seed for the network is 7\n\trand.Seed(7)\n\n\tg := gift.New(\n\t\t// edge detector\n\t\tgift.Convolution(\n\t\t\t[]float32{\n\t\t\t\t-1, -1, -1,\n\t\t\t\t-1, 8, -1,\n\t\t\t\t-1, -1, -1,\n\t\t\t},\n\t\t\tfalse, false, false, 0.0),\n\t\t// is this max pool?\n\t\tgift.Maximum(2, true),\n\t\tgift.Resize(50, 0, gift.LinearResampling),\n\n\t\t// random 5x5 conv, hmm but like the color channels bro this is a shit neural network\n\t\tgift.Convolution(\n\t\t\trandomArray(25),\n\t\t\tfalse, false, false, 0.0),\n\t\t// is this max pool?\n\t\tgift.Maximum(2, true),\n\t\tgift.Resize(25, 0, gift.LinearResampling),\n\n\t\t// random 3x3 conv, hmm but like the color channels bro this is a shit neural network\n\t\tgift.Convolution(\n\t\t\trandomArray(9),\n\t\t\tfalse, false, false, 0.0),\n\t\t// is this max pool?\n\t\tgift.Maximum(2, true),\n\t\tgift.Resize(10, 0, gift.LinearResampling),\n\n\t\t// 300 features one for each spartan RIP\n\t)\n\n\t//n := neural.NewNetwork(300, []int{100,20,1})\n\t//n.RandomizeSynapses()\n\n\t// forest builder\n\tgo func() {\n\t\t// is this a proper design pattern?\n\t\t// probs not it's awkward ROS node shit\n\t\tfor {\n\t\t\tsample := <-processed\n\t\t\tfmt.Println(sample)\n\n\t\t\t// ugh no inline if?\n\t\t\t/*prob := []float64{0.01}\n\t\t\t  if sample.yes {\n\t\t\t    prob = []float64{0.4}\n\t\t\t  }\n\n\t\t\t  learn.Learn(n, sample.features, prob, 0.05)\n\n\t\t\t  println(prob[0], learn.Evaluation(n, sample.features, prob))*/\n\t\t}\n\t}()\n\n\t// image loader and network runner\n\tgo func() {\n\t\tfor {\n\t\t\tpath := <-paths\n\n\t\t\t// load the image, this is 5 lines\n\t\t\t// i hate all this error handling does go have exceptions?\n\t\t\tf, err := os.Open(path)\n\t\t\tif err != nil {\n\t\t\t\tlog.Fatal(err, path)\n\t\t\t}\n\t\t\timg, err := png.Decode(f)\n\t\t\tif err != nil {\n\t\t\t\tlog.Fatal(err, path)\n\t\t\t}\n\t\t\tf.Close()\n\n\t\t\tdst := image.NewRGBA(g.Bounds(img.Bounds()))\n\t\t\tg.Draw(dst, img)\n\n\t\t\t// extract features\n\t\t\t// i can write much better than this wow shit\n\t\t\tret := make([]float32, 300)\n\t\t\tcnt := 0\n\t\t\tfor i := 0; i < 400; i++ {\n\t\t\t\tif i%4 == 3 {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tret[cnt] = float32(dst.Pix[i]) / 256.0\n\t\t\t\tcnt += 1\n\t\t\t}\n\n\t\t\tprocessed <- Example{features: ret, category: strings.Split(path, \"/\")[1]}\n\n\t\t\t//imaging.Save(dst, \"dst.png\")\n\t\t\t//println(dst)\n\t\t}\n\t}()\n\n\tfiles := []string{}\n\n\tfilepath.Walk(\"imgs/\", func(path string, finfo os.FileInfo, err error) error {\n\t\tif finfo.IsDir() {\n\t\t\treturn nil\n\t\t}\n\t\t//paths <- path\n\t\tfiles = append(files, path)\n\t\treturn nil\n\t})\n\tfmt.Println(\"files list built\")\n\tprintln(len(files))\n\n\t/*perm := rand.Perm(len(files))\n\t  for _, v := range perm {\n\t    paths <- files[v]\n\t  }*/\n}\n"
  }
]