Skip to content

Instantly share code, notes, and snippets.

View jaimeiniesta's full-sized avatar

Jaime Iniesta jaimeiniesta

View GitHub Profile
A small test to know if Rails 3 will double-escape already escaped strings, say, you've got your typical h(str), will str be escaped once by default and then escaped once again by h()? It does not look like this will happen (tried with rails 2.3.5 and the rails_xss plugin)
### .erb file
<% str = "A string that needs <strong>escaping</strong>" %>
<p>
Not escaped: <%= str %>
</p>
<p>
Escaped with h: <%= h str %>
feature "Articles", %q{
In order to manage articles
As an editor
I want to create, list, show, edit, update and destroy articles
} do
background do
Article.create(:title => 'First article', :body => 'My first article')
Article.create(:title => 'Second article', :body => 'My second article')
Article.create(:title => 'Third article', :body => 'My third article')
require "net/http"
module GooglePageRank
M=0x100000000 # modulo for unsigned int 32bit(4byte)
def m1(a,b,c,d)
return (((a+(M-b)+(M-c))%M)^(d%M))%M # mix/power mod
end
class SitemapController < ApplicationController
def sitemap
@plants = Plant.find(:all)
respond_to do |format|
format.xml
end
end
Bundler reports nearly 60 gems to be used by pagerankalert.com and its dependencies
-----> Gemfile detected, running Bundler version 1.0.0.rc.5
Unresolved dependencies detected; Installing...
Fetching source index for http://rubygems.org/
Fetching git://github.com/jaimeiniesta/metainspector.git
Fetching git://github.com/cavalle/steak.git
Installing rake (0.8.7)
Installing abstract (1.0.0)
Installing activesupport (3.0.0.rc)
# encoding: UTF-8
# Guess the charset encoding of a given input, by submitting it to vote to different guessers.
require 'rubygems'
require 'open-uri'
if RUBY_VERSION > "1.9"
# ruby encodings only work on 1.9
class Yukihiro
def guess_charset(str)
# spec/acceptance/blog_spec.rb
require File.dirname(__FILE__) + '/acceptance_helper'
feature "Feature name", %q{
In order to have a blog
As an administrator
I want to manage posts
} do
# Example on how to get the local file path for an attachment_fu attachment on a model
# (photos, in this example)
def attachment_fu_local_file_path
Rails.root+"/public/photos/"+("%08d" % id).scan(/..../).join('/')+"/"+filename
end