Skip to content

Instantly share code, notes, and snippets.

View phillipjohnson's full-sized avatar

Phillip Johnson phillipjohnson

View GitHub Profile
@phillipjohnson
phillipjohnson / rbg_img_process.py
Last active December 29, 2015 05:39
Quick Python script to process image RGB data.
import Image
from os import listdir
rgb_counts = {}
def main():
process()
write_results()
def process():
@phillipjohnson
phillipjohnson / rgb_img_cluster.R
Last active December 29, 2015 05:39
Cluster RGB data in R.
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)
@phillipjohnson
phillipjohnson / yelp_api_intro.py
Created February 8, 2014 20:18
A basic introduction to using the rauth library and the Yelp API.
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
@phillipjohnson
phillipjohnson / NaiveHashTable.java
Created March 16, 2014 17:44
Naive implementation of a hash table.
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;
@phillipjohnson
phillipjohnson / LICENSE.txt
Last active January 20, 2023 13:45
Simple steganography in Python
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:
@phillipjohnson
phillipjohnson / b64.scala
Created July 6, 2014 01:29
Scala base64 encryption with alternative encodings
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 {
@phillipjohnson
phillipjohnson / markov.sc
Created June 1, 2016 18:49
Markov-Chain Text Generation in Scala
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())