Skip to content

Instantly share code, notes, and snippets.

View yock's full-sized avatar

Michael Yockey yock

View GitHub Profile
@yock
yock / pre-push
Last active October 21, 2015 15:19
#!/bin/sh
## Run a project's test prior to pushing to a remote, and prevent the push if tests fail.
RUBY_TESTS=()
if [ -d "test" ]; then
RUBY_TESTS+=('ruby -Itest')
fi
@yock
yock / decronym.php
Created October 3, 2015 19:13 — forked from Two9A/decronym.php
Decronym: A simple Reddit bot
<?php
/**
* Dirty, dirty Reddit bot: Decronym
*/
class Reddit {
const USERNAME = '***';
const PASSWORD = '***';
const CLIENTID = '***';
const SECRET = '***';
$ cap production whenever:clear_crontab
$ cap production whenever:update_crontab
# deploy.rb
server '0.0.0.0', roles: %w{ retire } # Old app server is given a role of 'retire'
server '0.0.0.1', roles: %w{ app db } # New app server gets the existing roles
set :whenever_roles, %w{ retire app }
class PremiumFeature
attr_accessor :controller
def initialize(controller)
@controller = controller
end
def enabled?
controller.current_user.premium?
end
end
<table>
<thead>
<th>Foo</th>
<% if feature_enabled?(:premium) %>
<th>Premium</th>
<% end %>
</thead>
<tbody>
<tr>
<td><%= @widget.foo %></td>
@yock
yock / _tmux-new-session
Last active August 29, 2015 14:27
Using the current working directory as a name, look for an existing tmux session and attach if it exists, else create a new one
# ./functions/_tmux-new-session
#compdef tmux-new-session
compadd $(tmux list-sessions -F \#S | sed "s/[\* ]//g")
@yock
yock / solr.sh
Last active August 29, 2015 14:22
Apache Solr 4.x startup script
#! /bin/sh
### BEGIN INIT INFO
# Provides: solr
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Solr indexing service
# Description: Solr is an open source enterprise search platform.
### END INIT INFO
@yock
yock / begin.rb
Last active August 29, 2015 14:22
Rescuing in Ruby
class Foo
def dangerous
# Do stuff before the block
begin
raise 'Danger!'
rescue
# Make it safe
end
end
end
@yock
yock / view_spec.rb
Created May 6, 2015 17:20
Helper methods defined in controllers must be stubbed out for any view specs whose views access those helper methods.
describe 'some/view/file' do
before do
controller.singleton_class.class_eval do
def feature_enabled?(feature_name)
false
end
helper_method :feature_enabled?
end
end