I was recently playing around with some voice over IP (VoIP) applications. SIP is a beast of a complex protocol, and I found surprisingly little good simple information on the web. I found the pjsua CLI app to be the least bad SIP client that works on Linux. Unfortunately a prebuilt version isn't available in Ubuntu's repos as of writing. Luckily, it's pretty easy to compile pjsua: # A few deps…
For a project where I was plotting some locations using Matplotlib, I needed a way to get a PNG map from a bounding box lat-long pair. Here's a Python function I came up with. from os import listdir, mkdir from os.path import exists from PIL import Image from random import uniform from time import sleep from urllib.request import Request, urlopen import math # Similar to…
Here's a simple Geohash encode/decode implementation. The decoding function pretty closely follows the technique layed out on the Geohash Wikipedia entry . from fractions import Fraction """ First decode the special geohash variant of base32 encoding. Each encoded digit (0-9-b..z) (not continuous abc) is a 5 bit val 0,1,2...,30,31. In the resulting bitstream, every second bit is now for latitude…
This is an implementation of the Lossy Counting Algorithm described in Manku and Motwani's 2002 paper "Approximate Frequency Counts over Data Streams" . It is an algorithm for estimate elements in a stream whose frequency count exceeds a threshold, while using only limited memory. For example for video view counts on something like YouTube, finding which videos that each constitute more than 3% of…
These are the commands accompanying the video tutorial I've made on how to create a local Kubernetes cluster and deploy a simple stateless app from code, end to end. You can find the video tutorial here: https://youtu.be/MZr9Ls38uPw . # # Install k3s # curl -sfL https://get.k3s.io | K3S_CLUSTER_INIT=1 INSTALL_K3S_EXEC="--disable=servicelb" sh - cat /var/lib/rancher/k3s/server/node-token # Run on…
I was trying out MetalLB with a bare-metal Kubernetes cluster (using the k3s distro), and was hitting issues with requests to the cluster IP seemingly randomly giving me "destination unreachable". I noticed with Wireshark that I was getting a ton of "gratuitous" ARP packets. Every few seconds. I inspected MetalLB's logs with the following command: kubectl logs -lapp=metallb --namespace…
Here's a bash function for your bash profile that continuously prints some basic checks I usually do while diagnosing network issues: Show my LAN IPs Show the default gateway IP Ping the default gateway IP Ping 8.8.8.8 (Google's public DNS servers) DNS resolve amazon.com Ping amazon.com Get my WAN IP by curl'ing ifconfig.me Tested on Ubuntu 20.04 and MacOS Catalina function pingg() { while true;…
Here's a procedure I've come up with to fully upgrade a diskless setup of Alpine Linux on a running Raspberry Pi. It's not pretty, but seems gets the job done, based on the tests I did. I tested this procedure on each version from 3.3 to to 3.12. The system I tested on had a working setup of Apache2 with PHP, as well as Samba. Here's the result of the testing. Started with v3.3. Confirmed 3.3 to…
Here's a quick and dirty way to add shortcut keys to Google Drawing. It probably only works in Chrome. It's a JavaScript snippet that can be run in the context of the Google Drawing page in order to automate clicking on the toolbar buttons. The keys this code adds are: Alt-A: Arrow Alt-L: Line Alt-B: Rectangle (box) Alt-C: Cylinder Alt-X: Text box Here's a bookmarklet with the script: GDraw…
This post describes an approach to let your Linux machine behind a NAT be reachable from the public internet, using a cheap VPS and Wireguard. It's similar to this post in Ralph's Blog , but with with one distinction: it preserves the source IP of the incoming connection. This may be important depending on your use. For me, I was running a PHP web app for which I needed the $_SERVER["REMOTE_ADDR"]…
As of writing (Alpine Linux v3.12), the WireGuard kernel module is not part of the Alpine Linux Raspberry Pi kernel by default. There's a community module called wireguard-rpi2, but it doesn't work in a system set up in diskless mode. The reason it doesn't work, is because in diskless mode on a Raspberry Pi, Alpine Linux uses a read-only loopback file system to store its kernel modules. This…
I recently faced the problem of requiring negative lookbehinds in a regex engine that does not support them (Golang's Regexp package, RE2, and Hyperscan). For example, say you want to match the string "def" except if it is preceeded by "abc". In PCRE using negative lookbehinds you could achieve this with the regex: (?<!abc)def But this will not work in all regex engines, so I needed an…
I enjoy using the Foreflight app when flying in the US, and recently discovered that it can work very well in Europe as well. They have a guide on how to import custom charts , and it turned out to be very easy. PDFs of aviation charts for Denmark can be downloaded from the AIM and converted via the tool described in Foreflights guide. Here are a few charts current as of June 2018. Denmark ,…
Goal: A VM in the cloud or similar running an Ubuntu desktop with your dev tools (Sublime Text, Visual Studio Code, etc.), that you can remotely connect to and comfortably work on, spanning all your local monitors. Like this: We'll use TigerVNC. RealVNC 4 that comes with Ubuntu 16.04 can also be used, but it lacks the X extensions that are required for a well behaved multi monitor setup. Also,…
I had trouble deleting C:\ProgramData\Docker on Docker for Windows using Windows containers. This is because it contains a full Windows directory layout, with all system files and special permissions and flags. Here's a Powershell snippet to get a file hierarchy on Windows into a state where it can be deleted. $ErrorActionPreference = "stop" function reallyDelete($d) { function…
Here's a program that asks you every hour what you are doing, so you end up with a diary at the end of the day. It saves your input to a text file WhatAmIDoing.txt in the same folder you put the exe. The "ask every hour" button creates a Windows Scheduled Task. Note that if you move the location of the exe file, you will need to click the "ask every hour" button again.…
I needed a simple mailing list manager for a sports club I'm in. We wanted it to be of the type where an administrator manages the lists (not the type where any random person can subscribe him- or herself). Couldn't find any decent looking free service offering this, so I decided to make one: mailgroup.io . These are its features: Free for noncommercial use. Your own custom domain. Or…
Here's a soundpack for the FrSky Taranis, based on the original, but run through Melodyne so it sounds like GLaDOS from Portal: https://acoby.com/fpv/gladosStyleTaranisSounds.zip
Here's a heap sort implementation in C#: class HeapSort { public void Sort(int[] a) { // Turn the array into a max heap for (int i = (a.Length / 2) - 1; i >= 0; i--) { MaxHeapify(a, i, a.Length); } // Remove the largest element from the max heap and put it on the end, // and then max heapify the heap which is now 1 smaller for (int i = a.Length - 1; i >= 1; i--) { Swap(a, 0, i); MaxHeapify(a, 0,…
Inspired by Kartik Kukreja's implementation , but storing all data in a tree node class, rather than an array. I find it a lot easier to comprehend this way. class SegmentTreeNode { public int aggregateValue; public SegmentTreeNode left; public SegmentTreeNode right; public int origLowIndex; public int origHighIndex; } class SegmentTreeTest { public static SegmentTreeNode buildSegmentTree(int[] a,…
I recently bought a VoCore . It came pre-flashed with OpenWRT Chaos Calmer (as of 2015-03-16). OpenWRT was configured as a wireless access point, bridging with the ethernet port. Here is what I did to get it to a configuration where it acts as a NAT'ing wireless access point, similar to most consumer routers/access points: SSH'ed to its default IP of 192.168.61.1. Edited /etc/config/network: ...…
Here's a way of doing a super simple TCP proxy in C#. Warning: this should only be used for testing purposes, as it will leak threads. using System; using System.Net; using System.Net.Sockets; using System.Threading; class Program { static void ProxyStream(string stream1name, NetworkStream stream1, string stream2name, NetworkStream stream2) { var buffer = new byte[65536]; try { while (true) { var…
Here's a convenient way to get a command prompt running as Network Service. This is useful for troubleshooting authentication issues for services running as Network Service. Get Psexec from http://live.sysinternals.com/psexec.exe . Run: psexec -u "NT AUTHORITY\Network Service" -i cmd Or, if you prefer PowerShell: psexec -u "NT AUTHORITY\Network Service" -i powershell Or, if you prefer PowerShell,…
Here's a convenient way of creating a WCF net.tcp client for a quick test. It uses PowerShell to compile C# code to an exe on the fly. Note that the interface can be partial (only containing the method you want to call). $source = ' using System; using System.ServiceModel; [ServiceContract(Namespace = "http://example.com/SomeSchema")] public interface ISomeService { [OperationContract] bool…