Skip to content

Instantly share code, notes, and snippets.

View urfolomeus's full-sized avatar

Alan Gardner urfolomeus

View GitHub Profile
class Configuration
attr_accessor :tail_logs, :max_connections, :admin_password, :app_server
def app_server
@app_server ||= AppServerConfiguration.new
if block_given?
yield(@app_server)
end
@app_server
end
// inherited - bad
public MyString extends String {
public MyString () {
super();
}
public String capitalize(String string) {
String capString = string.subString(0,1);
capString = first.toUpperCase();
# Example of potential Template pattern implementation: -
class Animal
def initialize(name, type)
@name = name
@type = type
end
def mammal?
@type == "mammal"
@urfolomeus
urfolomeus / IRBRC.rb
Created February 25, 2011 16:57
My irbrc
if ENV['RAILS_ENV']
# Called after the irb session is initialized and Rails has been loaded
IRB.conf[:IRB_RC] = Proc.new do
#logger = Logger.new(STDOUT)
#ActiveRecord::Base.logger = logger
#ActiveRecord::Base.connection_pool.clear_reloadable_connections!
show_log
end
def show_log
@urfolomeus
urfolomeus / product_demo.rb
Created March 23, 2011 08:58
Proving to myself Rory was right :P
# This is a basic implementation and is essentially what Rory had.
# I just had to prove to myself that it worked. ;)
# Decorator pattern is precisely the way to go here.
# This is the base class that we want to decorate.
# It needs to have a default method for each of the lifecycle events.
# i.e. what does it do in the event that there are no products.
class Post
attr_accessor :products, :featured, :hidden
@urfolomeus
urfolomeus / gist:1094759
Created July 20, 2011 11:00
Example of using Capybara with RSpec to check the class and content of a table cell
require 'spec_helper'
describe "daemons/index.html.erb", :type => :request do
before :each do
assign( :daemons, { 'test' => :up } )
render
end
it "has the correct class" do
rendered.should have_css('table tr td.daemon-up')
@urfolomeus
urfolomeus / functionStatementExample.c
Created November 10, 2011 20:21
Difference between a function and a statement
/* this is a function */
main()
{
/* this is a statement */
printf("This C stuff is easy!\n");
/* so is this */
return 0;
}
@urfolomeus
urfolomeus / gist:1558958
Created January 4, 2012 07:26
vim folder structure
.
├── autoload
│   ├── pathogen.vim
│   └── pathogen.vim.old
├── backup
├── bundle
│   ├── nerdcommenter
│   ├── scss-syntax.vim
│   ├── snipmate.vim
│   ├── supertab
@urfolomeus
urfolomeus / .vimrc
Created January 4, 2012 07:27
.vimrc
call pathogen#infect()
syntax on
filetype plugin indent on
@urfolomeus
urfolomeus / hello.rb
Created February 3, 2012 14:47
Class level privates
class Hello
def self.first
puts "Boo!"
end
private
def self.second
puts "Buh!"
end