Skip to content

Instantly share code, notes, and snippets.

View kkoch986's full-sized avatar

Ken Koch kkoch986

  • Zentail
  • Raleigh, NC
View GitHub Profile
@kkoch986
kkoch986 / triesize.js
Last active August 29, 2015 13:56
Load an english language dictionary into a Trie and report the number of nodes required.
// Requires Node.js and [Natural](https://github.com/NaturalNode/natural)
var natural = require("natural");
var fs = require("fs");
// NOTE: This file should exist on most UNIX varieties
var dictionary = "/usr/share/dict/words";
var trie = new natural.Trie(false);
console.time("Build Trie");
@kkoch986
kkoch986 / post-receieve
Created February 21, 2014 04:04
Git post-receive hook for automatically deploying a new version of my sites
#!/bin/bash
# CHANGE THIS TO MATCH YOUR PROJECT
root_dir=/var/www/example.com;
while read oldrev newrev refname
do
branch=$(git rev-parse --symbolic --abbrev-ref $refname);
branch_dir=$root_dir/$branch/$newrev;
echo "[CI] Commit recieved on branch $branch";
@kkoch986
kkoch986 / tests.js
Created March 31, 2014 18:39
NaturalNode Wordnet vs Trie `isWord` lookups
// NOTE: These are not rock-solid benchmarks, just a quick illustrative test.
var wordnet = new natural.WordNet();
var fs = require("fs");
var loops = 100;
var allWords = [];
// NOTE: This file should exist on most UNIX varieties
var dictionary = "/usr/share/dict/words";
var trie = new natural.Trie(false);
@kkoch986
kkoch986 / categorization.js
Created July 25, 2014 03:11
Potential Categorization algorithm for Porter Stemmer
function categorizeGroups(token) {
var previous = null;
var current = null;
var string = "";
for(var c in token) {
var ch = token[c];
var next = null;
// Y is a special case, it is only a vowel if preceeded by a vowel.
if(ch === "y") {
@kkoch986
kkoch986 / nueralnets.js
Created December 2, 2014 14:09
playing with neural nets
var Unit = function(value, grad) {
this.value = value;
this.grad = grad;
};
var multiplyGate = function(){ };
multiplyGate.prototype = {
@kkoch986
kkoch986 / prisoners.js
Last active August 29, 2015 14:22
A simulation of 2 solutions to the prisoners with the light switch problem
function solve(prisoner_count, hard_limit) {
var prisoners = [];
var startTime = ((new Date()).getTime());
for(var x = 0 ; x < prisoner_count ; x++) {
prisoners[x] = false;
}
// Pick a random prisoner
function pickPrisoner() {
return Math.floor(Math.random() * prisoner_count);
@kkoch986
kkoch986 / crush.js
Last active December 29, 2015 15:44 — forked from mbuff24/crush.js
Naive javascript solution for Algorithmic Crush -- https://www.hackerrank.com/contests/w4/challenges/crush
String.prototype.splitSpacesAsInts = function() {
return this.split(" ").map(function(aNum) { return parseInt(aNum); });
};
function processData(input) {
var lines = input.split("\n");
var first = lines[0].splitSpacesAsInts();
var n = first[0];
var m = first[1];
var ops = lines.slice(1).map(function(line) { return line.splitSpacesAsInts(); });
@kkoch986
kkoch986 / gist:8312121
Created January 8, 2014 05:11
Use of a Trie to compute all possible word combinations found in a single word
var Trie = require("./index").Trie;
var t = new Trie();
// ... add your word dictionary ....
t.addStrings(["experts", "exchange", "pen", "island", "choose", "spain", "kids", "express", "childrens", "wear", "dickson", "web"]);
var testDomains = ["expertsexchange", "penisland", "choosespain", "kidsexpress", "childrenswear", "dicksonweb"];
function decompose(search) {
// find all of the words which start from the first letter
@kkoch986
kkoch986 / fooball.ino
Created April 9, 2016 14:56
Arduino code for my foosball table
// Circuit Board Pins
// 1- PhotoCell 1 +5
// 2- Arduino A0
// 3- PhotoCell 1 Ground
// 4- PhotoCell 2 +5
// 5- Arduino A1
// 6- PhotoCell 2 Ground
// 7- Arduino D2
// 8- Buzzer +
// 9- Buzzer -
@kkoch986
kkoch986 / pooltable.py
Last active July 6, 2016 22:03
working on a cv experiment for the pool table
import cv2
import numpy as np
import operator
from numpy import pi, sin, cos
import math
## Tweak these
hue_threshold = [4,3] # the lower and upper threshold for hue values in the mask
median_kernel_size = 5