Skip to content

Instantly share code, notes, and snippets.

View davisford's full-sized avatar

Davis Ford davisford

View GitHub Profile
kubectl get pods | grep Evicted | awk '{print $1}' | xargs kubectl delete pod
@davisford
davisford / rfc3339.swift
Created May 2, 2019 01:38 — forked from kristopherjohnson/rfc3339.swift
Parsing or formatting an RFC 3339 timestamp using NSDateFormatter
import Foundation
/// Parse RFC 3339 date string to NSDate
///
/// :param: rfc3339DateTimeString string with format "yyyy-MM-ddTHH:mm:ssZ"
/// :returns: NSDate, or nil if string cannot be parsed
public func dateForRFC3339DateTimeString(rfc3339DateTimeString: String) -> NSDate? {
let formatter = getThreadLocalRFC3339DateFormatter()
return formatter.dateFromString(rfc3339DateTimeString)
}
@davisford
davisford / ginkgo-cheatsheet.md
Last active December 21, 2018 22:34
ginkgo cheatsheet

FYI: I install ginkgo into $HOME/gocode. My .bash_profile does this:

export GOPATH=$HOME/gocode
export PATH=$PATH:$GOPATH/bin

And I do a custom GOPATH per project. I don't like global GOPATH for all projects. So on projectx, I have to cd projectx && export GOPATH=$(pwd):$GOPATH for example. It is a minor inconvenience, but I think it is cleaner.

This means, I want to install binaries like ginkgo into my global GOPATH and not necessarily my project path. Hope that makes sense.

@davisford
davisford / nats-cluster.txt
Last active May 4, 2017 16:59
Quick nats cluster
docker run -it --rm -p 4222:4222 -p 6222:6222 -p 8222:8222 --name nats-main nats
docker run -it --rm --name=nats-2 --link nats-main nats --cluster=nats://0.0.0.0:6222 --routes=nats-route://ruser:T0pS3cr3t@nats-main:6222
docker run -it --rm --name=nats-3 --link nats-main nats --cluster=nats://0.0.0.0:6222 --routes=nats-route://ruser:T0pS3cr3t@nats-main:6222
You now have a 3-node nats cluster. See http://localhost:8222/
@davisford
davisford / Setup MongoDB on localhost as Replica Set
Last active May 14, 2024 06:37
Setup MongoDB replica set on local host with only a single primary
Add the `replication` section to the mongod.conf file:
```
$cat /usr/local/etc/mongod.conf
systemLog:
destination: file
path: /usr/local/var/log/mongodb/mongo.log
logAppend: true
storage:
engine: mmapv1
// super quick hack to test mongodb replica set. once the replica set is running
// attemtp rs.stepDown() or just kill the primary and observe the behavior.
package main
import (
"fmt"
mgo "gopkg.in/mgo.v2"
"time"
)
"use strict";
/*\
|*|
|*| :: Number.isInteger() polyfill ::
|*|
|*| https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger
|*|
\*/
#!/bin/sh
if (( $# != 2))
then
echo "Usage: md2pdf.sh <input.md> <output.pdf>"
exit 1
fi
markdown $1 | htmldoc --cont --headfootsize 8.0 --linkcolor blue --linkstyle plain --format pdf14 - > $2
@davisford
davisford / gist:0823eb65508994c4622c
Created November 19, 2015 04:40 — forked from jberkus/gist:6b1bcaf7724dfc2a54f3
Finding Unused Indexes
WITH table_scans as (
SELECT relid,
tables.idx_scan + tables.seq_scan as all_scans,
( tables.n_tup_ins + tables.n_tup_upd + tables.n_tup_del ) as writes,
pg_relation_size(relid) as table_size
FROM pg_stat_user_tables as tables
),
all_writes as (
SELECT sum(writes) as total_writes
FROM table_scans