Skip to content

Instantly share code, notes, and snippets.

🍐
Working on a relaunch.

Charlie Park charliepark

🍐
Working on a relaunch.
Block or report user

Report or block charliepark

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Using Rails to find values within a range
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 ...
View gist:54552
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
View jQuery - update an object's z-index based on the current time.
/*
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 }
View A Minimalist CSS Grid Framework
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
View some attractive text CSS
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;}
View .htaccess code
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>
View Capistrano with Passenger
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
View Setting up a server on SliceHost
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
View input placeholder text from Jacob Bijani.html
<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';
}
View CSS_gradients.css
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/ */
You can’t perform that action at this time.