Skip to content

Instantly share code, notes, and snippets.

@mowings
mowings / gist:5d020f3a897409283636
Created August 28, 2015 14:08
imagemagick compositing
convert tmp/base.0100.png \( +clone -alpha Extract \) -channel RGB -compose Divide_Src -composite tmp/shadow.0100.png -compose Dst_Over -composite output/preview.0100.png
@mowings
mowings / default.conf
Last active August 29, 2015 14:03
Generic lxc-container nginx vhost. Access web services in an lxc container generically
# Allows you to specify just a container, or to prepend
# a port to get to something not running on 80
# ie, http://foo, or http://p9200.foo
# Obviously, you still need a host lookup mechanism for these
server {
listen 80 default_server;
server_name "~^(p(?<port>\d+)\.)?(?<container>[^\.]+)";
location / {
if ($port = '') {
set $port 80;
@mowings
mowings / gist:3f4fccc9ec4552b6aba0
Last active August 29, 2015 14:04
Stream 1080p video with raspberry pi and vlc
# This uses http at rotates my output 270 degrees (camera is in a werid position)
# I'm only doing 10 fps -- which keeps the load on the pi at around 1.5. Note that you need to
# be sure to max the framerate used by the pi with the framerate used by cvlc
sudo raspivid -o - -t 0 -w 1900 -h 1080 -rot 279 -fps 10 |cvlc -vvv stream:///dev/stdin --sout '#standard{access=http,mux=ts,dst=:8160}' :demux=h264 :h264-fps=10
# Use rtsp -- this is less firewall friendly but gracefuly trades off quality/framerate and loads up the pi less
# As above, carefully note that fps has to match on both sides. Note that the higher the fps, the lower the quality
# and visa-versa. Of course, you can also drop the resolution
sudo raspivid -o - -t 0 -w 1900 -h 1080 -rot 279 -fps 24 |cvlc -vvv stream:///dev/stdin --sout '#rtp{sdp=rtsp://:8554/}' :demux=h264 :h264-fps=24
@mowings
mowings / .profile
Last active August 29, 2015 14:04
Keep tmux from losing your ssh socket between sessions
# Predictable SSH authentication socket location.
SOCK="$HOME/.ssh/ssh-agent-sock"
if test $SSH_AUTH_SOCK && [ $SSH_AUTH_SOCK != $SOCK ]
then
ln -sf $SSH_AUTH_SOCK $SOCK
export SSH_AUTH_SOCK=$SOCK
fi
@mowings
mowings / gist:7231988a2fd6ee7089d0
Last active August 29, 2015 14:05
rsync as sudo-ed user on the remote host. Needed to preserve permissions, get special files over, etc
# Remote user must have NOPASSWD set in sudoers
# This example mirrors an entire directory
rsync --progress -avz --delete --rsync-path="sudo rsync" /path/to/sync/ user@host:/path/to/sync
@mowings
mowings / gist:fa7a0b790457e6497b73
Created October 21, 2014 19:36
Unattended ubuntu release upgrade

do-release-upgrade -f DistUpgradeViewNonInteractive

Note that any prompts might hang for 30 seconds or so before proceeding with the default answer.

@mowings
mowings / gist:017c80c188d1024ba3e7
Created June 26, 2015 21:48
golang -- get first non-loopback host ip that works on windows/linux
func externalIP() (string, error) {
addrs, err := net.InterfaceAddrs()
if err != nil {
return "", err
}
for _, addr := range addrs {
var ip net.IP
switch v := addr.(type) {
case *net.IPNet:
ip = v.IP
@mowings
mowings / multiple.json
Last active August 29, 2015 14:24
Restrict S3 bucket access to single / multiple IPs
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": [
"s3:GetObject"
],
@mowings
mowings / diskpart.txt
Created July 5, 2015 17:53
AWS Create a raid0 volume from two ephemerals. Can be run on startup with diskpart /s diskpart.txt
select disk 1
convert dynamic
select volume 2
delete volume
select disk 2
convert dynamic
select volume 2
delete volume
create volume stripe disk=1,2
format quick recommended label="My Label"
@mowings
mowings / gist:f2d93596efb85745ff08
Created August 17, 2015 20:32
Change elastic search index replica count (would also work for shards, etc)
curl -XPUT 'localhost:9200/_settings' -d '
{
"index" : {
"number_of_replicas" : 0
} }
'