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]}}
# https://stackoverflow.com/a/42544963
# using numfmt on GNU
git rev-list --objects --all | git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' | sed -n 's/^blob //p' | sort --numeric-sort --key=2 | cut -c 1-12,41- | numfmt --field=2 --to=iec-i --suffix=B --padding=7 --round=nearest
# using gnumfmt on MacOS
git rev-list --objects --all | git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' | sed -n 's/^blob //p' | sort --numeric-sort --key=2 | cut -c 1-12,41- | gnumfmt --field=2 --to=iec-i --suffix=B --padding=7 --round=nearest
## template start
{{ value_a }}
{{ value_b }}
## template end
this is a sample template
{{ value_a }}
{{ value_b }}
that's all folks
@techraf
techraf / Create a Company Structure
Last active November 4, 2016 07:10
Create Demo Domain
# This creates a demo company structure
@techraf
techraf / DellAAPrerequsites.ps1
Last active November 14, 2016 03:43
ADMgmtDemo
Install-WindowsFeature -Name GPMC
choco install -y mssqlserver2014express
# iwr https://git.io/v636d -UseBasicParsing | iex
Set-ExecutionPolicy Unrestricted -Force
# IP settings
New-NetIPAddress -InterfaceAlias Ethernet0 -IPAddress 10.20.50.10 -PrefixLength 16 -DefaultGateway 10.20.8.8
Set-DnsClientServerAddress -InterfaceAlias Ethernet0 -ServerAddresses 10.20.8.8
Set-NetConnectionProfile -InterfaceAlias Ethernet0 -NetworkCategory Private
# Ansible
2016-07-03 14:14:18 +0900
make
/usr/local/Cellar/cmake/3.5.2/bin/cmake -H/tmp/cpp-ethereum-20160703-10144-jqf5ju -B/tmp/cpp-ethereum-20160703-10144-jqf5ju --check-build-system CMakeFiles/Makefile.cmake 0
/usr/local/Cellar/cmake/3.5.2/bin/cmake -E cmake_progress_start /tmp/cpp-ethereum-20160703-10144-jqf5ju/CMakeFiles /tmp/cpp-ethereum-20160703-10144-jqf5ju/CMakeFiles/progress.marks
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/Makefile2 all
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/cpp-ethereum_BuildInfo.h.dir/build.make CMakeFiles/cpp-ethereum_BuildInfo.h.dir/depend
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f webthree-helpers/utils/libscrypt/CMakeFiles/scrypt.dir/build.make webthree-helpers/utils/libscrypt/CMakeFiles/scrypt.dir/depend
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f webthree-helpers/utils/secp256k1/CMakeFiles/secp256k1.dir/build.make webthree-helpers/utils/secp256k1/CMakeFiles/secp256k1.dir/depend
@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