Skip to content

Instantly share code, notes, and snippets.

View travisjeffery's full-sized avatar

Travis Jeffery travisjeffery

View GitHub Profile
@travisjeffery
travisjeffery / .vimrc
Created February 23, 2012 09:17
Find Rails Partial References
function! GrepPartial(partial)
if (a:partial)
let pattern = "partial.*" . partial
else
let path = substitute(expand("%:h"), "app/views/", "", "")
let action = substitute(expand("%:t:r:r"), "^_", "", "")
let pattern = "partial.*" . path . "/" . action
endif
if (exists('g:loaded_fugitive'))
@travisjeffery
travisjeffery / influxdb-setup.md
Last active March 17, 2024 15:38
Guide to setting up InfluxData's TICK stack

Guide to setting up InfluxData's TICK stack

InfluxData's T.I.C.K. stack is made up from the following components:

Component Role
Telegraf Data collector
InfluxDB Stores data
Chronograf Visualizer
@travisjeffery
travisjeffery / functional-options.md
Last active April 23, 2023 11:13
How to do functional options in Golang

Here's the simplest example showing how to do functional options in Golang.

They're a great way to enable users to set options and ease adding new options later.

package main

import (
	"flag"
	"fmt"
@travisjeffery
travisjeffery / tictactoe.c
Last active November 17, 2022 15:41
tic tac toe in c
#include <stdlib.h>
#include <stdbool.h>
typedef enum {
BLUE = -1,
NONE,
RED
} Player;
typedef struct {
@travisjeffery
travisjeffery / state_pattern.rb
Created March 11, 2012 01:08
State Pattern in Ruby
# State - allow an object to alter its behaviour when its internal state
# changes. The object will appear to change its class.
# Key idea - introduce an abstract class called SomethingState to represent the
# states of the object. Subclasses of the abstract class implement
# state-specific behaviour.
class Person
attr_accessor :state, :name
@travisjeffery
travisjeffery / person.js
Created May 7, 2012 02:33
Empty a Model's Collection With Mongoose
var mongoose = require("mongoose")
, assert = require("assert")
, async = require("async")
, Person
async.series([
function(callback){
mongoose.connect("mongodb://localhost/mydb")
mongoose.connection.on("open", callback)
},
@travisjeffery
travisjeffery / dep.md
Last active October 23, 2019 10:39
Fixing golang/dep's "unable to update checked out version" issue

If you're using golang/dep, and for an unexplained reason running dep ensure errors:

unable to update checked out version: : command failed: [git checkout 019ae5ada31de202164b118aee88ee2d14075c31]: exit status 1

You have to remove the dep from your Gopkg.lock file. This way Gopkg won't look for the missing ref.

And then dep ensure again.

@travisjeffery
travisjeffery / angular-focus.html
Created May 3, 2012 18:49
Angularjs Focus Directive
<script>
angular.directive('tj:focus', function(){
return function(scope, element){
element[0].focus();
};
});
</script>
<div>
<input type="text" ng:model="model" tj:focus />
host=$1
echo "finding host for container: $1"
function ec2-ip () {
aws ec2 describe-instances --filter Name=instance-id,Values=$1 | jq '.Reservations[0].Instances[0].PrivateIpAddress' | tr -d '"'
}
instances=$(aws ecs list-container-instances --cluster api --max-items 100 | jq '.containerInstanceArns | .[]' | tr -d '"')
ids=$(echo $instances | xargs aws ecs describe-container-instances --cluster api --container-instances | jq '.containerInstances | .[] | .ec2InstanceId' | tr -d '""')
// error.go
// Copyright 2016 The Upspin Authors. All rights reserved.
// populateStack uses the runtime to populate the Error's stack struct with
// information about the current stack.
func (e *Error) populateStack() {
e.Stack = &Stack{Callers: callers()}
}