Skip to content

Instantly share code, notes, and snippets.

@techraf
techraf / parse_yaml.sh
Created June 30, 2018 10:11 — forked from pkuczynski/parse_yaml.sh
Read YAML file from Bash script
#!/bin/sh
parse_yaml() {
local prefix=$2
local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
sed -ne "s|^\($s\)\($w\)$s:$s\"\(.*\)\"$s\$|\1$fs\2$fs\3|p" \
-e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 |
awk -F$fs '{
indent = length($1)/2;
vname[indent] = $2;
for (i in vname) {if (i > indent) {delete vname[i]}}
@techraf
techraf / dnscrypt-captive-portal-monitor-daemon
Created July 1, 2016 23:02
capitive portal autoswitching for dnscrypt
#!/usr/bin/env ruby
# /usr/local/libexec/run-continuously
DELAY_BETWEEN_INTERNET_CHECKS = 4 # seconds
TIMES_BEFORE_GC = 100 # 100 * 5 ~ 10 minutes
if Process.uid != 0
$stderr.puts "Must be root to run #{$0}"
exit 1
end
@techraf
techraf / gist:02c4b22c986327bf063e
Created March 19, 2016 14:07 — forked from datagrok/gist:2199506
Virtualenv's `bin/activate` is Doing It Wrong

Virtualenv's bin/activate is Doing It Wrong

I'm a Python programmer and frequently work with the excellent [virtualenv][] tool by Ian Bicking.

Virtualenv is a great tool on the whole but there is one glaring problem: the activate script that virtualenv provides as a convenience to enable its functionality requires you to source it with your shell to invoke it. The activate script sets some environment variables in your current environment and defines for you a deactivate shell function which will (attempt to) help you to undo those changes later.

This pattern is abhorrently wrong and un-unix-y. activate should instead do what ssh-agent does, and launch a sub-shell or sub-command with a modified environment.

Problems

@techraf
techraf / pedantically_commented_playbook.yml
Created October 2, 2015 23:35 — forked from phred/pedantically_commented_playbook.yml
Insanely complete Ansible playbook, showing off all the options
---
# ^^^ YAML documents must begin with the document separator "---"
#
#### Example docblock, I like to put a descriptive comment at the top of my
#### playbooks.
#
# Overview: Playbook to bootstrap a new host for configuration management.
# Applies to: production
# Description:
# Ensures that a host is configured for management with Ansible.
@techraf
techraf / pi_qemu.sh
Last active August 29, 2015 14:27 — forked from JasonGhent/pi_qemu.sh
OSX raspberry pi emulation via QEMU
# pulled from http://xecdesign.com/qemu-emulating-raspberry-pi-the-easy-way/
# expanded via http://superuser.com/questions/690060/how-to-enable-network-with-a-raspberry-pi-emulated-on-qemu
# tested with 2015-02-16-raspbian-wheezy.zip on OSX Mavericks
# also with 2015-05-05-raspbian-wheezy.zip on OSX Yosemite
# and qemu: stable 2.4.0 (bottled), HEAD (current as of 2015-08-17)
# OSX terminal
brew install qemu
@techraf
techraf / git-branch-between-different-repositories.md
Last active August 29, 2015 14:27 — forked from jcaraballo/git-branch-between-different-repositories.md
How to fork a github repository in bitbucket

#Create bitbucket branch

##Create local branch

$ git checkout -b sync
Switched to a new branch 'sync'
$ git branch
  master
* sync
When running "pip install m2crypto" in a virtualenv, I got the following error:
Downloading/unpacking m2crypto
Running setup.py egg_info for package m2crypto
Installing collected packages: m2crypto
Running setup.py install for m2crypto
building 'M2Crypto.__m2crypto' extension
swigging SWIG/_m2crypto.i to SWIG/_m2crypto_wrap.c
swig -python -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -I/usr/include -includeall -o SWIG/_m2crypto_wrap.c SWIG/_m2crypto.i
import os
import time
import boto
import boto.manage.cmdshell
def launch_instance(ami='ami-7341831a',
instance_type='t1.micro',
key_name='paws',
key_extension='.pem',
key_dir='~/.ssh',
@techraf
techraf / 0_reuse_code.js
Created August 2, 2014 01:54
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
Windows iso files (mount, create)