Skip to content

Instantly share code, notes, and snippets.

View griesmey's full-sized avatar
🏠
Working from home

Robert Griesmeyer griesmey

🏠
Working from home
  • Monster
  • Las Vegas
View GitHub Profile
def squareList(xs: List[Int]): List[Int] = xs match {
case Nil => xs
case y :: ys => y * y :: squareList(ys)
}
def squareList1(xs: List[Int]): List[Int] =
xs map (y => y * y)
@griesmey
griesmey / mergesort.sc
Created October 12, 2016 15:59
Mergesort with Implicit Type ordering
import math.Ordering
def msort[T](xs: List[T])(implicit ord: Ordering[T]): List[T] = {
val n = xs.length / 2
if (n == 0) xs
else {
def merge(xs: List[T], ys: List[T]): List[T] =
(xs, ys) match {
case (Nil, ys) => ys
case (xs, Nil) => xs
@griesmey
griesmey / gist:163d749f7a5fca65f5d9
Created October 15, 2015 22:34
Algorithm to check if a tree is a binary search tree
> emacs thing.cpp
#include <iostream>
#include <algorithm>
using namespace std;
template <class T>
class Node {
public:
Node* right;
@griesmey
griesmey / bigram_gist.py
Created September 21, 2015 04:35
quick bigram gist; You can use the dictVectorizer and the Tfidf transformer to generate your features
from collections import Counter
import re
from sklearn.feature_extraction import DictVectorizer
from sklearn.feature_extraction.text import TfidfTransformer
from sklearn.feature_extraction.text import CountVectorizer
from itertools import islice, tee
from nltk.corpus import stopwords
def tokenize(sentence):
words = re.findall("[a-zA-Z]+", sentence)
@griesmey
griesmey / .ipynb
Created September 21, 2015 04:33
Bigrams stuff
from itertools import islice, tee
from nltk.corpus import stopwords
@griesmey
griesmey / kmeans.py
Created August 18, 2015 16:31
implementation of KMeans in Python
from math import sqrt
import sys
from collections import defaultdict
from itertools import izip
class Point(object):
def __init__(self, x, y, id=None):
self.x = x
self.y = y
@griesmey
griesmey / TestKNN.py
Created January 27, 2012 01:46
Python script to automate tests for K-nearest Neighbor algorithm
import glob
import get_data
import run_knn
from math import *
__author__ = 'Robert Griesmeyer'
__date__ = 'May 21st 2011'
__doc__ = """ This module is for the use of accuaracy checking of the\
k-nearest neighbor algorithm execution. The parts tested are the predictions\