Skip to content

Instantly share code, notes, and snippets.

View andresgutgon's full-sized avatar
:octocat:
Coding things...

Andrés andresgutgon

:octocat:
Coding things...
  • Barcelona
View GitHub Profile
@andresgutgon
andresgutgon / gist:889118
Created March 27, 2011 10:49
Google Static Map
#application_helper.rb
def google_static_map_image_path(address,options={})
size = options[:size]? options[:size] : "220x220"
zoom = options[:zoom]? options[:zoom] : "16"
maptype = options[:maptype]? options[:maptype] : "roadmap"
sensor = options[:sensor]? "true" : "false"
query_string = "center=#{address.address_path}&zoom=#{zoom}&size=#{size}&maptype=#{maptype}&sensor=#{sensor}&markers=#{address.address_path}"
base_url="http://maps.google.com/maps/api/staticmap?#{query_string}"
end
@andresgutgon
andresgutgon / _base.sass
Created December 8, 2011 17:58
Susy set up
// Imports -------------------------------------------------------------------
@import "compass/reset"
@import "compass/typography"
@import "compass/css3"
@import "compass/layout"
@import "compass/utilities"
@import "compass/typography/vertical_rhythm"
//Grid ------------------------------------------------------------------
//Sorry susy has to be imported
@andresgutgon
andresgutgon / Gemfile
Created December 8, 2011 19:29
Compass not working in rails 3.1
group :assets do
gem 'sass-rails', "~> 3.1.0"
#gem 'coffee-rails', "~> 3.1.0"
gem 'uglifier'
gem "compass", "~> 0.12.alpha"
gem "compass-rgbapng", :require => "rgbapng"
gem "compass-susy-plugin", :require => "susy"
gem 'tinymce-rails'
end
map.namespace :users, :as => "members",:name_prefix => 'user' do |user|
user.resources :users,:path_prefix => "", :name_prefix => '',:except => [:destroy,:edit,:index,:show,:update,:create,:new,:send_email] do |user|
user.resources :projects, :except => [:destroy] do |project|
project.resources :collaborators,
:name_prefix => '',
:only => [:new,:edit,:create, :update],
:collection => {:order => :post, :search => :get}
end
end
end
@andresgutgon
andresgutgon / index.js.erb
Created December 17, 2011 14:39 — forked from ryanb/index.js.erb
Infinite scrolling solution covered in revised episode #114: http://railscasts.com/episodes/114-endless-page-revised
$('#products').append('<%= j render(@products) %>');
<% if @products.next_page %>
$('.pagination').replaceWith('<%= j will_paginate(@products) %>');
<% else %>
$('.pagination').remove();
<% end %>
@andresgutgon
andresgutgon / user.rb
Created January 8, 2012 13:28
Migrate Autholugic SHA512 Passwords to BCryt Devise Passwords
# Because we have some old legacy users in the database, we need to override Devises method for checking if a password is valid.
# We first ask Devise if the password is valid, and if it throws an InvalidHash exception, we know that we're dealing with a
# legacy user, so we check the password against the SHA1 algorithm that was used to hash the password in the old database.
#SOURCES OF SOLUTION:
# http://stackoverflow.com/questions/6113375/converting-existing-password-hash-to-devise
# https://github.com/binarylogic/authlogic/blob/master/lib/authlogic/crypto_providers/sha512.rb
# https://github.com/plataformatec/devise/blob/master/lib/devise/encryptors/authlogic_sha512.rb
alias :devise_valid_password? :valid_password?
def valid_password?(password)
@andresgutgon
andresgutgon / Ejemplo
Created March 4, 2012 12:42
Limpiar TextArea
Ejemplo: http://visca.cat/es/research/projects/temporal-and-spatial-effects-on-awareness-of-reachability
@andresgutgon
andresgutgon / clean_description.rake
Created March 4, 2012 17:56
Limpiar TextArea en Rails 3
require File.expand_path(File.dirname(__FILE__) + "/../sanitize_tinymce_text")
include SanitizeTinymceText
namespace :html do
desc "Limpiar descripciones guarrillas con css inline y spans"
task :clean => :environment do
Publication.all.each do |pub|
pub.abstract = sanitize_text(pub.abstract)
pub.save
@andresgutgon
andresgutgon / author.rb
Created March 18, 2012 12:31
Metaprogramacion
has_many :author_positions, :dependent => :destroy, :order => "position"
has_many :publications, :through => :author_positions
has_many :collaborator_positions, :dependent => :destroy, :order => "position"
has_many :projects, :through => :collaborator_positions
has_many :teacher_positions, :dependent => :destroy, :order => "position"
has_many :courses, :through => :teacher_positions
#author.publications => Listado publicaciones
@andresgutgon
andresgutgon / splash.js
Created March 18, 2012 18:52
Escribir cookie para no molestar al visitante mas de una vez
function splash_window(){
// Busco con js la cookie
var splash = jQuery.cookie('splash');
if(splash==null){
// Si no la encuentro la escribo en su navegador
document.cookie = 'splash=1; path=/; expires=' + new Date(2030,1,15).toUTCString();
//Como no la he encontrado le lanzo el popup
// Si ya la tuviera no entraria por aqui.
jQuery(document).bind('init.facebox',function() {