Skip to content

Instantly share code, notes, and snippets.

View glesica's full-sized avatar

George Lesica glesica

View GitHub Profile
@glesica
glesica / pool.go
Created January 27, 2015 03:28
Simple example of a goroutine pool.
package main
import (
"fmt"
"sync"
)
func main() {
numbers := make(chan int, 10)
squares := make(chan int, 10)
@glesica
glesica / helloworld.go
Created January 27, 2015 03:08
Hello, world! using a goroutine
package main
import (
"fmt"
)
func main() {
myChan := make(chan string)
go func() {
fmt.Println(<-myChan)
class RequestJson {
protected String firstName;
protected String lastName;
// Getters and setters omitted
}
class ResponseJson extends RequestJson {
protected Integer userId;
julia> typeof([i for i = 1:nrow(ddf)])
Array{Any,1}
julia> typeof([i for i = 1:10])
Array{Int64,1}
julia> k = 10
10
julia> typeof([i for i = 1:k])
type Attr
vals
data
end
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
@glesica
glesica / secretary.jl
Last active August 29, 2015 13:57
Simulation demonstrating the characteristics of the Secretary Problem (https://en.wikipedia.org/wiki/Secretary_problem) using Julia (http://julialang.org/).
# 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
@glesica
glesica / knn.jl
Created February 3, 2014 03:51
A simple KNN implementation in Julia that allows for a reasonable level of flexibility. Written to practice using Julia.
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)
end
function knn_normalize{T}(D::Array{T, 1}, mx::Array{T, 1}, mn::Array{T, 1})
return (D - mn) ./ (mx - mn)
end
function knn_maxmin{T}(D::Array{T, 2})
mx = vec(mapslices(maximum, D, 1))
@glesica
glesica / knn.jl
Created January 31, 2014 22:02
Minimal KNN implementation in Julia.
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])
end
"""
Contouring using the Marching Squares algorithm.
George Lesica
"""
from cairo import SVGSurface, Context
WIDTH = 8 * 72.0
HEIGHT = 8 * 72.0
@glesica
glesica / contour.jl
Created September 17, 2013 02:15
Contouring algorithm in Julia.
# contour(A, v)
# Implements the Marching Squares contouring algorithm (see:
# https://en.wikipedia.org/wiki/Marching_squares for details). The
# matrix `A` is an m x n scalar field and the scalar `v` is the
# value to be contoured. The return value is an (m-1) x (n-1) matrix
# of contour line type indices (see the Wikipedia article).
# TODO: Implement in parallel
function contour(A, v)
rows, cols = size(A)