Skip to content

Instantly share code, notes, and snippets.

@libryder
libryder / index.html.erb
Created August 21, 2012 19:44
Add CSS file to <head> from partial
<% content_for :head do %>
<%= stylesheet_link_tag 'path/to/css' %>
<% end %>
get '/' do
@title = "ThePostBin - Home"
if user_id = session[:user_id]
@user = User.find(user_id)
end
haml :index
end
@libryder
libryder / application.html.erb
Created July 29, 2012 04:05
Stop IE users from seeing your site with a BSOD splash
<div id="kill_ie"><img src="/bsod.png"></div>
@libryder
libryder / rspec-syntax-cheat-sheet.rb
Created July 21, 2012 03:19 — forked from dnagir/rspec-syntax-cheat-sheet.rb
RSpec 2 syntax cheat sheet by example
# RSpec 2.0 syntax Cheet Sheet by http://ApproachE.com
# defining spec within a module will automatically pick Player::MovieList as a 'subject' (see below)
module Player
describe MovieList, "with optional description" do
it "is pending example, so that you can write ones quickly"
it "is already working example that we want to suspend from failing temporarily" do
pending("working on another feature that temporarily breaks this one")
VCR.configure do |config|
config.cassette_library_dir = 'spec/cassettes'
config.hook_into :fakeweb
config.configure_rspec_metadata!
end
@libryder
libryder / usps_address.rb
Created June 27, 2012 23:06
Simple USPS API for verifying addresses
class USPSAddress
EXEMPT_ADDRESS_PARTS = ["NW", "NE", "SW", "SE"]
def initialize
@usps = USPS.new(USPS_USER_ID)
end
def parse_address(address)
location = Location.new(address)
@libryder
libryder / contact.php
Created June 21, 2012 21:16
Super simple PHP contact form in one file
<html>
<head>
<title>Contact Us</title>
</head>
<body>
<?php
if ($_POST['message']) {
$message = $_POST['message'];
<div class="navbar">
<div class="navbar-inner">
<div class="container">
<a class="brand" href="#">
<%= image_tag('G5_logo.png') %> Reputation Manager
</a>
<% if user_signed_in? %>
<% present current_user do |user_presenter| %>
<ul class="nav pull-right">
<% if rollout? :workflow %>
class Customer < User
# on the following comma-sep list, ONLY append values to the end!
has_preferences :hide_deleted_stores
def is_employee?
false
end
def is_customer?
true
def padded_store_link direction
user_store_ids = current_user.store_ids_for_client(@client)
client_store_ids = @client.stores.map(&:id)
sorted_user_store_ids = client_store_ids.select { |i| user_store_ids.include?(i) }
index = sorted_user_store_ids.index(@store.id)
puts "INDEX #{index}"
if direction == "next"
id = sorted_user_store_ids[index+1]