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 / gitlab-routes
Created June 27, 2013 22:45
Gitlab routes - Someone in IRC was looking for a list of routes for Gitlab
search GET /search(.:format) search#show
api_api /api API::API
sidekiq /admin/sidekiq Sidekiq::Web
/ #<Rack::Builder:0x00000003edd110 @run=#<Grack::Server:0x00000003edcdf0 @config={:git_path=>"/usr/bin/git", :project_root=>"/home/git/repositories/", :upload_pack=>true, :receive_pack=>true}>, @map=nil, @use=[#<Proc:0x00000003edce18@/home/inflection/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.5/lib/rack/builder.rb:82>]>
help GET /help(.:format) help#index
help_api GET /help/api(.:format) help#api
@thomasbiddle
thomasbiddle / puppet_setup
Last active December 17, 2015 11:59
Setting up Puppet
# Setting up the master
echo "deb http://apt.puppetlabs.com precise main" > /etc/apt/sources.list.d/puppet.list
curl http://apt.puppetlabs.com/pubkey.gpg | apt-key add -
apt-get update
apt-get install puppetmaster
echo 'import "nodes"' > /etc/manifests/site.pp
touch /etc/manifests/nodes.pp
echo "127.0.0.1 puppet" > /etc/hosts
hostname puppet
echo "puppet" >> /etc/hostname
@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
class Users < ActiveRecord::Base
attr_accessible(
:nickname,
:email
)
# Set password to accessor so we can validate it below.
attr_accessor(
:password
)
@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();
}
@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: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: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: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
flash[:notice] = "Hey, you're not allowed in there!"
return redirect_to(
:controller => 'projects',
:action => 'index',
:notice_type => 'error'
)