Skip to content

Instantly share code, notes, and snippets.

View thomasbiddle's full-sized avatar

TJ (Thomas J.) Biddle thomasbiddle

View GitHub Profile
@thomasbiddle
thomasbiddle / OSXBuildTool.sh
Created August 6, 2012 18:47
OSX Build Tool
cd /tmp
if [ -d /tmp/losops-bt/ ]
then
rm -rf /tmp/losops-bt/
fi
git clone git@git:losops-bt
if [ -f /usr/bin/bt ]
then
sudo rm -rf /usr/bin/bt
@thomasbiddle
thomasbiddle / librarian-puppet-rake-task
Created October 22, 2012 23:24
Librarian-Puppet Rake Task for Templating the Puppetfile
#!/usr/bin/ruby
require 'erb'
desc "Templates the Puppetfile to the specified environment"
task :template_puppetfile, [:env] do |t, args|
unless args[:env].nil?
@environment = args[:env]
read_file = 'Puppetfile.erb'
write_file = 'Puppetfile'
flash[:notice] = "Hey, you're not allowed in there!"
return redirect_to(
:controller => 'projects',
:action => 'index',
:notice_type => 'error'
)
@thomasbiddle
thomasbiddle / gist:4515739
Created January 12, 2013 02:28
if model Foo has_many model Bars how can I find Foos that don't have any Bars at all?
Foo.all.each do |f|
if Bar.where(:foo_id => f.id).all.empty?
puts "#{f.id} has no bars!"
end
end
@thomasbiddle
thomasbiddle / gist:4543359
Created January 16, 2013 00:00
Rails Forms
<%= form_tag('/projects/build/', :method => "post") do %>
<%= label_tag(:revision, "Revision:") %>
<%= text_field_tag(:revision) %>
<%= submit_tag "Submit", :confirm => "You sure you want to do that?", :class => "btn btn-primary" %>
<% end %>
# In the controller:
@thomasbiddle
thomasbiddle / gist:4949826
Last active December 13, 2015 17:39
method_missing in ruby
module BADASS
class Config
def initialize(config_file)
@config_file = config_file
end
def method_missing(method, *args)
if method.to_s =~ /[a-zA-Z0-9\-_]=$/
puts method
puts args[0]
@thomasbiddle
thomasbiddle / gist:5027464
Created February 25, 2013 03:53
CodingForInterviews.com Feb 20, 2013 Article
# Binary Search
def search array, num, first, last
middle = (first+last)/2
if (first or last) == middle
return -1
end
if num == array[middle]
return middle
elsif num > array[middle]
search(array, num, middle, last)
@thomasbiddle
thomasbiddle / gist:5350078
Last active December 16, 2015 00:49
Grabbing an environment variable from Jenkins
// Assuming environment is an EnvVars object, and mergeOptions is an arbitrary object that, when I call getMergeOptions(), returns the branch I'm merging with - Which can either be a string - or an environment variable, $some_var
String mergeTarget = "";
if ( environment.get(mergeOptions.getMergeTarget()) != null ) {
mergeTarget = environment.get(mergeOptions.getMergeTarget().substring(1));
} else {
mergeTarget = mergeOptions.getMergeTarget();
}
class Users < ActiveRecord::Base
attr_accessible(
:nickname,
:email
)
# Set password to accessor so we can validate it below.
attr_accessor(
:password
)
@thomasbiddle
thomasbiddle / gist:5581079
Last active December 17, 2015 08:38
Spin up Rails in either "prod" or "production" environment
# Belongs in your config/application.rb as far up as possible (Right under require statements should be good)
# Allow either 'prod' or 'production' rails env.
if ENV['RAILS_ENV'] == 'prod'
ENV['RAILS_ENV'] = 'production'
end