Skip to content

Instantly share code, notes, and snippets.

@cahna
cahna / mergeCidrRanges.js
Last active April 12, 2020 03:59
JavaScript: Merge overlapping CIDR ranges and return as start/end IP ranges
const { Address4 } = require('ip-address');
function ipToInt(ipString) {
return ipString.split('.')
.map(str => parseInt(str, 10))
.map((octet, i) => (octet ? octet * 256 ** (3 - i) : 0))
.reduce((a, b) => (a + b));
}
function mergeCidrRanges(cidrStrings) {
@cahna
cahna / broadcast-obs-to-dev-video2.md
Last active July 10, 2022 01:20
Linux: Fake webcam device to broadcast custom content

HOWTO: Setup "fake" webcam video device for custom content

  • Once configured, select the new video device (/dev/video2 in this example) as input device for client program.
  • Example use: Broadcast custom video/images to group video chat (ex: Zoom/Skype/etc)
  • Tested working on: Manjaro Linux 5.4
  1. Install OBS and prerequisites for building plugin and kernel module:
pacman -S base-devel cmake obs-studio

Keybase proof

I hereby claim:

  • I am cahna on github.
  • I am cahna (https://keybase.io/cahna) on keybase.
  • I have a public key whose fingerprint is 7ED9 1182 506F D80C D50E 943D B3E5 2F13 A94F 8BEA

To claim this, I am signing this object:

@cahna
cahna / ansible-cli-wrapper.py
Last active July 28, 2022 00:00
Custom CLI wrapper for common ansible tasks.
#!/usr/bin/env python
#
# Run `python ansible-cli-wrapper.py -h` for usage information.
#
import os
from datetime import datetime
from tempfile import NamedTemporaryFile
import boto
@cahna
cahna / verify_mysql_replication.py
Created December 29, 2016 18:04
Check that the contents of 2 databases are identical
#!/usr/bin/env python
import sys
import ConfigParser
import MySQLdb
import click
from threading import Thread
class MySQLExtrasFileParser(ConfigParser.ConfigParser):
@cahna
cahna / parse_ps_aux.py
Last active September 27, 2023 22:39
Parse the output of `ps aux` into a list of dictionaries representing the parsed process information from each row of the output.
#!/usr/bin/python
# -*- coding: utf-8 -*-
import pprint
import subprocess
def get_processes():
"""
Parse the output of `ps aux` into a list of dictionaries representing the parsed
@cahna
cahna / proxy.py
Last active August 29, 2015 14:23
Simple Python Proxy
# -*- coding: ascii -*-
from webob.dec import wsgify
from wsgiproxy import HostProxy
from wsgiref.simple_server import make_server
@wsgify
def application(req):
return HostProxy('http://example.com')
@cahna
cahna / ansible-aur-pkg-installer.md
Last active September 11, 2022 06:26
download, build, and install aur packages with ansible

About

When using ArchLinux, I typically prefer to use an AUR helper like pacaur or yaourt to automate away the process of installing a community package.

Ansible's pacman module is great, but it doesn't support AUR packages or pacman's -U flag. Installing AUR packages with Ansible seemed to be left as an exercise to the user, and since AUR helpers do not come with a fresh Arch install, I

@cahna
cahna / ENV.moon
Created July 6, 2014 09:24
Moonscript - read environment variable shorthand
-- Package that helper into the worlds shortest module.
-- Usage: import HOME, SHELL, EDITOR from require 'ENV'
setmetatable {}, __index: (k) => os.getenv k
@cahna
cahna / add-pathogen-submodules.sh
Last active March 3, 2017 11:13
manage installed pathogen plugins as git submodules within dofiles repo
# cd into your dotfiles repo and run this to add all of your
# installed pathogen plugins as submodules of your dotfiles repo:
ls ~/.vim/bundle \
| xargs -I% echo "grep -m1 -oP 'https[^\ ]+' <(cd ~/.vim/bundle/% && git remote -v show)" \
| bash \
| xargs -n1 git submodule add