Skip to content

Instantly share code, notes, and snippets.

View serverhorror's full-sized avatar

serverhorror serverhorror

  • Earth
View GitHub Profile
@serverhorror
serverhorror / rules_on_infrastructure.mdown
Created December 10, 2009 12:41 — forked from anonymous/gist:161265
Rules on Infrastructure

Rules

On Infrastructure

  • There is one system, not a collection of systems.
  • The desired state of the system should be a known quantity.
  • The "known quantity" must be machine parseable.
  • The actual state of the system must self-correct to the desired state.
  • The only authoritative source for the actual state of the system is the system.
# considered success?
systemctl status jenkins.service
jenkins.service - Jenkins CI Server
Loaded: loaded (/usr/local/lib/systemd/system/jenkins.service)
Active: inactive (dead)
Main PID: 3682 (code=killed, signal=TERM)
CGroup: name=systemd:/system/jenkins.service
# considered fail?
jenkins.service - Jenkins CI Server
$ python
Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> def f():
... try:
... raw_input("Read something:")
... except KeyboardInterrupt:
... print "A SIGINT HAPPENED!"
... sys.exit(0)
@serverhorror
serverhorror / cucumbertables.vim
Created June 4, 2011 21:02 — forked from tpope/cucumbertables.vim
vim automagically tabularize
inoremap <silent> <Bar> <Bar><Esc>:call <SID>align()<CR>a
function! s:align()
let p = '^\s*|\s.*\s|\s*$'
if exists(':Tabularize') && getline('.') =~# '^\s*|' && (getline(line('.')-1) =~# p || getline(line('.')+1) =~# p)
let column = strlen(substitute(getline('.')[0:col('.')],'[^|]','','g'))
let position = strlen(matchstr(getline('.')[0:col('.')],'.*|\s*\zs.*'))
Tabularize/|/l1
normal! 0
call search(repeat('[^|]*|',column).'\s\{-\}'.repeat('.',position),'ce',line('.'))
# This isn't perfect for high traffic sites, if you need something more production ready
# please tell us or stay tuned as we will open it up shortly.
import urllib
import urllib2
import base64
import simplejson
def track(event, properties=None):
"""
@serverhorror
serverhorror / format_mtime.sh
Created December 8, 2011 11:08
Print a date string (rather path segment) with the last mtime of an input path
#!/bin/bash
# Print a date string (rather path segment) with the last mtime of an input path
function format_mtime() {
p = $1
_mtime=$(stat --format="%y" $p)
result=$(date -d "$_mtime" "+%Y/%Y-%m/%Y-%m-%d/%Y-%m-%d_%Hh")
return result
}
d := time.Now()
b, _ := xml.Marshal(d)
fmt.Println()
fmt.Printf("%s\n", b)
fmt.Println()
Output is: <Time></Time>
"" MAGIC! call pathogen#infect()
syntax on
if has("autocmd")
filetype plugin indent on
endif
"" Variables
set nocompatible " Use Vim defaults (much better!)
set bs=2 " allow backspacing over everything in insert mode
@serverhorror
serverhorror / gist:2983396
Created June 24, 2012 14:24
Why is there a `@Received(1): "X"` in the output?
package main
// $ go version
//go version go1.0.2
/// OUTPUT (made with echo test | nc -v -w 1 -4 -u 127.0.0.1 1234)
// 2012/06/24 16:22:47 @Received(1): "X"
// 2012/06/24 16:22:47 @Received(5): []byte{0x74, 0x65, 0x73, 0x74, 0xa}
// 2012/06/24 16:22:47 @Received(5): "test"
# term 1
$ go run udpreceiver.go -host localhost:1235
2012/06/24 16:33:32 @Booting...
2012/06/24 16:33:32 @I need to listen here (flag): %s0xf840052240
2012/06/24 16:33:32 @Trying to listen on (UDPAddr): %s127.0.0.1:1235
2012/06/24 16:33:37 @Received(1): []byte{0x58}
2012/06/24 16:33:37 @Received(1): "X"
2012/06/24 16:33:37 @Received(1): []byte{0x58}
2012/06/24 16:33:37 @Received(1): "X"