Skip to content

Instantly share code, notes, and snippets.

View zacheryph's full-sized avatar

Zachery Hostens zacheryph

View GitHub Profile
require 'sinatra/base'
class Bacon < Sinatra::Base
enable :logging, :clean_trace
get '/' do
'Hello from Sinatra!'
end
end
class ArelReport
# == MIXINS
extend ActiveModel::Callbacks
define_model_callbacks :optionals, :only => [:after, :before]
define_model_callbacks :query, :only => :before
# == CLASS
class << self
attr_accessor :projections, :default_table, :remove_zeros
@zacheryph
zacheryph / render_loop_in_helper.rb
Last active December 11, 2015 16:38
collecting render calls from helper method
def account_tree(root, partial, output="")
sorter = ->(n) {[n.content.index_path, n.content.number]}
output += render(partial: partial, object: root.content) if root.content
root.children.sort_by(&sorter).each {|node| output = account_tree(node, partial, output)}
output.html_safe
end
@zacheryph
zacheryph / bucket_split.rb
Last active August 29, 2015 13:56
spread amount over buckets with no under/over
class BucketSplit
class InvalidSpread < StandardError ; end
def initialize(total, splits, precision = 2)
self.precision = precision
self.total = total.round(precision)
self.splits = splits
self.buckets = calculate_buckets
end
@zacheryph
zacheryph / interactor.coffee
Last active August 29, 2015 13:56
Interactor pattern in CoffeeScript
# Interactor pattern
# idea pulled blatently from: https://github.com/collectiveidea/interactor
#
# NEED TO DO:
# - add bluebird, so ALL perform() calls are promises.
# - 'rollback' support to crawl 'backwards' when there is an error
# - 'fail()' for the rollback
#
# Question:
# - Is doing a pattern like this in JS useless?
@zacheryph
zacheryph / emitter.rb
Created March 20, 2014 16:31
pub/sub with ActiveSupport::Notifications
module Eventable
module Emitter
extend ActiveSupport::Concern
included do
def emit(event_name, payload = {})
full_event = "#{self.class.to_s.underscore}:#{event_name}"
Eventable.emit full_event, self, payload
end
end
# this contains development overrides
version: "3.5"
# common for app/sidekiq
# we volume bundler so we aren't constantly re-installing gems
x-app: &app-common
build:
context: .
target: dev
volumes:
# Zachery Hostens
# Ensure TPM Installation {{{
if "test ! -d ~/.tmux/plugins/tpm" \
"run 'git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm'"
# }}}
# General {{{
set -g prefix C-a
set-option -g base-index 1
setw -g pane-base-index 1
@zacheryph
zacheryph / chart-deployment.yaml
Created February 6, 2018 19:07
Private Gitlab / K8s / helm deployment pipeline
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "pkg.fullname" . }}
labels:
app: {{ include "pkg.name" . }}
chart: {{ include "pkg.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
spec:
@zacheryph
zacheryph / keybase.md
Last active April 14, 2020 18:28
keybase.md

Keybase proof

I hereby claim:

  • I am zacheryph on github.
  • I am zacheryph (https://keybase.io/zacheryph) on keybase.
  • I have a public key ASCDPgxfcWLiWhYVg09hdJi9QRrfK4ruGx8qLUluzsEdAQo

To claim this, I am signing this object: