Skip to content

Instantly share code, notes, and snippets.

@tomasdev
tomasdev / colorize.js
Created April 10, 2024 00:52
Colorize any size palette
const s = document.createElement('script'); s.src = 'https://colorjs.io/dist/color.global.js'; document.body.appendChild(s);
// wait for load
function colorize(hue) {
$$("body *").forEach(e => {
if (e.tagName.toUpperCase() === 'SVG' || e.closest('svg')) return;
const s = getComputedStyle(e);
for (const prop of s) {
if (prop.startsWith('-webkit')) continue;
const value = s[prop];
@tomasdev
tomasdev / commands.sh
Last active December 4, 2022 22:50
Useful Docker commands
# Cheat sheet at https://dockerlabs.collabnix.com/docker/cheatsheet/
# Creates a Docker image on the current directory (must have a Dockerfile)
docker build -t $IMAGE_NAME .
# Run the recently built image
docker run $IMAGE_NAME
# Deletes all containers and all images
docker container prune && docker image prune -a
@tomasdev
tomasdev / minecraft-emoji.md
Last active November 5, 2024 17:40
Minecraft allowed emojis

Minecraft allowed emojis

Ever wondered how to insert emoji in minecraft? Well turns out Minecraft supports only a subset of emoji (old one) but you can copy-paste these in it!

Screenshot of the emojis being rendered in Minecraft

These also look great on signs!

Minecraft sign with glowing effect showcasing arrows

@tomasdev
tomasdev / keybindings.json
Last active February 17, 2023 19:59
VSCode settings to allow cmd+number and next/prev tab navigation
[
{
"key": "cmd+0",
"command": "workbench.action.openLastEditorInGroup"
},
{
"key": "cmd+1",
"command": "workbench.action.openEditorAtIndex1"
},
{
# Taken from https://github.com/zeit/hyper-site/issues/31
function printcolors() {
echo
echo -e "\033[0mNC (No color)"
echo -e "\033[1;37mWHITE \033[0;30mBLACK"
echo -e "\033[0;34mBLUE \033[1;34mLIGHT_BLUE"
echo -e "\033[0;32mGREEN \033[1;32mLIGHT_GREEN"
echo -e "\033[0;36mCYAN \033[1;36mLIGHT_CYAN"
echo -e "\033[0;31mRED \033[1;31mLIGHT_RED"
@tomasdev
tomasdev / how-to-patch-examples.sh
Last active January 21, 2020 12:10
Guide to patch - diff (How to use patch)
# Create a patch file
diff -u file.old file.new > file.patch
# Apply a patch
patch < file.patch
# Create a backup before applying patch
patch -b < file.patch
# Create a versioned backup before applying patch
@tomasdev
tomasdev / gif.sh
Last active September 3, 2020 12:10
Video to GIF converter (uses ffmpeg)
#!/bin/bash
printable_colours=256
# DEFAULTS
SIZE=480
FPS=15
LENGTH=2
# Report usage
usage() {
@tomasdev
tomasdev / numbers.js
Created November 7, 2019 23:06
poorly performance pandigital fractions
var unique = n => Array.from(new Set((n+'').split(''))).length === (n+'').length
var possibilities1 = []
var possibilities2 = []
var combos = []
for (var i = 1234; i < 9876; i++) {
if (!(i+'').includes('0') && unique(i)) possibilities1.push(i)
}
for (var i = 12345; i < 98765; i++) {
@tomasdev
tomasdev / utils.js
Created November 15, 2018 00:12
Utilities for easing and animation ala jquery but vanilla javascript
// easing equations from https://github.com/danro/easing-js/blob/master/easing.js
export const EASING = {
linear: x => x,
easeOut: x => Math.sin(x * (Math.PI / 2)),
easeInOut: x => (-0.5 * (Math.cos(Math.PI * x) - 1)),
easeInOutQuint: x => (x /= 0.5) < 1 ? 0.5 * Math.pow(x, 5) : 0.5 * (Math.pow((x - 2), 5) + 2)
};
export const animate = (method, ms = 1000, ease = EASING.easeInOut) => {
const now = () => (window.performance || Date).now();
@tomasdev
tomasdev / mp4-to-gif.sh
Created February 9, 2018 17:11
MP4 to GIF using FFMPEG
# Step 1: define video
export VIDEO=name.mp4
# Step 2: create palette to have a better image quality result
ffmpeg -i $VIDEO -vf fps=15,scale=320:-1:flags=lanczos,palettegen palette.png
# Step 3: use the palette to convert the mp4 to gif
ffmpeg -i $VIDEO -i palette.png -filter_complex "fps=15,scale=400:-1:flags=lanczos[x];[x][1:v]paletteuse" $VIDEO.gif