Skip to content

Instantly share code, notes, and snippets.

@danreedy
danreedy / index.html.haml
Created May 19, 2011 15:21
Tab Admin Page Layout
- title "Rate Calculator"
.block#tab-container
#tab-container.secondary-navigation
%ul.wat-cf
%li{class: (current_user.has_role?(:check_role) ? "first" : nil)}= link_to "First Tab", "#tab-one"
%li= link_to "Second Tab", "#tab-two"
%li= link_to "Third Tab", "#tab-three"
.content
#tab-one
%h2 First Tab
@danreedy
danreedy / place.rb
Created April 20, 2011 17:40
Original Places Controller create method
class Place < ActiveRecord::Base
after_save :create_simplegeo_record
private
def create_simplegeo_record
begin
record = SimpleGeo::Record.new({
:id => self.id,
@danreedy
danreedy / https.js
Created April 8, 2011 16:06
A HTTPS Server using a locally created and self-signed wildcard SSL certificate (proof of concept)
var https = require('https');
var fs = require('fs');
var options = {
key: fs.readFileSync('local.key'),
cert: fs.readFileSync('local.pem')
};
https.createServer(options, function (req, res) {
res.writeHead(200);
@danreedy
danreedy / autgen.sh
Created April 8, 2011 16:05
Scripting the automation of an interactive script to generate a self-signed certificate for POW usage
# Generate our local key
openssl genrsa 2048 > local.key
# Create the self-signed certificate for all *.dev addresses
openssl req -new -x509 -nodes -sha1 -days 3650 -key local.key << ANSWERS > local.cert
US
IL
Chicago
Myself
Me
@danreedy
danreedy / users_controller.rb
Created April 5, 2011 18:56
Your typically scaffold controller
class UsersController < ApplicationController
respond_to :html, :xml
def index
@users = User.all
respond_with(@user)
end
def show
@danreedy
danreedy / Lucky 13 Ruby 2 line solution
Created December 10, 2010 05:06
What the heck, here's a 2 line solution to the engine yard contest. Usage === straight_bet(13,100_00)
require 'open-uri';
def straight_bet(bet,bid); (open('http://roulette.engineyard.com').read.gsub(/[^\d]/,'')==bet.to_s) ? 35*bid : 0; end
@danreedy
danreedy / Another Lucky 13 Entry
Created December 10, 2010 04:53
Rather than a simple one-liner, I figured I'd take the time to develop a test case and a full set of classes.
require 'open-uri'
require 'test/unit'
class Spin
def self.winning_number
URI.parse('http://roulette.engineyard.com').read.gsub(/[^\d]/,'').to_i
end
end
class StraightBet
@danreedy
danreedy / user.rb
Created December 2, 2010 18:38
This is a starting place for the User class that is spec'd in another gist.
class User
ROLES = %w[Administrator Editor Moderator User]
end
@danreedy
danreedy / user_spec.rb
Created December 2, 2010 17:12
Your mission: Make these RSpec tests pass I will be running these tests against Ruby 1.9.2, so ensure that your environment is similar. You can learn about RSpec by visiting http://rspec.info/. If you want a jump start for the user.rb file you can look
require_relative 'user'
describe User, "#roles" do
it "returns 'User' for a new user" do
user = User.new
user.roles.include?("User").should be(true)
end
it "returns 'User' and 'Moderator' if user is a moderator" do
user = User.new