Skip to content

Instantly share code, notes, and snippets.

@slhck
slhck / ffmpeg-progress.py
Last active July 10, 2023 11:29
Run an ffmpeg command and get the progress in percent
#!/usr/bin/env python3
#
# Run an ffmpeg command with a progress iterator
# Author: Werner Robitza
# Based on: https://gist.github.com/Hellowlol/5f8545e999259b4371c91ac223409209
# For a library version, see https://pypi.org/project/ffmpeg-progress-yield/
# License: MIT
import subprocess
import re
@diyism
diyism / wireguard_config.txt
Last active February 13, 2023 11:26
wireguard config
$ sudo apt-get install linux-headers-$(uname -r)
$ sudo add-apt-repository ppa:wireguard/wireguard
$ sudo apt-get update
$ sudo apt-get install wireguard
$ sudo modprobe wireguard
$ sudo mkdir /etc/wireguard
$ (umask 077 && printf "[Interface]\nPrivateKey = " | sudo tee /etc/wireguard/wg0.conf > /dev/null)
$ wg genkey | sudo tee -a /etc/wireguard/wg0.conf | wg pubkey | sudo tee /etc/wireguard/publickey
$ sudo nano /etc/wireguard/wg0.conf
@alanhamlett
alanhamlett / oauth_example_decorator.py
Created July 12, 2018 02:22
OAuth permission decorator code snippet from WakaTime blog post
""" Example for Blog Post:
https://wakatime.com/blog/34-part-3-flask-api-decorators-and-helpers
"""
def oauth(required_scopes=[]):
def wrapper(func):
@wraps(func)
def inner(*args, **kwargs):
# don't check oauth tokens if user already logged in with session cookie
private fun getAllWifiSubnetIpAddresses(): List<InetAddress> {
val wifiMgr = getSystemService(WIFI_SERVICE) as WifiManager
val wlanAddr = NetworkUtils.intToInetAddress(wifiMgr.dhcpInfo.ipAddress)
return NetworkInterface.getNetworkInterfaces().toList()
.flatMap { it.interfaceAddresses }
.filter { it.address == wlanAddr }
.map { SubnetUtils(it.address.hostAddress + "/" + it.networkPrefixLength) }
.flatMap { it.info.allAddresses.asList() }
.map { Inet4Address.getByName(it) }
@vi
vi / hextobin.c
Created August 25, 2017 15:10
Hex string to byte buffer in C
// Based on https://stackoverflow.com/a/23898449/266720
void tallymarker_hextobin(const char * str, uint8_t * bytes, size_t blen)
{
uint8_t pos;
uint8_t idx0;
uint8_t idx1;
// mapping of ASCII characters to hex values
const uint8_t hashmap[] =
{
@Freaky
Freaky / borg-backup.sh
Last active February 20, 2023 20:39
Simple BorgBackup script
#!/bin/sh
#
# borg-backup.sh - BorgBackup shell script
#
# Author: Thomas Hurst <tom@hur.st>
#
# No warranty expressed or implied. Beware of dog. Slippery when wet.
# This isn't going to be your *only* backup method, right?
#
# Synopsis:
@JoeUX
JoeUX / compile-nginx.sh
Last active March 5, 2022 18:36 — forked from tollmanz/compile-nginx.sh
Optimized nginx compilation flags for modern CPUs, faster math, and LTO. This should be much faster than vanilla nginx builds. Still testing.
# Install dependencies
#
# * checkinstall: package the .deb
# * libpcre3, libpcre3-dev: required for HTTP rewrite module
# * zlib1g zlib1g-dbg zlib1g-dev: required for HTTP gzip module
apt-get install checkinstall libpcre3 libpcre3-dev zlib1g zlib1g-dbg zlib1g-dev && \
mkdir -p ~/sources/ && \
# Compile against OpenSSL to enable NPN. I updated this block to get the latest 1.0.2h release. It's critical that OpenSSL be up to date.
anonymous
anonymous / colour_ring.pde
Created May 19, 2016 15:14
// by davey whyte aka @beesandbombs
void setup(){
size(600,520,P3D);
colorMode(HSB,1);
noStroke();
}
float R = 160, r = 55;
int N = 720;
@myusuf3
myusuf3 / delete_git_submodule.md
Created November 3, 2014 17:36
How effectively delete a git submodule.

To remove a submodule you need to:

  • Delete the relevant section from the .gitmodules file.
  • Stage the .gitmodules changes git add .gitmodules
  • Delete the relevant section from .git/config.
  • Run git rm --cached path_to_submodule (no trailing slash).
  • Run rm -rf .git/modules/path_to_submodule (no trailing slash).
  • Commit git commit -m "Removed submodule "
  • Delete the now untracked submodule files rm -rf path_to_submodule
@pelegm
pelegm / round.go
Last active January 5, 2018 13:48 — forked from DavidVaini/round.go
package main
import (
"log"
"math"
)
func Round(val float64, roundOn float64, places int ) (newVal float64) {
var round float64
pow := math.Pow(10, float64(places))