Skip to content

Instantly share code, notes, and snippets.

View trustedtomato's full-sized avatar

Tamás Halasi trustedtomato

  • Hungary, Budapest
View GitHub Profile
@trustedtomato
trustedtomato / curry.js
Last active August 25, 2017 17:58
Javascript ES6 currying
function curry(fn){
const len = fn.length;
const next = oldArgs => (...newArgs) => {
const args = oldArgs.concat(newArgs);
return (args.length >= len)
? fn.apply(this, args)
: next(args);
};
return next([]);
};
@trustedtomato
trustedtomato / wait-for-key.js
Last active August 25, 2017 14:38
Wait for a key in JS
/** Wait for the given key; if key is omitted, any key will trigger. It resolves the event. */
function waitForKey(key){
return new Promise(resolve => {
var onkeydown = e => {
if(typeof key === 'undefined' || e.key === key){
document.removeEventListener('keydown', onkeydown);
resolve(e);
}
};
document.addEventListener('keydown', onkeydown);
@trustedtomato
trustedtomato / twoExp.js
Created August 30, 2017 12:09
2^n in an other way
twoExp = n => eval('0b1' + Array(n - 1).fill(0).join(''));
@trustedtomato
trustedtomato / wait-frame.js
Created August 31, 2017 09:23
requestAnimationFrame Promise
const waitFrame = () => new Promise(requestAnimationFrame);
@trustedtomato
trustedtomato / all-mp3-to-opus
Last active December 10, 2017 18:46
Covert all mp3 to opus
find . -exec ffmpeg -i {} -acodec libopus -b:a 64k -n -vbr on -compression_level 10 ~/Documents/opus/{}.opus \;
@trustedtomato
trustedtomato / cursor.ts
Last active October 22, 2017 18:26
Tracking cursor position & improved mousemove event
const cursor = (() => {
const cursorEventTarget = Object.assign(document.createDocumentFragment(), {x: 0, y: 0});
let changed = false;
const onmove = (e:MouseEvent) => {
if(cursorEventTarget.x !== e.x || cursorEventTarget.y !== e.y){
cursorEventTarget.x = e.x;
cursorEventTarget.y = e.y;
changed = true;
}
};
/* System Fonts as used by GitHub */
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
}
/* System Fonts as used by Medium and WordPress */
body {
font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",sans-serif;
}
@trustedtomato
trustedtomato / .bash_aliases
Last active May 6, 2019 11:26
Debian post-install script.
alias clipboard='xclip -selection c'
@trustedtomato
trustedtomato / alacritty.sh
Created December 28, 2019 14:23
Open alacritty in current directory.
alacritty --working-directory $(DIR=$(xprop -id $(xprop -root '\t$0' _NET_ACTIVE_WINDOW | cut -f 2) 8t '\t$0' _NET_WM_NAME | cut -f 2 | grep -Po '(?<=:).*(?=")' | sed "s|^~|$HOME|"); if [ -d "$DIR" ]; then echo $DIR; else echo $HOME; fi)
@trustedtomato
trustedtomato / advent of code.md
Last active December 4, 2022 14:32
Advent of code 2022

These are my solutions to Advent of Code 2022. They are not meant to be readable, these are just the quickest-to-write solutions I found with plain ol' Javascript.