Skip to content

Instantly share code, notes, and snippets.

View stanchan's full-sized avatar
🏠
Working from home

Stan Chan stanchan

🏠
Working from home
View GitHub Profile
ruby_block "upload-pubkey" do
block do
cert_contents = File.read("/etc/chef/client.pem")
raw_data = { "server" => cert_contents, "loaded" => false }
begin
tls_keys_data_bag = Chef::DataBag.load("tls_keys")
rescue Net::HTTPServerException => e
if e.response.code == "404" then
Chef::Log.error("Creating a new tls_keys data bag")
# Monkey patch the gem parse_hosts_file method
module Beaker
module Options
#A set of functions to parse hosts files
module HostsFileParser < Beaker::Options
# Read the contents of the hosts.cfg into an OptionsHash, merge the 'CONFIG' section into the OptionsHash, return OptionsHash
# @param [String] hosts_file_path The path to the hosts file
#
# @example
script: |
def gitURL = "{scm-url}"
def getTags = ("git ls-remote -t -h $gitURL refs/tags/*").execute()
def getBranches = ("git ls-remote -t -h $gitURL feature/*").execute()
#return getBranches.text.readLines()
# .collect {{ it.split()[1].replaceAll('refs/heads/', '') }}
# .unique()
# .findAll {{ it.startsWith('<pattern>') }}
@stanchan
stanchan / RT2870STA.dat.patch
Created October 2, 2016 23:58
Raspberry Pi 2/3 + OpenSprinkler and AlarmDecoder
--- mt7610u_wifi_sta_v3002_dpo_20130916.orig/conf/RT2870STA.dat 2013-09-16 10:03:08.000000000 -0400
+++ mt7610u_wifi_sta_v3002_dpo_20130916/conf/RT2870STA.dat 2016-10-02 17:47:57.553736694 -0400
@@ -4,7 +4,7 @@
CountryRegionABand=7
CountryCode=
ChannelGeography=1
-SSID=11n-AP
+SSID=
NetworkType=Infra
WirelessMode=5
<% @hosts.each do |host| %>
Host <%= host %>
StrictHostKeyChecking no
UserKnownHostsFile=/dev/null
<% end %>
127.0.0.1 - - [14/Dec/2016:05:03:56 +0000] GET /nginx_status HTTP/1.1 "200" 112 0.001 "-" "Ruby" "-"
@stanchan
stanchan / sudoers
Created December 21, 2016 16:34
Vagrant Host Updater Changes
# Allow passwordless startup of Vagrant with vagrant-hostsupdater.
Cmnd_Alias VAGRANT_HOSTS_ADD = /bin/sh -c echo "*" >> /etc/hosts
Cmnd_Alias VAGRANT_HOSTS_REMOVE = /usr/local/opt/gnu-sed/libexec/gnubin/sed -i -e /*/ d /etc/hosts
%admin ALL=(root) NOPASSWD: VAGRANT_HOSTS_ADD, VAGRANT_HOSTS_REMOVE
@stanchan
stanchan / nginx_performance.txt
Created December 31, 2016 00:18
Nginx Web Socket Performance Tuning
Baseline for 40 cores 120GB memory VM
vm.swappiness = 0
fs.file-max = 12000500
fs.nr_open = 20000500
net.ipv4.ip_nonlocal_bind = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.ip_local_port_range = 1024 65000
net.ipv4.tcp_fin_timeout = 30
@stanchan
stanchan / gist:d3f56bc5cce899925e25032e2da7e577
Created January 17, 2017 01:31 — forked from cridenour/gist:74e7635275331d5afa6b
Setting up Vim as your Go IDE

Setting up Vim as your Go IDE

The final IDE

Intro

I've been wanting to do a serious project in Go. One thing holding me back has been a my working environment. As a huge PyCharm user, I was hoping the Go IDE plugin for IntelliJ IDEA would fit my needs. However, it never felt quite right. After a previous experiment a few years ago using Vim, I knew how powerful it could be if I put in the time to make it so. Luckily there are plugins for almost anything you need to do with Go or what you would expect form and IDE. While this is no where near comprehensive, it will get you writing code, building and testing with the power you would expect from Vim.

Getting Started

I'm assuming you're coming with a clean slate. For me this was OSX so I used MacVim. There is nothing in my config files that assumes this is the case.

@stanchan
stanchan / config_slurper.go
Created January 27, 2017 05:52
Read data from config file and assign to variables
/**
[profile manager]
key=value
password = sjssh31mmv
; a comment
port = 8080
ip = 123.456.789.321
# another comment
url=example.com
file=