Skip to content

Instantly share code, notes, and snippets.

View charliepark's full-sized avatar
🚀

Charlie Park charliepark

🚀
View GitHub Profile
From Rails changeset 5876: http://dev.rubyonrails.org/changeset/5876
A range may be used in the hash to use the SQL BETWEEN operator:
Student.find(:all, :conditions => { :grade => 9..12 })
... so, presumably ...
User.find(:all, :conditions => { :created_at => '2009-01-01'..'2009-02-01' })
... compare with ...
Friendlier Error Messages
(from http://apidock.com/rails/ActionView/Helpers/ActiveRecordHelper/error_messages_for#82-Friendlier-error-message-example)
The default error messages can be a bit stale and off putting. Try somethings like this:
error_messages_for(
:user,
:header_message => "Oops - We couldn't save your user!",
:message => "The following fields were a bit of a problem:",
:header_tag => :h1
/*
A way to set your z-index to dynamically update, based on the current time.
When you click on the object ('.element'), the javascript grabs the current time,
concatenates the hours, minutes, and seconds, and sets that number as the z-index for the object.
*/
$('.element').mousedown(function(event) {
var time = new Date();
var hours = time.getHours();
if (hours.toString().length == 1) { hours = "0" + '' + hours }
This is intended to be a minimalist alternative to Blueprint (www.blueprintcss.org) and other, more fleshed-out CSS grid frameworks. Change 3 variables, and the framework does the rest for you. It's intended for use in Ruby / Rails applications.
========
Put the following in the <head> of your ERB file (either in a layout file or in a partial, if you're calling it from several pages):
<style type="text/css">
.g{BACKGROUND:RGBA(255,0,0,0.2)}
<%
num = number_of_columns = 16
body {font-family:'helvetica neue', helvetica, arial, sans-serif;}
h1 {font-size:24px;line-height:26px;margin:10px 0 18px;}
p{font-size:14px;line-height:18px;margin:0 0 18px;}
place this in public/.htaccess
FileETag none
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript
<IfModule mod_expires.c>
ExpiresActive on
ExpiresByType image/png "access plus 1 year"
ExpiresByType text/css "access plus 1 year"
</IfModule>
namespace :deploy do
desc "Restarting mod_rails with restart.txt"
task :restart, :roles => :app, :except => { :no_release => true } do
run "touch #{current_path}/tmp/restart.txt"
end
[:start, :stop].each do |t|
desc "#{t} task is a no-op with mod_rails"
task t, :roles => :app do ; end
end
FOLLOW THESE TUTORIALS:
SET UP UBUNTU
1. http://articles.slicehost.com/2008/11/28/ubuntu-intrepid-setup-page-1
2. http://articles.slicehost.com/2008/11/28/ubuntu-intrepid-setup-page-2
SET UP RUBY / RAILS
3. http://articles.slicehost.com/2009/1/6/ubuntu-intrepid-ruby-on-rails
SET UP APACHE
<input type="text" class="text_field placeholder_content"
value="Default value"
onfocus="
if (this.className == 'text_field placeholder_content') {
if (! this.getAttribute('default_value')) {
this.setAttribute('default_value', this.value);
}
this.value = '';
this.className = 'text_field';
}
background: #999; /* for non-css3 browsers */
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#cccccc', endColorstr='#000000'); /* for IE */
background: -webkit-gradient(linear, left top, left bottom, from(#ccc), to(#000)); /* for webkit browsers */
background: -moz-linear-gradient(top, #ccc, #000); /* for firefox 3.6+ */
/* from http://www.webdesignerwall.com/tutorials/cross-browser-css-gradient/ */