Skip to content

Instantly share code, notes, and snippets.

CREATE OR REPLACE FUNCTION GETUTCDATE() RETURNS TIMESTAMP AS '
SELECT CAST(LOCALTIMESTAMP AT TIME ZONE ''UTC'' AS TIMESTAMP);
' LANGUAGE SQL VOLATILE;
GETUTCDATE();
@dreamr
dreamr / gist:6749273
Last active December 24, 2015 05:19
git workflow
### Git Workflow
Answering the following questions helps you choose a branch workflow:
* Where do important phases of development occur?
* How can you identify (and backport) groups of related change?
* Do you have work which often needs to be updated in multiple distinct long-lived branches?
* What happens when emergency patches are required?
* What should a branch for a particular purpose (including user-tactical) be named?
* What is the lifecycle of a branch?
how do I get from here (app01)
(ruby-1.9.3) ~/proj/hvst/infrastructure $ knife node show app01.hvst.com
Node Name: app01.hvst.com
Environment: _default
FQDN: app01.hvst.com
IP: 54.218.202.46
Run List: role[base], role[app--rails]
Roles: base, internal--shell, internal--logs, internal--security, internal--mailer, internal--monitoring, internal--datadog, internal--system_tools, app--rails, internal--development, internal--image_tools
Recipes: base, runit, chef-client, omnibus_updater, chef-client::config, ohai, hvst::route53, tmux, grc, zsh, users::sysadmins, hostname, resolver, ntp, logwatch, logrotate, papertrail-cookbook, openssh, sysctl, iptables, hvst::iptables, sudo, denyhosts, chkrootkit, rkhunter, postfix::sasl_auth, postfix::aliases, datadog::dd-agent, datadog::dd-handler, datadog::network, htop, monit, newrelic-sysmond, sysstat, curl, git, rsync, vim, xml, xslt, zip, build-essential, postgresql::libpq, imagemagick, imagemagick::devel, hvst::ruby, nodejs, hvst::rails, hv
(ruby-1.9.3) ~/proj/hvst/infrastructure $ knife ec2 server create -r 'role[base], role[app--rails]' -I ami-daac32ea -f m1.medium -G hvst-base -x ubuntu -Z us-west-2b -N app02.hvst.com
Instance ID: i-295ba41e
Flavor: m1.medium
Image: ami-daac32ea
Region: us-west-2
Availability Zone: us-west-2b
Security Groups: hvst-base
Tags: {"Name"=>"app02.hvst.com"}
SSH Key: staginghvstcom
@dreamr
dreamr / gist:6995089
Last active December 25, 2015 14:59
firing up a new ec2 server

firing up a new ec2 server

NOTE!! Bug in knife ec2 - v

  • knife the server once
  • log in with generic ubuntu once
    • fix encrypted dbag value
    • ensure edbs is at /etc/chef/encrypted_data_bag_secret has the correct key (get from dreamr)
@dreamr
dreamr / gist:7028011
Last active December 25, 2015 19:29
I was showing method chaining to someone, @jgarcia I think
reporter = Reporting::Reporter.new
def do_shit
reporter.add_msg_line "Starting do shit"
rescue Exception => e
reporter.add_msg_line "There was an error! #{e.message}"
ensure
reporter.send_event("do Shit")
end
@dreamr
dreamr / after
Last active December 26, 2015 03:48
from mess to clean - showing a dev how to remove conditional logic
def calculate_return(last_trade)
send(:"calculate_#{recommendation.to_s}_return", last_trade)
end
@dreamr
dreamr / gist:7187332
Last active December 26, 2015 17:29
hangman in ruby lambdas!
require 'io/console'
# Some vars to give us data
dict = %W(ruby lambda functional)
game_word = dict[rand(dict.size)]
guesses = {
correct: [],
incorrect: []
}
max_guesses = 7
@dreamr
dreamr / gist:7421224
Last active December 28, 2015 01:29
A code challenge from a prospective client - name withheld to prevent other people cheating
module Yahtzee
module ScoreCardUpdater
module_function
def update(game_card)
->(placement, value) {
game_card.update!(placement => value)
}
end
end