Skip to content

Instantly share code, notes, and snippets.

@mowings
mowings / cron_docker.md
Last active May 8, 2024 11:54
Run cron on docker with job output directed to stdout

You'd like a docker container that runs cron jobs, with the output of those cron jobs going to stdout so they are accessible as docker logs. How do you do that?

Install cron, and set it up to run in the foreground

In your Dockerfile, apt-get -y install cron Use apk or whatever if you are running on alpine or another distribution Set the command or entrypoint in your Dockerfile to run cron 9n the foreground

ENTRYPOINT ["/usr/sbin/cron", "-f"]
@mowings
mowings / mermaid-pdf.md
Created May 3, 2024 14:12
Markup with embedded Mermaid to PDF on OSX

Install pandoc, basic-tex and mermaid-filter

# brew install pandoc
# brew install --cask basictex
# npm i -g mermaid-filter

# Be sure to run the path_helper in an existing shell. Otherwise pdf-latex won't be found
# eval "$(/usr/libexec/path_helper)"

Convert an markdown to pdf

@mowings
mowings / readme.md
Last active April 9, 2024 20:51
ffmpeg stream and save video from Dahua 4300s IP Camera

Use ffmpeg to stream video from a dahua 4300s to a file or files

You can use ffmpeg to directly pull frames off of a dahua 4300s at full resolution. May be a good alternative to pricey dvrs which likely cannot record at full resolution, may not work with the camera, or are prohibitevly expensive

Simple Stream to file

Simple stream to file. Full resolution

ffmpeg -loglevel debug -rtsp_transport tcp -i "rtsp://admin:admin@198.175.207.61:554/live" \

-c copy -map 0 foo.mp4

@mowings
mowings / client.go
Last active February 29, 2024 08:09
Golang Websocket JSONRPC server and client
package main
import (
"golang.org/x/net/websocket"
"log"
"net/rpc/jsonrpc"
)
// In a real project, these would be defined in a common file
type Args struct {
@mowings
mowings / readme.md
Last active February 27, 2024 20:05
Run a shell in an ecs container via SSM
@mowings
mowings / loop.sh
Last active February 4, 2024 22:28
Bash -- sleep until a specific time, like tomorrow midnight
#!/bin/bash
# Sometimes you want to sleep until a specific time in a bash script. This is useful, for instance
# in a docker container that does a single thing at a specific time on a regular interval, but does not want to be bothered
# with cron or at. The -d option to date is VERY flexible for relative times.
# See
# https://www.gnu.org/software/coreutils/manual/html_node/Relative-items-in-date-strings.html#Relative-items-in-date-strings
# For details
# ALPINE USERS: You will need to install coreutils, as the built-in busybox date does not handle -d correctly.
@mowings
mowings / pg.md
Last active November 6, 2023 13:13
Multiple versions of postgresql on the same ubuntu 16 host.

Running multiple postgresql versions on the same Ubuntu 16 host

We start with postgres 9.3 installed from a self-build deb. We'd like to upgrqde to 9.6, but that requires both versions to be installed on the server. The idea is to add the new version directly from the repository, and adjust the data and log directories so both can run at the same time. We can then run pg_upgrade or a dump/restore to upgrade to a new cluster.

Steps:

# Create new data and log directories
mkdir /postgres/pg_data.new && chown postgres:postgres /postgres/pg_data.new
mkdir /mnt/pg_log.new && chown postgres:postgres /mnt/pg_log.new
@mowings
mowings / ncq.md
Created June 24, 2019 14:28
Disable NCQ (disk command queuing in linux)

There is a kernel option to do this, if it cauxes boot issues, but otherwise in /etc/rc.local you can just add

echo 1 > /sys/block/sdb/device/queue_depth

Normally the kernel disables it after too many errors automatically, but it can cause disk timeouts until that happens. Does not have much of a performance impact on ssds.

@mowings
mowings / masq.sh
Last active September 25, 2023 20:00
script to get xet xhyve working with all vpn interfaces
#!/bin/bash
interfaces=( $(netstat -in | egrep 'utun\d .*\d+\.\d+\.\d+\.\d+' | cut -d ' ' -f 1) )
rulefile="rules.tmp"
echo "" > $rulefile
sudo pfctl -a com.apple/tun -F nat
for i in "${interfaces[@]}"
do
RULE="nat on ${i} proto {tcp, udp, icmp} from 192.168.64.0/24 to any -> ${i}"
echo $RULE >> $rulefile
done
@mowings
mowings / diagrams.md
Last active August 30, 2023 16:00
Diagrams as code