Skip to content

Instantly share code, notes, and snippets.


Phillip Johnson phillipjohnson

View GitHub Profile
phillipjohnson /
Created Jun 1, 2016
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())
phillipjohnson / b64.scala
Created Jul 6, 2014
Scala base64 encryption with alternative encodings
View b64.scala
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 / LICENSE.txt
Last active Dec 21, 2016
Simple steganography in Python
View LICENSE.txt
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 /
Created Mar 16, 2014
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 /
Created Feb 8, 2014
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)
#Be a good internet citizen and rate-limit yourself
phillipjohnson / rgb_img_cluster.R
Last active Dec 29, 2015
Cluster RGB data in R.
View rgb_img_cluster.R
rgbsamp<-rgbdata[sample(nrow(rgbdata), 5000), ]
plotcluster(rgbsamp[c("r","b","g")], rgbsamp$cluster_32,col=rgb(rgbsamp$r/255,rgbsamp$g/255,rgbsamp$b/255),pch=19)
phillipjohnson /
Last active Dec 29, 2015
Quick Python script to process image RGB data.
import Image
from os import listdir
rgb_counts = {}
def main():
def process():