Skip to content

Instantly share code, notes, and snippets.

View sapient's full-sized avatar

Mark Howell sapient

View GitHub Profile
@sapient
sapient / _form.html.erb
Created November 11, 2011 21:54
Most recent form
<%= form_for(@post) do |f| %>
<% if @post.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:</h2>
<ul>
<% @post.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
def index
if Rails.env == "development"
longitude = "-95.2752"
latitude = "29.9459"
else
longitude = request.location.longitude
latitude = request.location.latitude
end
@venues = Venue.near([latitude, longitude].join(", "), 60)
@sapient
sapient / xirr.rb
Created November 14, 2011 20:07
XIRR Function Written for Ruby 1.9.2
require 'date'
require 'bigdecimal/newton'
require 'bigdecimal/math'
include Newton
class XIRR
def initialize(datevalues)
@datevalues = datevalues
@zero = BigDecimal::new("0.0")
@sapient
sapient / controller.rb
Created November 20, 2011 22:39
NEVER DO THIS
def show
if params["product_search"].present?
@product = Product.find_by_name(params["product_search"][:name])
if @product.blank?
redirect_to(products_path, :notice => "Not Found")
return
end
else
@product = Product.find(params[:id])
end
@sapient
sapient / config.ru
Created March 6, 2012 12:06
Rails Lightweight Stack. Most of this is detailed on Crafting Rails Applications - http://pragprog.com/book/jvrails/crafting-rails-applications
# Run this file with `RAILS_ENV=production rackup -p 3000 -s thin`
# Be sure to have rails and thin installed.
require "rubygems"
# We are not loading Active Record, nor the Assets Pipeline, etc.
# This could also be in your Gemfile.
gem "actionpack", "~> 3.2"
gem "railties", "~> 3.2"
# The following lines should come as no surprise. Except by
@sapient
sapient / routes.rb
Created April 27, 2012 07:18
Forum routes
namespace :forum do
resources :forums do
collection do
get 'sort'
post 'update_sort'
end
end
resources :topics do
member do
get 'lock'