This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Image | |
from os import listdir | |
rgb_counts = {} | |
def main(): | |
process() | |
write_results() | |
def process(): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rgbdata<-read.table("data_all.txt",header=F,sep="\t") | |
names(rgbdata)<-c("r","b","g","count") | |
km<-kmeans(rgbdata[c("r","b","g")],32,iter.max=500) | |
rgbdata$cluster_32<-km$cluster | |
rgbsamp<-rgbdata[sample(nrow(rgbdata), 5000), ] | |
library(fpc) | |
plotcluster(rgbsamp[c("r","b","g")], rgbsamp$cluster_32,col=rgb(rgbsamp$r/255,rgbsamp$g/255,rgbsamp$b/255),pch=19) | |
library(plyr) | |
rgb_means<-ddply(rgbdata,~cluster_32,summarise,r=mean(r),g=mean(g),b=mean(b),count=sum(count)) | |
rgb_means$r<-round(rgb_means$r) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import rauth | |
import time | |
def main(): | |
locations = [(39.98,-82.98),(42.24,-83.61),(41.33,-89.13)] | |
api_calls = [] | |
for lat,long in locations: | |
params = get_search_parameters(lat,long) | |
api_calls.append(get_results(params)) | |
#Be a good internet citizen and rate-limit yourself |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Arrays; | |
/** | |
* Author: Phillip Johnson | |
* Date: 3/15/14. | |
*/ | |
public class NaiveHashTable { | |
private Object[][] hashTable; | |
private static final int MAX_EQUAL_HASHES = 8; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The MIT License (MIT) | |
Copyright (c) 2014 Phillip Johnson | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to deal | |
in the Software without restriction, including without limitation the rights | |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
copies of the Software, and to permit persons to whom the Software is | |
furnished to do so, subject to the following conditions: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val b64_ZH = "的一是不了人我在有他这中大来上国个到说们为子和你地出道也时年得" + | |
"就那要下以生会自着去之过家学对可她里后小么心多天而能好都然没日。" | |
val b64_EN = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" | |
val input = "Man is distinguished, not only by his reason, but by this singular " + | |
"passion from other animals, which is a lust of the mind, that by a " + | |
"perseverance of delight in the continued and indefatigable generation " + | |
"of knowledge, exceeds the short vehemence of any carnal pleasure." | |
def strToAscii(s: String) : List[Int] = { | |
val ascii = for { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.collection.mutable | |
val MARKOV_MAP:mutable.Map[Seq[String], mutable.Map[String, Int]] = new mutable.HashMap() | |
val CHAIN_SIZE = 2 | |
def adjustProbabilities(sentence:String):Unit = { | |
val segments = sentence.split(" ").+:("").:+("").sliding(CHAIN_SIZE + 1).toList | |
for(segment <- segments) { | |
val key = segment.take(CHAIN_SIZE) | |
val probs = MARKOV_MAP.getOrElse(key, scala.collection.mutable.Map()) |