Skip to content

Instantly share code, notes, and snippets.

@jonniek
jonniek / setNativeValue.js
Created January 21, 2022 15:40
set input value from console reactively
function setNativeValue(element, value) {
const valueSetter = Object.getOwnPropertyDescriptor(element, 'value').set;
const prototype = Object.getPrototypeOf(element);
const prototypeValueSetter = Object.getOwnPropertyDescriptor(prototype, 'value').set;
if (valueSetter && valueSetter !== prototypeValueSetter) {
prototypeValueSetter.call(element, value);
} else {
valueSetter.call(element, value);
}
@jonniek
jonniek / url-resolver.lua
Last active May 1, 2019 09:29
mpv url resolver
-- resolve_ytdl helper command: https://gist.github.com/jonniek/4a9d850d224bbd704b71f9ec882eeef6
-- copy it and add it to some path dir and update the below path to match
local resolver = '/usr/bin/resolve_ytdl'
local tmpfile = '/tmp/resolvedtitle'
local utils = require("mp.utils")
local processed_urls = {}
local resolved_urls = {}
mp.observe_property('playlist-count', "number", function()
@jonniek
jonniek / postfixcalc.js
Last active October 2, 2018 11:38
Postfix calculator
function Stack() {
let arr = []
return {
push: (data) => arr.push(data),
pop: () => arr.pop(),
show: () => arr
}
}
function calc(string, showstack) {
function binaryArray(arr) {
const array = arr
const find = (searchvalue) => {
let middle = Math.floor(array.length / 2)
let left = 0
let right = array.length
while (right >= left) {
function Node(value, parent, left, right) {
this.value = value
this.left = left || null
this.right = right || null
this.parent = parent || null
this.height = () => {
const lefth = this.left ? this.left.height() : -1
const righth = this.right ? this.right.height() : -1
if (lefth > righth) {
return lefth + 1;
function iterableStack() {
let arr = []
return {
push: (data) => arr.push(data),
pop: () => arr.pop(),
[Symbol.iterator]: function* () {
let index = 0
while (arr[index]) {
yield arr[index]
index++
@jonniek
jonniek / queue.js
Last active August 29, 2018 15:27
Simple queue and Stack in js
function createStack() {
let head = null
let length = 0
return {
push: (data) => {
head = { data, next: head }
length++
},
pop: () => {
if (head === null) return null
@jonniek
jonniek / twoWayKeyValueStore.js
Created August 14, 2018 07:20
Two way key value hashmap/object/store in JavaScript. Get keys with values or values with keys.
/**
* Two way key value store.
* When you want to get key with value or value with a key.
*
* examples:
* var store = twoWayKeyValueStore([ [200, "ok"], [401, "unauthorized"] ])
* store.get(401) // "unauthorized"
* store.get("unauthorized") // 401
* store.set(200, "ok").get("ok") // 200
* store.remove("ok").get(200) // undefined
@jonniek
jonniek / systemfont.css
Created August 15, 2017 08:22
Use system fonts for html text styles
/* Sans-serif system fonts look good and do not need to be loaded by the visitor! */
body {
font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",sans-serif;
}
/*
For serif and monospace:
font-family: "Apple Garamond", "Baskerville", "Times New Roman", "Droid Serif", "Times","Source Serif Pro", serif;
font-family: "SF Mono", "Monaco", "Inconsolata", "Fira Mono", "Droid Sans Mono", "Source Code Pro", monospace;
*/
@jonniek
jonniek / movingsub.lua
Last active October 4, 2018 11:30
moving external subs for mpv
--mpv.conf -> input-ipc-server=/tmp/mpvsocket
--$ echo 'script-message addscrollingsub "hello world"' | socat - /tmp/mpvsocket
local assdraw = require("mp.assdraw")
local utils = require("mp.utils")
local settings = {
ass_style = "\\1c&HC8C8B4\\fs33\\bord2",
speed = 0.3
}