Skip to content

Instantly share code, notes, and snippets.

View dugancathal's full-sized avatar

TJ Taylor dugancathal

  • Forj
  • Denver, CO
  • 11:05 (UTC -06:00)
View GitHub Profile
cf ssh $APP_NAME -c 'export PATH=~/app/vendor/ruby-2.3.1/bin:~/app/bin:$PATH && gem install bundler && bundle exec rails c production'
require 'csv'
ORDERING_FREQUENCY = ['Monday', 'Thursday', 'Wednesday']
def date_of_next(day, anchor)
anchor + 0.upto(6).find {|i| Date::DAYNAMES[(anchor + i).wday] == day }
end
people = CSV.parse(File.read(ARGV[0])).shuffle
start = Date.parse(ARGV[1]) rescue Date.today
schedule = ORDERING_FREQUENCY.cycle.take(30).map {|day| start = date_of_next(day, start) }
@dugancathal
dugancathal / wrap-httparty.rb
Created February 2, 2016 21:08
Wrapping HTTParty for more logging
require 'httparty'
class HTTPGetter
include HTTParty
base_uri 'http://google.com'
end
class LoggingDecorator < SimpleDelegator
def initialize(thing, logger)
super(thing)
@logger = logger
g() {
if [[ $# > 0 ]]; then
git "$@"
else
git status
fi
}
source "/usr/local/etc/bash_completion.d/git-completion.bash"
__git_complete g _git
@dugancathal
dugancathal / bootstrap.html
Created February 2, 2016 05:25
A blank html page with jquery and bootstrap
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>$TITLE</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
</head>
<body>
@dugancathal
dugancathal / try.rb
Last active November 24, 2015 01:17
This is probably what you meant.
# Paste me into your config/initializers directory.
class Object
def try(*args)
message, *other_args, options = *args
if options.is_a?(Hash) && options[:force]
self && self.public_send(message, *other_args)
else
raise NoMethodError, <<-MSG
Stop! Hold everything!
@dugancathal
dugancathal / callbacks.rb
Created July 1, 2015 06:13
Success/failure callbacks in Ruby
require 'json'
class PostsController
def create
CreatePost.new(params)
.on_success(&-> {
render json: {}, status: 200
})
.on_failure(&-> {
render json: {errors: {name: ["can't be blank"]}}, status: 422
@dugancathal
dugancathal / proto.rb
Created June 19, 2015 01:45
A DSL for protobuf in Ruby
require 'erb'
require 'binding_of_caller'
GENERATED_CLASS_FOR_MESSAGE = <<-CLS
class <%= name %>
attr_reader <%= message.fields.map {|name, _| ':' + name.to_s }.join(', ') %>
def initialize
<% message.fields.each do |name, field| %>
<%= field.to_s %>
<% end %>
@dugancathal
dugancathal / reflection.go
Created May 5, 2015 06:42
Set ID on a struct if it exists and hasn't already been set.
package reflectiontest
import "reflect"
type ThingWithId struct {
Id string
Name string
}
type ThingWithoutId struct {
@dugancathal
dugancathal / main.go
Created April 23, 2015 01:32
A quick example of tagging using Postgres in Golang
package main
import (
"bytes"
"database/sql"
"encoding/csv"
"errors"
"fmt"
_ "github.com/lib/pq"
)