Skip to content

Instantly share code, notes, and snippets.

View danielcooper's full-sized avatar

Daniel Cooper danielcooper

View GitHub Profile
{{ 'world' | prepend:'hello' | upcase }}
template = "{{foo}}"
Liquid::Template.parse(template).render({'foo' => 'bar'})
{% rss source: http://rubysource.com/feed/%}
<article class='main rss_list'>
<h1>{{ feed.title }}</h1>
{% for item in feed.items limit:3%}
<section>
<h1><a href='{{item.link}}'>{{item.title}}</a></h1>
<p>{{item.description}}</p>
</section>
<hr/>
{%endfor%}
class RenderRSS < Liquid::Block
def initialize(tag_name, markup, tokens)
super
@markup = markup
@attributes = {}
markup.scan(Liquid::TagAttributes) do |key, value|
@attributes[key] = value
end
class PostsController < ActionController::Base
after_filter :set_http_cache, :only => :index
private
def set_http_cache
expires_in(30.seconds, :public => true)
end
end
@danielcooper
danielcooper / gist:1981912
Created March 5, 2012 23:16
Mass Assignment
class User < ActiveRecord::Base
end
class UsersController < ApplicationController
def update
User.find(params[:id]).update_attributes(params[:user])
end
end
@danielcooper
danielcooper / gist:1893730
Created February 23, 2012 16:55
Kris should have stayed at homeflow
# This gets X users within a distance of '10' radians
user = User.find_me_a_bloody_user
result = ActiveRecord::Base.connection.execute("
SELECT
((ACOS( SIN( #{user.lat} * PI( ) /180 ) * SIN( latitude * PI( ) /180 ) + COS( #{user.lat} * PI( ) /180 ) * COS( latitude * PI( ) /180 ) * COS( (
#{user.lng} - longitude) * PI( ) /180 ) ) *180 / PI( ) ) *60 * 1.1515)