Skip to content

Instantly share code, notes, and snippets.

View cespare's full-sized avatar

Caleb Spare cespare

View GitHub Profile
# The machines:
# Mac OS (MBP Retina):
$ sysctl -n machdep.cpu.brand_string
Intel(R) Core(TM) i5-3230M CPU @ 2.60GHz
$ go version
go version go1.2 darwin/amd64
# Linux desktop (Ubuntu 13.10):
$ go version
@cespare
cespare / rsync.yml
Created January 15, 2014 15:43
Ansible hang
---
- name: rsync set default value for copy_dest
set_fact: copy_dest={{ dest }}
when: copy_dest is not defined
- name: rsync src={{ src }} dest={{ dest }} copy_dest={{ copy_dest }}
local_action: >
rsync --archive --compress --copy-unsafe-links --checksum --itemize-changes --exclude=.git
--exclude=.vagrant --copy-dest={{ copy_dest }} {{ src }} {{ inventory_hostname }}:{{ dest }}
register: rsync
---
- name: hang test
hosts: "{{ hosts }}"
tasks:
- name: hang test 1
local_action: command ssh {{ inventory_hostname }} ls
when: task_to_run == "1"
- name: hang test 2
local_action: shell ssh {{ inventory_hostname }} ls 2>/dev/null
when: task_to_run == "2"
@cespare
cespare / results.txt
Created March 20, 2014 19:03
Print out stdlib packages not used within the stdlib.
$ go run unused.go
container/ring
debug/gosym
debug/pe
encoding/ascii85
encoding/csv
expvar
go/build
hash/crc64
hash/fnv

Dump redis rdb files to json. Many limitations, including:

  • Only one DB allowed
  • Only plain key/vals and hashes allowed (no sets, lists, zsets for now)

3x faster than rdbtool for my test dump:

$ time rdb --command json dump.rdb > rdbtool.json 
rdb --command json  > rdbtool.json  264.65s user 0.80s system 99% cpu 4:25.93 total
@cespare
cespare / example.conf
Created September 27, 2014 23:08
example nginx reverse proxy config
server {
listen 80;
server_name mysite.example.com;
access_log /path/to/mysite.example.com.log;
location / {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# app server listens on localhost:9876
@cespare
cespare / md.html
Last active August 29, 2015 14:10
rendered markdown exmaple
<h1>Reflex</h1>
<p>Reflex is a small tool to watch a directory and rerun a command when certain files change. It's great for
automatically running compile/lint/test tasks and for reloading your application when the code changes.</p>
<h2>A simple example</h2>
<div class="highlight"><pre># Rerun make whenever a .c file changes
reflex -r &#39;\.c$&#39; make
</pre></div>
@cespare
cespare / foo_test.go
Created January 22, 2015 22:37
Example of excluding tests with build tags
package foo
import "testing"
func TestFoo(t *testing.T) {
t.Log("A")
}
no ssa:
"".avgSliceValue t=1 size=80 value=0 args=0x20 locals=0x0
0x0000 00000 (ssa_test.go:24) TEXT "".avgSliceValue(SB), $0-32
0x0000 00000 (ssa_test.go:24) NOP
0x0000 00000 (ssa_test.go:24) NOP
0x0000 00000 (ssa_test.go:24) MOVQ "".s+16(FP), DX
0x0005 00005 (ssa_test.go:24) FUNCDATA $0, gclocals·2fccd208efe70893f9ac8d682812ae72(SB)
0x0005 00005 (ssa_test.go:24) FUNCDATA $1, gclocals·33cdeccccebe80329f1fdbee7f5874cb(SB)
@cespare
cespare / wtf.js
Created April 18, 2016 01:07
vanguard's crappy broken password validation javascript
function PasswordOnLoad()
{
}
//------------------ EscapeClick --------------///
function EscapeClick()
{
if (document.all)
{