Skip to content

Instantly share code, notes, and snippets.

View RickyCook's full-sized avatar
🏳️‍🌈

Ricky Cook RickyCook

🏳️‍🌈
View GitHub Profile
@RickyCook
RickyCook / keybase.md
Last active August 29, 2015 14:06
Keybase

Keybase proof

I hereby claim:

  • I am rickycook on github.
  • I am rickycook (https://keybase.io/rickycook) on keybase.
  • I have a public key whose fingerprint is 1255 FA8D 8DE3 0534 D431 4564 79D6 68B9 12F3 6735

To claim this, I am signing this object:

@RickyCook
RickyCook / rsync.yaml
Created October 27, 2014 05:45
Ansible rsync changed status
# Uses the rsync change summary to figure out how many things changed, and uses that
# to tell Ansible if something changed or not
- name: sync hieradata
shell: rsync --delete -ri "/tmp/repo/hieradata" "/etc/puppet/hieradata" | awk '{print $1}' | grep -vE '..\.\..\.\.\.\.' | wc -l
register: hieradata_changes
changed_when: "hieradata_changes.stdout|int != 0"
@RickyCook
RickyCook / multiprocessing_latency.py
Last active August 29, 2015 14:08
Test the "latency" of different ways to trigger multiprocessing start
"""
Test the "latency" of different ways to trigger multiprocessing start.
This will essentially create a multiprocessing `Process` object and measure the
time from when we tell that process to start processing (not necessarily
`Process.start`) until the time that the process picks up the request to start.
This is done in several ways:
- Without a blocker: the time is recorded, then the `Process.start` method
@RickyCook
RickyCook / file_match.py
Last active August 29, 2015 14:08
Pytho one line file match in directory
# Find files in the current directory that do not contain a '.'
(item for sublist in ((os.path.join(r,f) for f in fs if '.' not in f) for r, _, fs in os.walk('.')) for item in sublist if os.path.isfile(item))
# Add '.log' to the end of any file that has no extension. Probably easier with `rename` command :|
[shutil.move(src, '%s.log' % src) for src in (item for sublist in ((os.path.join(r,f) for f in fs if '.' not in f) for r, _, fs in os.walk('.')) for item in sublist if os.path.isfile(item))]
@RickyCook
RickyCook / git_sync.sh
Last active August 29, 2015 14:13
Rsync a git repo to its remote. For when you want to sync, but not commit
#!/bin/bash
remote_name="$1"
: ${remote_name:="origin"}
git_root="$(cd "$(git rev-parse --show-toplevel)"; pwd)/"
rsync_dest=$(git remote -v | grep "^$remote_name\s.*\(push\)" | awk '{print $2}')
echo "Remote name: $remote_name"
echo "Repo root: $git_root"
echo "Repo dest: $rsync_dest"
@RickyCook
RickyCook / bookmarklet.js
Last active August 29, 2015 14:16
Fill AWS tags based on a JSON hash, obtained from user prompt
(function($, c) {
var rootObject = $('table:visible:contains("Create Tag")').first(),
createButton = $('button:contains("Create Tag")', rootObject).first(),
inputsKey = $('input[name="key"]', rootObject),
inputsValue = $('input[name="value"]', rootObject),
tags = $.parseJSON(prompt('JSON tag values')),
tagsKeys = Object.keys(tags);
if (tagsKeys.length > inputsKey.length) {
for (var i = 0; i < tagsKeys.length - inputsKey.length; i++) {
@RickyCook
RickyCook / README.md
Last active August 29, 2015 14:19
LastPass to 1password cleanup

LastPass adds category fields for everything; even things without categories! It will add a "grouping: (none)" for these passwords. This script takes a data.1pif export file (File -> Export -> All Items in 1password) and strip out this useless extra data. When done, import the data-out.1pif, and the fields will be removed. Data is updated in-place in 1password, so there will be no duplicates or anything nasty like that (thanks 1password!)

@RickyCook
RickyCook / cloud-config
Last active August 29, 2015 14:21
cloud-config
#cloud-config
coreos:
units:
- name: 00-eth0.network
runtime: true
content: |
[Match]
Name=eth0
[Network]
@RickyCook
RickyCook / Command.md
Last active November 7, 2023 06:55
Using socat to forward new ports via STDIO in a running Docker container

What?... Why?

Imagine you're messing around in a container, and you install some stuff, add some config, and now it's time to load up your client and check it out! Oh wait, you forgot to forward ports when you created the container! Fear not, all is not lost, for in the world of pipes, and streams, there is always a way to do something disgusting.

The Dockerfile

Example Dockerfile included will install Nginx, and socat in a container, and make Nginx run in foreground mode. To build, and run:

What.....?

TL;DR tunnels a socket from multiple hosts to a single host, creating sockets on the remote end automatically and encrypting all traffic over the network.

Creates a server that listens on 4433. All traffic is encrypted with OpenSSL using both client and server keys. When a client connects, a new random UNIX socket is created on the host and waits for connection. When an application connects to the socket on the server, it can talk to the socket on the client as if it were a local socket.

In this case, we're using a Docker socket, but this is easy to change.

On the server

$ ./server.sh server