Skip to content

Instantly share code, notes, and snippets.

xs =: (i: 10) % 10
ys =: (i: 20) % 10
grid =: ys j./ xs
in =: 4 > |
out =: 1 - in
trim =: (* in) + (_ * out)
iter =: trim @ (+ *:)
require 'viewmat'
@yurivish
yurivish / gist:10085175
Last active August 29, 2015 13:58
Artistic design with fractal matrices
NB. http://link.springer.com/article/10.1007%2FBF01908446#page-2
iter =: monad : '(2 * 0 1 { $ +/~y) $, +/~y'
m =: 2 3 $ 0 _4 1 1 _3 2
NB. random matrix with entries from _10 to 10:
NB. m =: 2 3 $ (? 6 $ 20) - 10
viewmat iter^:4 m
@yurivish
yurivish / Treap.jl
Last active August 29, 2015 14:01
A Julia implementation of a treap (v6; in progress)
import Base: isempty, start, next, done, length, getindex, minimum, maximum, search, show
export Treap, TreapNode
type TreapNode{K}
priority::Float64
size::Int
key::K
left::TreapNode{K}
right::TreapNode{K}
code:
function Base.getindex{K}(t::TreapNode{K}, index::Int)
1 <= index <= t.size || throw(KeyError(key))
while t.left.size != index - 1
if index <= t.left.size
t = t.left
else
index = index - t.left.size - 1
t = t.right
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]
@yurivish
yurivish / linegen.jl
Created September 21, 2014 17:19
Antialiased Lines (in progress...)
### 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)
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')
@yurivish
yurivish / v5
Created February 23, 2015 16:47
Documentation
# 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.
* * *
@yurivish
yurivish / venn-diagrams.js
Last active December 26, 2020 03:20
Area-proportional Venn Diagrams
// 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;
}
// Based on a C implementation written by David Blackman and Sebastiano
// Vigna (vigna@acm.org): 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