Skip to content

Instantly share code, notes, and snippets.

@andyhawthorne
andyhawthorne / cache_example.html.erb
Created September 11, 2012 21:42
Fragment caching applied
<table>
<% cache do %>
<% @posts.each do |post| %>
<tr>
<td><strong><%= post.title %></strong></td>
</tr>
<tr>
<td><em>Posted: <%= post.created_at.strftime('%a %d %B %Y - %H:%M') %></em></td>
</tr>
<tr>
@andyhawthorne
andyhawthorne / unicorn_init.sh
Created September 4, 2012 22:35
start unicorn
#!/bin/sh
set -e
# Feel free to change any of the following variables for your app:
TIMEOUT=${TIMEOUT-60}
APP_ROOT=/home/you/apps/app_name/current
PID=$APP_ROOT/tmp/pids/unicorn.pid
CMD="cd $APP_ROOT; bundle exec unicorn -D -c $APP_ROOT/config/unicorn.rb -E production"
AS_USER=andy
set -u
@andyhawthorne
andyhawthorne / unicorn.rb
Created September 4, 2012 22:29
unicorn
root = "/home/you/apps/appname/current"
working_directory root
pid "#{root}/tmp/pids/unicorn.pid"
stderr_path "#{root}/log/unicorn.log"
stdout_path "#{root}/log/unicorn.log"
listen "/tmp/unicorn.your_user_name.sock"
worker_processes 2
timeout 30
@andyhawthorne
andyhawthorne / nginx.conf
Created September 4, 2012 22:21
nginx conf
upstream unicorn {
server unix:/tmp/unicorn.your_user.sock fail_timeout=0;
}
server {
listen 80 default deferred;
# server_name example.com;
root /home/andy/apps/you/current/public;
location ^~ /assets/ {
@andyhawthorne
andyhawthorne / deploy.rb
Created September 4, 2012 22:13
Deploy
require "bundler/capistrano"
server "176.xx.xx.xx", :web, :app, :db, primary: true
set :application, "your app"
set :user, "your user"
set :deploy_to, "/home/#{user}/apps/#{application}"
set :deploy_via, :remote_cache
set :use_sudo, false
@andyhawthorne
andyhawthorne / main.rb
Created August 27, 2012 11:11
Completed blog file
require 'sinatra'
require 'find'
require 'rdiscount'
def get_files(path)
dir_list_array = Array.new
Find.find(path) do |f|
dir_list_array << File.basename(f, ".*") if !File.directory?(f)
end
@andyhawthorne
andyhawthorne / index.erb
Created August 27, 2012 11:02
new index.erb
<ul>
<% @arr.each do |page| %>
<li><a href="/view/<%=page%>"><%=formatter(page) %></a></li>
<% end %>
</ul>
@andyhawthorne
andyhawthorne / helper.rb
Created August 27, 2012 10:57
Sinatra helper
helpers do
def formatter(page)
formatted = ""
formatted = page.gsub(/[-]/, ' ').capitalize
return formatted
end
end
@andyhawthorne
andyhawthorne / about.rb
Created August 27, 2012 10:08
Sinatra about page
get '/about' do
#if you don't want to use Markdown for pages, do this:
#erb :"pages/about"
#Then create about.erb in views/pages
markdown :"pages/about", :layout_engine => :erb
end
@andyhawthorne
andyhawthorne / 404.rb
Created August 27, 2012 09:49
Sinatra 404 method
not_found do
erb :missing
end