Skip to content

Instantly share code, notes, and snippets.

View brandocorp's full-sized avatar

Brandon Raabe brandocorp

View GitHub Profile
@brandocorp
brandocorp / octokit_examples.rb
Created August 26, 2015 00:29
Octokit Examples
# Build our client object
client = Octokit::Client.new(:access_token => ENV['GITHUB_API_TOKEN'])
# Connect and get our User object
user = client.user
# Get a listing of this user's personal repos
user_repos = user.rels[:repos].get.data
user_repos.each do |repo|
puts repo.name, repo.clone_url
end
@brandocorp
brandocorp / gist:9574673
Created March 15, 2014 22:11
win32-file-stat test
irb(main):001:0> require 'win32/file'
=> true
irb(main):002:0> f = File::Stat.new('C:\Program Files')
=> #<File::Stat archive=false atime=2014-02-26 14:52:59 -0700 blksize=4096 blockdev=false blocks=1 compressed=false ctime=2009-07-13 20:20:08 -0700 dev=2 encrypted=false gid=2271478464 hidden=false indexed=true ino=281474976710716 mode=040555 mtime=2014-02-26 14:52:59 -0700 nlink=1 normal=false offline=false rdev=1478858236 readonly=true reparse_point=false size=4096 sparse=false system=false temporary=false uid=2271478464
irb(main):003:0> f.directory?
=> true
irb(main):004:0> f.writable?
=> false
irb(main):008:0> f.send(:access_check, 'C:\Program Files', 0x40000000) # GENERIC_WRITE
=> true
@brandocorp
brandocorp / handler_remote_file_cache_handler.rb
Last active August 29, 2015 14:00
Remote File Pre-Caching
require 'chef/handler'
require 'chef/rest'
require 'chef/version_constraint'
class Chef
class RemoteFile
class CacheHandler < ::Chef::Handler
attr_reader :config
@brandocorp
brandocorp / config
Created January 16, 2015 17:19
use jumphost with ssh proxy command
Host *
ControlMaster auto
ControlPath ~/.ssh/tmp/%h_%p_%r
TCPKeepAlive yes
ServerAliveInterval 30
ConnectTimeout 15
LogLevel ERROR
Host jumphost
HostName ${JUMPHOST_IP}
@brandocorp
brandocorp / monkey_patch.rb
Created January 22, 2015 18:39
Stop include_recipe directive from actually loading the recipe
# This keeps any cookbook aside from our target cookbook from actually loading recipes
class Chef
class CookbookVersion
alias_method :old_load_recipe, :load_recipe
def load_recipe(recipe_name, run_context)
old_load_recipe(recipe_name, run_context) if metadata.name == 'cookbook_name'
end
end
end
@brandocorp
brandocorp / supervisor_cleanup.sh
Last active August 29, 2015 14:17
supervisor log cleanup
#!/bin/bash
# remove emtpy clutter
find /var/log/supervisor/ -size 0 -exec rm -f {} \;
##### Rotated Logs #####
# gzip any rollovers
find /var/log/supervisor/ -regex '.*supervisor-[A-Za-z0-9]+.log.[0-9]+' -exec gzip -f {} \;
# remove anything older than 3 days
find /var/log/supervisor/ -regex '.*supervisor-[A-Za-z0-9]+.log.*' -mtime +2 -exec rm -f {} \;
@brandocorp
brandocorp / docker-host-01.sh
Last active August 29, 2015 14:17
Elasticsearch Unicast across Docker Hosts
#!/bin/bash
#
# Docker Host 01
# eth0: 192.168.1.10
#
docker run -d \
-p 9200:9200 \
-p 9300:9300 \
@brandocorp
brandocorp / chef_winrm.ps1
Last active August 29, 2015 14:20
Prepare server to be bootstrapped by Chef with WinRM
# Get network connections
$networkListManager = [Activator]::CreateInstance([Type]::GetTypeFromCLSID([Guid]"{DCB00C01-570F-4A9B-8D69-199FDBA5723B}"))
$connections = $networkListManager.GetNetworkConnections()
$connections | % {$_.GetNetwork().SetCategory(1)}
# run quick config
winrm qc -q
# allow incoming traffic from anywhere (still requires VPN connection)
netsh advfirewall firewall set rule name="Windows Remote Management (HTTP-In)" profile=private new enable=yes remoteip=any localip=any protocol=tcp
### Keybase proof
I hereby claim:
* I am brandocorp on github.
* I am brandocorp (https://keybase.io/brandocorp) on keybase.
* I have a public key whose fingerprint is B27E EF08 56F0 C4B4 66A4 DDA0 6501 9DAC 08D6 305D
To claim this, I am signing this object:
@brandocorp
brandocorp / jenkins_password.rb
Last active August 29, 2015 14:21
Encrypt or decrypt a stored password from a Jenkins config file
#
# All credit to belongs to the original author here:
# http://xn--thibaud-dya.fr/jenkins_credentials.html
#
# This is merely a ruby implementation of the code found here:
# https://github.com/tweksteen/jenkins-decrypt/blob/master/decrypt.py
#
require 'openssl'
require 'base64'