Skip to content

Instantly share code, notes, and snippets.

View beef's full-sized avatar

Beef beef

  • Beef
  • Bristol, UK
View GitHub Profile
@beef
beef / test.html
Created January 26, 2011 09:50
An html file
We couldn’t find that file to show.
@beef
beef / Gemfile
Created December 15, 2010 11:29
Production environment for Rails 3 on heroku with rack-cache
# Add this to your gem file
group :production do
gem 'dalli'
gem 'rack-cache', :require => 'rack/cache'
gem 'rack-contrib', :require => 'rack/contrib'
end
<Location />
# Insert filter
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/x-javascript
# Netscape 4.x has some problems...
BrowserMatch ^Mozilla/4 gzip-only-text/html
# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip
# Place in /config/initializers
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
if html_tag =~ /<(input|textarea|select|label)[^>]+style=/
style_attribute = html_tag =~ /class=['"]/
html_tag.insert(style_attribute + 7, "fieldWithErrors ")
elsif html_tag =~ /<(input|textarea|select|label)/
first_whitespace = html_tag =~ /\s/
html_tag[first_whitespace] = ' class="fieldWithErrors" '
end
html_tag
@beef
beef / init.d
Created December 9, 2009 15:52
Ubuntu Passanger nginx init.d
#! /bin/sh
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server
# Description: starts nginx using start-stop-daemon
@beef
beef / Grep a rails log
Created September 7, 2009 11:44
Regular expression to find log blocks for certain actions
#!/bin/bash
# using all types of newlines, search for a rails log header for a certain action of a certain controller
# copy and paste into terminal
pcregrep -MN ANY 'Processing FatController#action_man([^\n]*\n){10}' log/production.log
# Be sure to restart your server when you modify this file.
my_formats = {
:short_ordinal => '%d %B - %H:%M',
:short_dot => ' %d.%m.%y',
:long_dot => '%H:%M - %d.%m.%y',
:time => '%H:%M'
}
ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.merge!(my_formats)
Scenario: Create an Article
Given I am on the new article page
When I fill in the article details
And I press "Save"
Then I should be on articles admin page
And I should see 'Article successfully created'
Scenario: Update a article
Given there are saved articles
And I am on the articles admin page
class ActiveRecord::Base
protected
def self.construct_count_options_from_args(*args)
name_and_options = super
if name_and_options[0].is_a?(String)
if name_and_options[0].include?(',')
name_and_options[0] = "DISTINCT #{quoted_table_name}.#{primary_key}"
elsif name_and_options[0] =~ /\.\*$/
name_and_options[0] = '*'
end
server {
listen 80;
server_name dev.myapp.com;
root /var/www/staging/current/public;
passenger_enabled on;
rails_env staging;
}
server {
listen 80;