Skip to content

Instantly share code, notes, and snippets.

View hohyon-ryu's full-sized avatar

Will Hohyon Ryu hohyon-ryu

View GitHub Profile
@hohyon-ryu
hohyon-ryu / ES_Stemming.rb
Created May 25, 2011 19:19
Stemming for ElasticSearch
# Script to test stemming for ElasticSearch. Working now!!
# Reference: http://stackoverflow.com/questions/4981001/why-elasticsearch-is-not-finding-my-term
require 'rubygems'
require 'net/http'
require 'yaml'
require 'json'
# kill the index
delete = Net::HTTP::Delete.new("/willindex")
@hohyon-ryu
hohyon-ryu / gist:1107915
Created July 26, 2011 20:21
Get a 3D plane through 3 points and get z of a point (x,y) on that plane
require "matrix"
def cross( v, w )
x = v[1]*w[2] - v[2]*w[1]
y = v[2]*w[0] - v[0]*w[2]
z = v[0]*w[1] - v[1]*w[0]
Vector[x,y,z]
end
def multi_sumV( v, w )
@hohyon-ryu
hohyon-ryu / lda_gibbs.py
Created September 11, 2011 01:35 — forked from mblondel/lda_gibbs.py
Latent Dirichlet Allocation with Gibbs sampler
"""
(C) Mathieu Blondel - 2010
Implementation of the collapsed Gibbs sampler for
Latent Dirichlet Allocation, as described in
Finding scientifc topics (Griffiths and Steyvers)
"""
import numpy as np
@hohyon-ryu
hohyon-ryu / chunk_message.py
Created January 12, 2016 07:28
Chunk a long message into chunks of max length n with the page numbers like (1/10)
def chunk(msg, n):
words = msg.split(" ")
totalPages = 1
prevTotalPages = 0
while totalPages != prevTotalPages:
chunks = []
chunk = []
for word in words:
page = "(%d/%d)" % (len(chunks) + 1, totalPages)
if len(" ".join(chunk + [page])) > n: