Skip to content

Instantly share code, notes, and snippets.

View djones's full-sized avatar
🍍
' OR '1'='1

David Jones djones

🍍
' OR '1'='1
View GitHub Profile
#!/usr/bin/env ruby
require 'rubygems'
require 'hpricot'
require 'open-uri'
query = "//table//table//table//td/font/b"
html_doc = Hpricot(open("http://www.ccc.govt.nz/weatherdata/waterweb.htm")).search(query)
temperature = html_doc[0].inner_html.to_f
# Came from http://snippets.dzone.com/posts/show/68
require 'rexml/document'
require 'net/http'
class RSSParser
require 'rexml/document'
def self.run(url)
class PagesController < ApplicationController
def home
...
@posts = RSSParser.run('http://blog.resolvedigital.com/feed/')[:items]
...
end
end
<div id='blog'>
<h2>Fresh off the blog</h2>
<h3><%= link_to @posts.first[:title], @posts.first[:link] %></h3>
<p>
<%= truncate(strip_tags(@posts.first[:encoded]), :length => 285) %>
</p>
</div>
<div id='blog'>
<h2>Latest posts from the blog</h2>
<% 3.times do |n| %>
<h3>
<%= link_to @posts[n][:title], @posts[n][:link] %>
</h3>
<p>
<%= truncate(strip_tags(@posts[n][:encoded]), :length => 285) %>
</p>
<% end %>
= Setup
=== In your browser
login to http://github.com
go to http://github.com/resolve/refinerycms
if you have a fork already, delete it (if you're not going to loose work. This makes it much easier for us to integrate your changes back in)
click on fork
=== In terminal
git clone [email protected]:USERNAME/refinerycms.git refinerycms
@djones
djones / UIDevice+Utilities.h
Created August 14, 2010 03:33
A nicer way to do runtime conditional coding for iPad and iPhone/iPod Touch
@interface UIDevice (Utilities) {}
+ (BOOL)iPad;
@end
@djones
djones / Campfire Fluid Userstyle.css
Created September 10, 2010 00:43
Userstyle for using Campfire as a minimal Fluid App
/* Use match pattern: * */
#Header, body.chat.with_launchbar div#Header {
top: 0px !important;
}
#launchbar, #corner_logo, #Sidebar, #MainTabs li:nth-last-child(-n+6) {
display: none !important;
}
@djones
djones / blog_controller.rb
Created September 30, 2010 18:56
Shows how to get the latest posts from an external RSS feed into Refinery
class BlogController < ApplicationController
def index
begin
Timeout::timeout(5) {
@posts = RSSParser.run('http://refinerycms.com/blog.rss')[:items][0..3] # get the first 3 posts
}
rescue Timeout::Error => e
logger.warn("timeout exceeded for downloading blog RSS: #{e}")
@posts = nil
end
@djones
djones / twitter_controller.rb
Created September 30, 2010 23:15
Shows you how to get the latest tweets from RSS, cache them and display them in Refinery CMS
class TwitterController < ApplicationController
around_filter :cache_twitter, :only => [:twitter]
def twitter
begin
Timeout::timeout(5) {
result = RSSParser.run(RefinerySetting.find_or_set(:twitter_rss_feed_url,
"http://twitter.com/statuses/user_timeline/19258840.rss"))
@tweets = result[:items][0..0] if result.present? and result[:items].present?