Skip to content

Instantly share code, notes, and snippets.

curl "https://www.duckdns.org/update?domains=###&token=***&ipv6=`curl -s6 ifconfig.co`&verbose=true"
@meehatpa
meehatpa / ffmpeg_cheatsheet
Last active January 15, 2023 12:18
ffmpeg cheatsheet
# Video from text for x duration
ffmpeg -f lavfi -i \
color=size=1920x1080:duration=10:rate=60:color=black \
-vf "drawtext=fontfile=/path/to/font.ttf:fontsize=14:fontcolor=gray:x=(w-text_w)/2:y=(h-text_h)/2:text='Stack Overflowing'" \
output.mp4
# Add text to existing video
ffmpeg -i output.mp4 \
-vf "drawtext=text='Centered Text':x=(w-text_w)/2:y=(h-text_h)/2:fontsize=24:fontcolor=gray" -c:a copy output2.mp4
@meehatpa
meehatpa / WAphotos.sh
Last active December 31, 2022 08:49
Exiftool
# WA photos/videos do not have exif data embedded, so first fill them
exiftool '-alldates<${filename;$_=substr($_,0,12)} 00:00:00' SOURCE
# Now organize them into YY/YY-mm structure
exiftool -r -d %Y/%Y-%m '-directory<createdate' "-directory<datetimeoriginal" SOURCE
@meehatpa
meehatpa / pre-push
Created March 25, 2021 14:21
git pre-push hook to check clang-format
for commit in $(git rev-list origin/master..HEAD)
do
err=`git --no-pager show $commit | clang-format-diff-10 -p1`
if [ -n "$err" ]
then
# echo "$err"
echo >&2 "\"`git log --oneline -1 $commit`\" failed clang-format check!"
exit 1
fi
done
@meehatpa
meehatpa / settings.json
Last active June 5, 2021 15:23
Change /etc/systemd/system/multi-user.target.wants/transmission-daemon.service to pick settings.json via ExecStart=/usr/bin/transmission-daemon -f --log-error -g <settings_dir>
{
"alt-speed-down": 50,
"alt-speed-enabled": false,
"alt-speed-time-begin": 540,
"alt-speed-time-day": 127,
"alt-speed-time-enabled": false,
"alt-speed-time-end": 1020,
"alt-speed-up": 50,
"bind-address-ipv4": "0.0.0.0",
"bind-address-ipv6": "::",
#!/bin/bash
set -e
prefix=/mnt/usb/
# delete dir with size < 5 MB
#DIRRM=`find /mnt/usb -mindepth 1 -maxdepth 1 -type d -exec du -ks {} + | awk '$1 <= 50000' | cut -f 2-`
#IFS='
#'
#for i in $DIRRM; do
# rm -rf $i
@meehatpa
meehatpa / combine.py
Created February 1, 2021 10:54
Combine chrome trace json
import json
import glob
import os
import re
def clean_json(string):
string = re.sub(",[ \t\r\n]+}", "}", string)
string = re.sub(",[ \t\r\n]+\]", "]", string)
string = re.sub(",$", "", string)
@meehatpa
meehatpa / CMakeLists.txt
Created September 22, 2020 11:26
Sample CMakeLists.txt to use add_custom_command
cmake_minimum_required(VERSION 3.16)
project(testcmake)
# Build only when gen.g gets modified
add_custom_command(
OUTPUT ${PROJECT_SOURCE_DIR}/gen
COMMAND ${CMAKE_COMMAND} -E touch ${PROJECT_SOURCE_DIR}/gen
DEPENDS "${PROJECT_SOURCE_DIR}/gen.g"
)
@meehatpa
meehatpa / http_get_cmd.py
Last active August 24, 2020 07:06
Raspberry pi http server to run shell command using http get from client
#!/usr/bin/python3
# Example:
# http://192.168.1.100:8080/?cmd=ls%20-l&cmd=date
#
from http.server import BaseHTTPRequestHandler, HTTPServer
from urllib.parse import parse_qs
import subprocess
class Handler(BaseHTTPRequestHandler):
def do_HEAD(self):
@meehatpa
meehatpa / lru.cpp
Created August 17, 2020 05:48
LRU cache cpp implementation
#include <iostream>
#include <list>
#include <map>
class cache {
public:
cache(int s) : size(s) {};
void put(int k) {