Skip to content

Instantly share code, notes, and snippets.

George Lesica glesica

View GitHub Profile
glesica / knn.jl
Created Jan 31, 2014
Minimal KNN implementation in Julia.
View knn.jl
using StatsBase
function knn(k, train, classes, obs)
nearest = sortperm(vec(sqrt(sum(broadcast((a, b) -> (a-b)^2, obs, train), 2))))[1:k]
return mode(classes[nearest])
glesica / knn.jl
Created Feb 3, 2014
A simple KNN implementation in Julia that allows for a reasonable level of flexibility. Written to practice using Julia.
View knn.jl
function knn_normalize{T}(D::Array{T, 2}, mx::Array{T, 1}, mn::Array{T, 1})
return mapslices(x -> (x - mn) ./ (mx - mn), D, 2)
function knn_normalize{T}(D::Array{T, 1}, mx::Array{T, 1}, mn::Array{T, 1})
return (D - mn) ./ (mx - mn)
function knn_maxmin{T}(D::Array{T, 2})
mx = vec(mapslices(maximum, D, 1))
glesica / secretary.jl
Last active Aug 29, 2015
Simulation demonstrating the characteristics of the Secretary Problem ( using Julia (
View secretary.jl
# Do K simulation runs each with N items. The goal is to find the largest
# item in the list, without "remembering" and carrying along some previous
# maximum.
N = 10000
K = 1000
diffs = zeros(Int, K)
pct_diffs = zeros(Float64, K)
for i = 1:K
View cartesian_product.jl
type Attr
function cart_prod(sets...)
result_size = length(sets)
result_elems = reduce(*, 1, map(length, sets))
result = zeros(result_elems, result_size)
scale_factor = result_elems
View comprehension.jl
julia> typeof([i for i = 1:nrow(ddf)])
julia> typeof([i for i = 1:10])
julia> k = 10
julia> typeof([i for i = 1:k])
class RequestJson {
protected String firstName;
protected String lastName;
// Getters and setters omitted
class ResponseJson extends RequestJson {
protected Integer userId;
glesica / helloworld.go
Created Jan 27, 2015
Hello, world! using a goroutine
View helloworld.go
package main
import (
func main() {
myChan := make(chan string)
go func() {
glesica / pool.go
Created Jan 27, 2015
Simple example of a goroutine pool.
View pool.go
package main
import (
func main() {
numbers := make(chan int, 10)
squares := make(chan int, 10)
View simple_pool.go
package main
import "sync"
func main() {
jobChan := make(chan int)
resChan := make(chan int)
squareGroup := new(sync.WaitGroup)
// The workers
glesica /
Created Mar 11, 2015
Brief exploration of Python's magic methods for equality testing.
# Equality in Python
# When using custom types (classes) many programmers like to be able
# to use built-in concepts like "==" instead of something like
# "a.equals(b)". Generally it is only a good idea to do this if the
# concept you are implementing is conceptually the same as what the
# operator is normally used for. An example:
class Person1(object):
def __init__(self, name, age):
You can’t perform that action at this time.