Skip to content

Instantly share code, notes, and snippets.

@nathansgreen
nathansgreen / array_position.sql
Created January 5, 2018 16:57
PostgreSQL <9.5 array_position function
-- The array_position function was added in Postgres 9.5.
-- For older versions, you can get the same behavior with this function.
create function array_position(arr ANYARRAY, elem ANYELEMENT, pos INTEGER default 1) returns INTEGER
language sql
as $BODY$
select row_number::INTEGER
from (
select unnest, row_number() over ()
from ( select unnest(arr) ) t0
) t1
@nathansgreen
nathansgreen / jq-examples.md
Last active October 26, 2018 16:10
Stuff I've had to do with jq

Simple things to do using jq

# turn a delimted string into an array:
echo '"2368;3924"' | jq 'split(";")
[
  "2368",
  "3924"
]
@nathansgreen
nathansgreen / perl-recent-version-compat.patch
Last active October 30, 2019 15:25 — forked from xywei/patch.txt
A patch for automake to compile it with later versions of Perl
Allow recent versions of Perl to compile automake.
For Yocto. Tested on poky (krogoth branch).
From https://gist.github.com/xywei/03b546054f0d2e2f76c5ac530c88268a
--- a/bin/automake.in 2015-01-06 03:25:55.000000000 +0800
+++ b/bin/automake.in 2017-07-26 13:58:07.086205701 +0800
@@ -3878,7 +3878,7 @@
sub substitute_ac_subst_variables
{
my ($text) = @_;
@nathansgreen
nathansgreen / setup-unifi-macos.sh
Last active August 23, 2022 12:07
UniFi Network Controller Setup for MacOS
#!/bin/sh
# https://community.ui.com/questions/Unifi-Controller-5-11-50-on-Mac-OS-X-Catalina-fails-to-start-/2fde6f63-b0ac-43a0-83f7-5cf43ba3d40f?page=2
brew cask install homebrew/cask-versions/adoptopenjdk8
brew cask install ubiquiti-unifi-controller
export CLASSPATH=/Applications/UniFi.app/Contents/Java/*
cd /Applications/UniFi.app/Contents/Resources
java com.ubnt.ace.Launcher start &
@nathansgreen
nathansgreen / find_iphone_uuid.sh
Created April 24, 2020 16:22
Find iPhone device UUID/UDID
#!/usr/bin/env sh
system_profiler SPUSBDataType 2>/dev/null \
| sed -n '/iPhone/,/Serial/p' \
| grep "Serial Number:" \
| awk -F ": " '{print substr($2,1,8)"-"substr($2,9,24)}'
@nathansgreen
nathansgreen / README.md
Last active May 15, 2020 04:50
UniFi Reserved IP for Access Point using DHCP

Read the last paragraph if you want a simpler solution.

The current (May 2020) controller interface doesn't give you a clear ability to reserve IP addresses for wireless access points. Instead it gives you the option of statically entering all of the information. You can use the customization features of config.gateway.json to do what the GUI does not let you do.

To figure out your network name, you'll probably want to ssh into your USG and then get your shared-network-name by running the following command: mca-ctrl -t dump-cfg. Once you have a network name and its associated subnet, you can enter in the static

@nathansgreen
nathansgreen / usg-commands.md
Last active November 6, 2022 00:17
USG CLI commands

Ubiquit Security Gateway CLI Commands

Random commands I've used for various things.

mca-ctrl -t dump-cfg

renew dhcp interface eth0

show interfaces

@nathansgreen
nathansgreen / README.md
Last active May 19, 2020 21:23
USG Disable DNS over HTTPS on local LAN with dnsmasq

I wanted a way to disable DNS over HTTPS so I can control DNS activity on my local network. I also block unauthorized outbound DNS requests with firewall rules.

The biggest limitation of this approach is the need to put all forwarding options in the config. Leaving out options, especially the 'server=' can break DNS on your whole network, so be careful. SSH into your USG and run mca-ctrl -t dump-cfg to find your current options and use them to replace the values in the file here.

I recommend running cat /etc/dnsmasq.conf before and after applying this config to see if you are missing things you need.

@nathansgreen
nathansgreen / renew.udhcp.sh
Created May 19, 2020 21:48
Renew DHCP lease on Alpine Linux (using udhcp as the client)
#!/usr/bin/env sh
pkill -USR1 udhcpc
@nathansgreen
nathansgreen / AccessLogValve.java
Last active July 23, 2021 23:05
Send Embedded Tomcat Access Logs to Application Logger
@lombok.extern.log4j.Log4j2
public class AccessLogValve extends
org.apache.catalina.valves.AbstractAccessLogValve {
@Override
protected void log(java.io.CharArrayWriter message) {
log.info(message.toString());
}
}