Skip to content

Instantly share code, notes, and snippets.

@tdr2d
tdr2d / utils.js
Created February 16, 2021 18:25
Javascript vanilla utils
function serializeForm(form) { // Serialize inputs values into json object
var obj = {};
var formData = new FormData(form);
for (var key of formData.keys()) {
obj[key] = formData.get(key);
}
return obj;
};
@tdr2d
tdr2d / helm_usage.md
Created November 5, 2020 17:07
Helm 3 Usage Cheatsheet

Helm Usage Cheatsheet

1. Generate a new helm chart

helm create portail-web

This will generate a helm chart structured like:

portail-web/
  Chart.yaml
 values.yaml
@tdr2d
tdr2d / Makefile
Last active November 29, 2024 14:29
Linux useful bash commands
help: ## Show this help
@grep -E "^[a-z0-9_-]+:|^##" Makefile | sed -E 's/([a-z0-9_]+):.*##(.*)/\1:\2/' | column -s: -t | sed -e 's/##//'
##
## Utils
sync: ## sync
rsync -azP --exclude={.git/,build}./ [email protected]:/root/engine
sync_gcp: ## sync in gcp VM (pre-req gcloud compute config-ssh)
rsync -Pavz --exclude={'data','*.pyc','prototypes','.git','.pytest_cache'} ./ sshuser@`gcloud compute instances list --filter="name=elasticsearch" --format "get(networkInterfaces[0].accessConfigs[0].natIP)"`:~/horizon
@tdr2d
tdr2d / youtube-dl.sh
Last active January 2, 2020 16:41
Youtube-dl, Udemy-dl cheat code
#!/usr/bin/env bash
set -e
### Youtube
URLS=(
"https://www.youtube.com/watch?v=YbH1E2R9TOM"
"https://www.youtube.com/watch?v=fdNYW23Vm_c"
"https://www.youtube.com/watch?v=gh0faLFKl3w"
"https://www.youtube.com/watch?v=Homukj0sBYU"
@tdr2d
tdr2d / sort_algorithms.py
Last active August 19, 2019 11:03
Quick sort, and Insert sort, Bubble sort, Merge sort algorithms
#!/usr/bin/env python
# Using a pivot
# Place value lower than pivot to the left, greater to the right
# Sort left and right recursively
def quick_sort(arr):
less, equal, greater = [], [], []
if len(arr) > 1:
pivot = arr[0]
@tdr2d
tdr2d / .bashrc
Last active July 23, 2023 10:22
Personal .bashrc utilities
# General
unameOut="$(uname -s)"
case "${unameOut}" in
Linux*) machine=Linux;;
Darwin*) machine=Mac;;
CYGWIN*) machine=Cygwin;;
MINGW*) machine=MinGw;;
*) machine="UNKNOWN:${unameOut}"
esac
@tdr2d
tdr2d / docker-mysql.sh
Created August 27, 2018 14:56
Docker runner for mysql, accessible from host
#!/usr/bin/env bash
sudo docker run --rm -p 3306:3306 --name=mysql \
-e MYSQL_ROOT_PASSWORD="1234" \
-e MYSQL_DATABASE="test" \
-e MYSQL_USER="test" \
-e MYSQL_PASSWORD="1234" \
-d mysql/mysql-server --default-authentication-plugin=mysql_native_password
sudo docker logs -f mysql
@tdr2d
tdr2d / web_worker_function_wrapper.js
Last active August 24, 2018 14:00
Run a function into a web worker instance
/**
* @argument callback function
* @argument arg argument
* @argument onMessageCallback function
* usage: runInWorker(function(e){return JSON.parse(e);}, '{"name": "toto"}', console.log);
**/
function runInWorker(callback, arg, onMessageCallback){
var blob = new Blob(['onmessage=function(_e){postMessage('+ callback.toString() + '(_e)); close();']);
var worker = new Worker(URL.createObjectURL(blob));
worker.onmessage = onMessageCallback;
@tdr2d
tdr2d / docker_cleanup.sh
Last active March 10, 2021 01:37
Remove all unused docker containers, remove all docker volumes, cleanup networks
#!/usr/bin/env bash
removevolumes() {
sudo docker volume rm $(sudo docker volume ls -qf dangling=true)
sudo docker volume ls -qf dangling=true | xargs -r sudo docker volume rm
}
removenetwork() {
sudo docker network ls
sudo docker network ls | grep "bridge"
@tdr2d
tdr2d / ffmpeg-VP9-encoder.sh
Last active November 9, 2022 17:13
ffmpeg - convert videos using the VP9 codec - prepare multiple resolutions for DASH
#!/usr/bin/env bash
# Prepare the videos to be used over http with the MPEG-DASH protocol
# The vp9 codec is used for the videos because h265 is not supported by chrome and h264 is too big
# This script generates webm files
## DOCS
# https://developers.google.com/media/vp9/settings/vod/
# https://developer.mozilla.org/en-US/docs/Web/HTML/DASH_Adaptive_Streaming_for_HTML_5_Video
# http://wiki.webmproject.org/adaptive-streaming/instructions-to-playback-adaptive-webm-using-dash