This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Combinatorics | |
factorial(x) = reduce(*, 1:Int(x)) | |
# type union shorthand for dispatching on specific functions | |
union(fs...) = Union{typeof.(fs)...} | |
# unary operations | |
apply!(op::union(sqrt, factorial), xs) = push!(xs, op(pop!(xs))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Name{T} | |
name::T | |
end | |
struct Arr{T, N} <: AbstractArray{T, N} | |
data::Array{T, N} | |
end | |
Base.size(A::Arr) = size(A.data) | |
Base.axes(A::Arr) = axes(A.data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using LibSndFile, Images, Colors | |
# Load and parse the viridis color scheme | |
viridis_data = "44015444025645045745055946075a46085c460a5d460b5e470d60470e6147106347116447136548146748166848176948186a481a6c481b6d481c6e481d6f481f70482071482173482374482475482576482677482878482979472a7a472c7a472d7b472e7c472f7d46307e46327e46337f463480453581453781453882443983443a83443b84433d84433e85423f854240864241864142874144874045884046883f47883f48893e49893e4a893e4c8a3d4d8a3d4e8a3c4f8a3c508b3b518b3b528b3a538b3a548c39558c39568c38588c38598c375a8c375b8d365c8d365d8d355e8d355f8d34608d34618d33628d33638d32648e32658e31668e31678e31688e30698e306a8e2f6b8e2f6c8e2e6d8e2e6e8e2e6f8e2d708e2d718e2c718e2c728e2c738e2b748e2b758e2a768e2a778e2a788e29798e297a8e297b8e287c8e287d8e277e8e277f8e27808e26818e26828e26828e25838e25848e25858e24868e24878e23888e23898e238a8d228b8d228c8d228d8d218e8d218f8d21908d21918c20928c20928c20938c1f948c1f958b1f968b1f978b1f988b1f998a1f9a8a1e9b8a1e9c891e9d891f9e891f9f881fa0881fa1881fa1871fa28720a38620a48621a58521a68522a78522a88423a9832 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// S + $type_ -> $type_ | |
impl $trait_<$type_> for S { | |
type Output = $type_; | |
fn $fn_(self, rhs: $type_) -> $type_ { | |
$type_::new($(self $op rhs.$args), *) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Based on a C implementation written by David Blackman and Sebastiano | |
// Vigna ([email protected]): http://xoroshiro.di.unimi.it/xoroshiro128plus.c | |
// Translated to Rust by Yuri Vishnevsky. Code kept close to the original. | |
/* This is the successor to xorshift128+. It is the fastest full-period | |
generator passing BigCrush without systematic failures, but due to the | |
relatively short period it is acceptable only for applications with a | |
mild amount of parallelism; otherwise, use a xorshift1024* generator. | |
Beside passing BigCrush, this generator passes the PractRand test suite |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Since `overlapArea` function is monotonic increasing, we can perform a | |
// simple bisection search to find the distance that leads to an overlap | |
// area within epsilon of the desired overlap. | |
function distanceForOverlapArea(r1, r2, desiredOverlap) { | |
// Ensure r1 <= r2 | |
if (r1 > r2) { | |
var temp = r2; | |
r2 = r1; | |
r1 = temp; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# V5 Documentation | |
V5 is built using [React](reactjs.org). The overall architecture of the V5 application follows Facebook’s standard [Flux](http://facebook.github.io/flux/docs/overview.html) model for organizing React-based systems. | |
Briefly, data is stored in **stores** which subscribe to **events** dispatched by a **Dispatcher**. Dispatches usually occur in response to a user interface interaction. **UI components** subscribe to **change events** on the **stores** they care about. They respond to change events by rerendering to reflect the current state. | |
The entry point is **main.coffee**. That is where project data for the chosen project is loaded from the cache, or, if not present there, from the server. It is also the location of the other assorted initialization tasks like kicking off the rendering of the UI. | |
* * * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window._d = window.d = console?.log.bind(console) ? -> | |
randUpTo = (num) -> ~~(num * Math.random()) | |
randIndex = (arr) -> randUpTo(arr.length) | |
randEntry = (arr) -> arr[randIndex(arr)] | |
d3.text 'data/aphorisms.txt', (err, text) -> | |
throw err if err | |
lines = text.split('\n') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Vectors ### | |
immutable Vec2 | |
x::GLfloat | |
y::GLfloat | |
end | |
Base.getindex(a::Vec2, n) = n == 1 ? a.x : n == 2 ? a.y : error("Invalid Vec2 index: $n") | |
Base.length(a::Vec2) = 2 | |
Base.norm(a::Vec2) = sqrt(a.x^2 + a.y^2) | |
normalize(a::Vec2) = a / norm(a) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getInfoLog(obj::GLuint) | |
# Return the info log for obj, whether it be a shader or a program. | |
isShader = glIsShader(obj) | |
getiv = isShader == GL_TRUE ? glGetShaderiv : glGetProgramiv | |
getInfo = isShader == GL_TRUE ? glGetShaderInfoLog : glGetProgramInfoLog | |
# Get the maximum possible length for the descriptive error message | |
int::Array{GLint, 1} = [0] | |
getiv(obj, GL_INFO_LOG_LENGTH, int) | |
maxlength = int[1] |
NewerOlder