Skip to content

Instantly share code, notes, and snippets.

@robbyt
robbyt / ruby-wtf
Last active August 29, 2015 13:57
Ruby reminds me of PHP sometimes.
irb(main):001:0> require 'facter'
=> true
irb(main):002:0> network = Facter.value('network_bond0') or Facter.value('network_eth0')
=> "100.10.3.0"
irb(main):003:0> network
=> nil
irb(main):004:0> network = Facter.value('network_bond0') || Facter.value('network_eth0')
=> "100.10.3.0"
irb(main):005:0> network
=> "100.10.3.0"
@robbyt
robbyt / gist:8628815
Created January 26, 2014 05:25
backtrace
warning: no loadable sections found in added symbol-file system-supplied DSO at 0x7fff9bffe000
0x00007fbaacf5f0a3 in epoll_wait () from /lib/x86_64-linux-gnu/libc.so.6
(gdb) c
Continuing.
Program received signal SIGPIPE, Broken pipe.
0x00007fbaadb5f19d in send () from /lib/x86_64-linux-gnu/libpthread.so.0
(gdb) bt
#0 0x00007fbaadb5f19d in send () from /lib/x86_64-linux-gnu/libpthread.so.0
#1 0x00000000004fdc6d in ?? ()
@robbyt
robbyt / better-django-detection.vim
Created January 19, 2014 21:00
The vim script to add the Django paths to your vim environment for use with YouCompleteMe does not properly detect if Django is installed. If you're working on a Python project in a virtualenv without Django, Vim will complain because it cannot find the settings.py file. To fix the Django integration with YouCompleteMe, add this to your vim conf…
function FindDjangoSettings2()
if strlen($VIRTUAL_ENV) && has('python')
let django_check = system("pip freeze | grep -q Django")
if v:shell_error
" echo 'django not installed.'
else
" echo 'django is installed.'
let output = system("find $VIRTUAL_ENV \\( -wholename '*/lib/*' -or -wholename '*/install/' \\) -or \\( -name 'settings.py' -print0 \\) | tr '\n' ' '")
let outarray= split(output, '[\/]\+')
let module = outarray[-2] . '.' . 'settings'
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.provider :virtualbox do |v, override|
override.vm.box = "centos-64-x64-vbox4210"
override.vm.box_url = "http://puppet-vagrant-boxes.puppetlabs.com/centos-64-x64-vbox4210.box"
@robbyt
robbyt / github_pub_key.sh
Created September 6, 2013 15:33
Sick of saying "yes" to add the github ssh public host key the first time you clone a repo from github on a new box? Me too.
$ sudo puppet resource sshkey github.com ensure=present type=ssh-rsa key="AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ=="
...
backend WebCluster
<% @web_servers.keys.sort.each do |ws| -%>
server <%= web_servers[ws]['hostname'] %> <%= web_servers[ws]['ipaddress'] %>:80 weight 1 maxconn 100
<% end -%>
...
@robbyt
robbyt / apache2.pp
Last active December 18, 2015 14:49
class apache2 {
class{'apache2::install':}->
class{'apache2::config':}->
class{'apache2::service':}
@@ini_setting { $::fqdn :
ensure => present,
path => '/etc/haproxy/haproxy.conf',
section => 'backend WebCluster',
@robbyt
robbyt / gist:5703596
Last active December 18, 2015 01:28 — forked from nyarla/gist:5698606

Enviroments

  • Host:
    • Mac mini late 2012
    • OSX Mountain Lion 10.8.3
    • Vagrant 1.2.1 + VMware Fusion Provider
    • VMware Fusion 5.0.3
  • VM:
    • Ubuntu 12.04
@robbyt
robbyt / vcac.rb
Created April 25, 2013 18:55
custom fact to read the vcac agent xml
require 'rubygems'
require 'nokogiri'
require 'facter'
output = {}
xml_file = "/usr/share/gugent/site/CustomizeOS/properties.xml"
fact_prefix = "vcac_"
keys_we_care_about = [
'VirtualMachine.Admin.AdministratorEmail',
'VirtualMachine.Admin.Approver',
@robbyt
robbyt / json-lint.py
Last active December 16, 2015 15:08
Simple json parser that will print out json if it is valid. If it is invalid, it will print out which line has the error.
#!/usr/bin/env python
import json
import pprint
def main(args):
if len(args) >= 2:
for i in args[1:]:
s = open(i).read()
try:
pprint.pprint(json.loads(s))