Skip to content

Instantly share code, notes, and snippets.

@vrld
vrld / refresh-firefox
Created July 9, 2019 08:02
Refresh firefox window with xdotool
#!/bin/sh
ACTIVE_WINDOW=$(xdotool getactivewindow)
if [ -z "${1}" ]; then
xdotool search --classname Navigator windowactivate --sync key --clearmodifiers "ctrl+F5"
else
xdotool search --classname Navigator search --name $1 windowactivate --sync key --clearmodifiers "ctrl+F5"
fi
@vrld
vrld / marknote
Created July 9, 2019 08:00
Live Markdown Preview powered by pandoc and entr
#!/bin/sh
usage() {
echo "Usage: marknote path"
exit -1
}
FILE=$1
[ -z "${FILE}" ] && usage
def covar_2d(e, s):
"""Returns a 2D covariance matrix with main diagonal in direction e and second diagonal perpendicular to e with proportional length s.
Params:
-------
e: array-like
Direction of the main diagonal.
s: float
Proportional scale of the second diagonal.
@vrld
vrld / dirble.py
Created April 2, 2015 23:52
Python Dirble API wrapper
import requests
from collections import namedtuple
class Dirble(object):
Category = namedtuple("Category", "id name description")
Station = namedtuple("Station", "id name streamurl country bitrate status")
StationDetails = namedtuple("StationDetails", "id name streamurl country bitrate status description added urlid website songhistory")
Song = namedtuple("Song", "artist title")
def __init__(self, key, base_url):
@vrld
vrld / cholesky.jl
Last active August 29, 2015 14:14
Cholesky Decomposition and simple (!) gaussian process regression
function chol_(A::Matrix, L::Matrix)
for i = 1:size(A,1)
s = 0
@simd for j = 1:i-1
@inbounds L[i,j] = (A[i,j] - sum([L[i,k]*L[j,k] for k = 1:j-1])) / L[j,j]
@inbounds s += L[i,j]^2
end
L[i,i] = sqrt(A[i,i] - s)
end
L
@vrld
vrld / OnlineLearning.jl
Created October 31, 2014 12:00
Online Learning Algorithms
type Perceptron
w::Vector{Float64}
Perceptron(d::Int) = new(zeros(d))
Perceptron(w::Vector{Float64}) = new(w)
end
type Winnow
w::Vector{Float64}
η::Float64
Perceptron(d::Int, η::Float64) = new(ones(d)./d, η)
@vrld
vrld / ContourDescriptors.jl
Created October 30, 2014 12:34
Various contour descriptors
function forward_difference(c::Matrix)
out = zeros(c)
@simd for i = 1:size(c,1)-1
@inbounds out[i,:] = c[i+1,:] - c[i,:]
end
@inbounds out[size(c,1),:] = c[1,:] - c[size(c,1),:]
out
end
function at(c::Matrix, t::Number, Δc::Matrix, cumlen::Vector{Float64})
module Crossvalidation
export KFold, StratifiedKFold, LOO, RandomSplit
#==
K-Fold cross validation
Example (5-Fold CV):
KFold(X, y, 5) do X_tr, y_tr, X_te, y_te
train!(model, X_tr, y_tr)
@vrld
vrld / rythm.lua
Created June 3, 2014 12:31
Euclidean Rythms in Lua
-- Euclidean rythm (http://en.wikipedia.org/wiki/Euclidean_Rhythm)
function rythm(k,n)
local r = {}
for i = 1,n do
r[i] = {i <= k}
end
local function cat(i,k)
for _,v in ipairs(r[k]) do
r[i][#r[i]+1] = v
@vrld
vrld / buddha.cpp
Last active August 29, 2015 13:56
Buddhabrot Renderer
#include <omp.h>
#include <vector>
#include <complex>
#include <iostream>
#include <fstream>
#include <sstream>
#include <exception>
#include <string>
#include <cstdint>