Skip to content

Instantly share code, notes, and snippets.

View mathiasvr's full-sized avatar

Mathias Rasmussen mathiasvr

  • Denmark
View GitHub Profile
@mathiasvr
mathiasvr / cie1931.py
Last active October 21, 2024 21:08
Convert LED brightness to PWM value based on CIE 1931 curve.
# Generate lookup table for converting between perceived LED brightness and PWM
# Adapted from: https://jared.geek.nz/2013/feb/linear-led-pwm
# See also: https://ledshield.wordpress.com/2012/11/13/led-brightness-to-your-eye-gamma-correction-no/
from sys import stdout
TABLE_SIZE = 256 # Number of steps (brightness)
RESOLUTION = 2**10 # PWM resolution (10-bit = 1024)
@mathiasvr
mathiasvr / autosub.lua
Last active December 3, 2018 00:46 — forked from selsta/autosub.lua
Automatically download subtitles in mpv using subliminal.
local utils = require 'mp.utils'
function load_sub_fn()
log("info", "Searching for subtitles")
local t = {args = {"subliminal", "download", "-s", "-l", "en", mp.get_property("path")}}
local res = utils.subprocess(t)
if res.status == 0 and res.stdout:find("0 error") then
mp.commandv("rescan_external_files", "reselect")
@mathiasvr
mathiasvr / index.js
Created October 15, 2016 18:37
requirebin sketch
var onHold = require('on-hold')
var i = 0
var div = document.createElement('div')
var btn = document.createElement('button')
btn.textContent = 'Press and Hold'
document.body.appendChild(btn)
document.body.appendChild(div)
@mathiasvr
mathiasvr / index.js
Created June 9, 2016 22:57
requirebin sketch
var mainLoop = require('main-loop')
var h = require('virtual-dom/h')
var state = { items: [] }
function renderItem (item) {
var listItem = h('li.item', {
key: item.color, // TODO: use a unique key.
style: { 'background-color': item.color },
onclick: function (ev) { removeItem(item.color) }