Skip to content

Instantly share code, notes, and snippets.

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

Simon SimonDanisch

🏠
Working from home
View GitHub Profile
function foo(x::Vector{Number}) = println(x)
# Will only be callable with Array{Number},
# but not with any subtype of number like Array{Int}
function foo{T <: Number}(x::Vector{T}) = println(x)
# Will be callable with every Array
function foo{T <: Vector{Z <: FloatingPoint}}(x::Vector{T}) = println(x)
# Doesn't exist :(
import VideoIO
using GLPlot, React, GLAbstraction
device = VideoIO.DEFAULT_CAMERA_DEVICE
format = VideoIO.DEFAULT_CAMERA_FORMAT
camera = VideoIO.opencamera(device, format)
img = VideoIO.read(camera)
# Just for fun, lets apply a laplace filter:
using GLPlot
xx=[1 2 3 4;
1 2 3 4;
1 2 3 4];
yy=[2 2 2 2;4 4 4 4;6 6 6 6]
vals=ones(3,4)
colorf(m)="xyz.z>0 ? vec4(.2,.4,0.5+"string(m)"*xyz.z,0.98) : vec4(.2,.4-"*string(1.2m)"*xyz.z,0.5,0.98);" # <- forgot *
function glupdatewindow(obj,window)
@SimonDanisch
SimonDanisch / FixedSizeArray.jl
Created October 28, 2014 18:07
FixedSizeArray Bench
module Test1
tic()
using FixedSizeArrays
elapsed_time = toq()
println("loading time FixedSizeArrays: ", elapsed_time)
immutable RGB{T} <: AbstractFixedVector{T, 3}
r::T
g::T
b::T
@SimonDanisch
SimonDanisch / FixedSizeArrays.jl
Created October 28, 2014 18:11
FixedSizeArrays
module FixedSizeArrays
importall Base
export AbstractFixedArray
export AbstractFixedVector
export AbstractFixedMatrix
export cross
export norm
export unit
macro DSL(name, text)
tokens = dsltokenizer(DSLTokens{name}(), text)::DSLTokens{name}
dslast = generate_ast(tokens)::AST{name}
return dsl(dslast)::AST{:Julia}
end
#Overwrite any of these stages, to implement your own DSL
dsltokenizer(::DSLTokens, text) = ...
generate_ast(text::DSLTokens) = ...
dsl(ast::AST) = ...
#Version 1, if you really need to access the counters via a name
type CountersDict
counters::Dict{Symbol, Array{Int64}}
end
function CountersDict()
CountersDict([
:counter1 => zeros(Int64, 100000),
:counter2 => zeros(Int64, 100000),
:counter3 => zeros(Int64, 100000),
:counter4 => zeros(Int64, 500),
immutable Functor{FuncName} end
#with staged functions available in 0.4:
#=
stagedfunction evaluate{NumArgs,FuncName}(::Functor{FuncName}, args::NTuple{NumArgs})
args_expr = map(1:NumArgs) do x
:(args[$x])
end
:($FuncName($(args_expr...)))
end
=#
using Romeo, GLFW, GLAbstraction, Reactive, ModernGL, GLWindow, Color
function init_romeo()
sourcecode_area = lift(Romeo.ROOT_SCREEN.area) do x
Rectangle(0, 0, div(x.w, 7)*3, x.h)
end
visualize_area = lift(Romeo.ROOT_SCREEN.area) do x
Rectangle(div(x.w,7)*3, 0, div(x.w, 7)*3, x.h)
end
search_area = lift(visualize_area) do x
immutable StandardChunk
i32::Int32
i64::Int64
i8::Int8
end
immutable ByteBuffer{Chunk}
data::Vector{Chunk}
ptr::Ptr{Int8}
end
ByteBuffer{T}(data::Vector{T}) = ByteBuffer{T}(data, convert(Ptr{Int8}, pointer(data)))