Skip to content

Instantly share code, notes, and snippets.

View keypress.html
<!DOCTYPE html>
<html>
<head>
<title>on key press test</title>
<script>
function keyPress(e) {
var keynum, keychar;
if(window.event) { // IE
keynum = e.keyCode;
@jswanner
jswanner / gist:1324770
Created Oct 29, 2011
Get full sentence for query
View gist:1324770
> text = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.'
> query = 'veniam'
> pos = text =~ /#{query}/
=> 142
> prev_period = text.rindex('.', pos) || -1
=> 123
> next_period = text.index('.', pos) || -1
=> 231
> sentence = text[prev_period+1..next_period]
=> " Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."
View gist:1302999
# before
def self.front_page
where(:front_page => true).select('*, coalesce(position, 999999999) AS position').order('position ASC')
end
# after
def self.front_page
where(:front_page => true).select([
Arel.sql('*'),
Arel::Nodes::NamedFunction.new('COALESCE', [arel_table[:position], 999999999]).as('position')
@jswanner
jswanner / refineryedge.rb
Created Oct 20, 2011
Installing RefineryCMS on Edge
View refineryedge.rb
gem 'refinerycms', :git => 'git://github.com/gogogarrett/refinerycms.git', :branch => 'heroku'
run 'bundle install'
generate 'refinery:cms'
rake 'db:migrate'
append_file 'Gemfile' do
" # group :development, :test do
# gem 'refinerycms-testing', '~> 2.0'
# end
@jswanner
jswanner / Gemfile.diff
Created Oct 7, 2011
Differences between Rails 3.1.0.rc8 & Rails 3.1.1 generated apps
View Gemfile.diff
diff -U 0 -r rails-3.1.0.rc8/Gemfile rails-3.1.1/Gemfile
--- rails-3.1.0.rc8/Gemfile 2011-10-07 12:05:37.000000000 -0400
+++ rails-3.1.1/Gemfile 2011-10-07 12:59:13.000000000 -0400
@@ -3 +3 @@
-gem 'rails', '3.1.0.rc8'
+gem 'rails', '3.1.1'
@@ -14,3 +14,3 @@
- gem 'sass-rails', " ~> 3.1.0.rc"
- gem 'coffee-rails', "~> 3.1.0.rc"
- gem 'uglifier'
@jswanner
jswanner / Gemfile.diff
Created Oct 7, 2011
Differences between Rails 3.1.1.rc1 & Rails 3.1.1 generated apps
View Gemfile.diff
diff -U 0 -r rails-3.1.1.rc1/Gemfile rails-3.1.1/Gemfile
--- rails-3.1.1.rc1/Gemfile 2011-10-07 12:08:28.000000000 -0400
+++ rails-3.1.1/Gemfile 2011-10-07 12:59:13.000000000 -0400
@@ -3 +3 @@
-gem 'rails', '3.1.1.rc1'
+gem 'rails', '3.1.1'
@@ -14,2 +14,2 @@
- gem 'sass-rails', " ~> 3.1.0"
- gem 'coffee-rails', "~> 3.1.0"
+ gem 'sass-rails', '~> 3.1.4'
@jswanner
jswanner / Gemfile.diff
Created Oct 7, 2011
Differences between Rails 3.1.0.rc2 & Rails 3.1.1 generated apps
View Gemfile.diff
diff -U 0 -r rails-3.1.0.rc2/Gemfile rails-3.1.1/Gemfile
--- rails-3.1.0.rc2/Gemfile 2011-10-07 12:00:05.000000000 -0400
+++ rails-3.1.1/Gemfile 2011-10-07 12:59:13.000000000 -0400
@@ -3 +3 @@
-gem 'rails', '3.1.0.rc2'
+gem 'rails', '3.1.1'
@@ -10,4 +10,8 @@
-# Asset template engines
-gem 'sass-rails', "~> 3.1.0.rc"
-gem 'coffee-script'
@jswanner
jswanner / Gemfile.diff
Created Oct 7, 2011
Differences between Rails 3.1.0.rc6 & Rails 3.1.1 generated apps
View Gemfile.diff
diff -U 0 -r rails-3.1.0.rc6/Gemfile rails-3.1.1/Gemfile
--- rails-3.1.0.rc6/Gemfile 2011-10-07 12:04:34.000000000 -0400
+++ rails-3.1.1/Gemfile 2011-10-07 12:59:13.000000000 -0400
@@ -3 +3 @@
-gem 'rails', '3.1.0.rc6'
+gem 'rails', '3.1.1'
@@ -14,3 +14,3 @@
- gem 'sass-rails', " ~> 3.1.0.rc"
- gem 'coffee-rails', "~> 3.1.0.rc"
- gem 'uglifier'
@jswanner
jswanner / .gitignore.diff
Created Oct 7, 2011
Differences between Rails 3.1.0.beta1 & Rails 3.1.1 generated apps
View .gitignore.diff
diff -U 0 -r rails-3.1.0.beta1/.gitignore rails-3.1.1/.gitignore
--- rails-3.1.0.beta1/.gitignore 2011-10-07 11:56:15.000000000 -0400
+++ rails-3.1.1/.gitignore 2011-10-07 12:59:12.000000000 -0400
@@ -4,0 +5 @@
+.sass-cache/
@jswanner
jswanner / Gemfile.diff
Created Oct 7, 2011
Differences between Rails 3.1.0.rc1 & Rails 3.1.1 generated apps
View Gemfile.diff
diff -U 0 -r rails-3.1.0.rc1/Gemfile rails-3.1.1/Gemfile
--- rails-3.1.0.rc1/Gemfile 2011-10-07 11:57:59.000000000 -0400
+++ rails-3.1.1/Gemfile 2011-10-07 12:59:13.000000000 -0400
@@ -3 +3 @@
-gem 'rails', '3.1.0.rc1'
+gem 'rails', '3.1.1'
@@ -10,4 +10,8 @@
-# Asset template engines
-gem 'sass'
-gem 'coffee-script'