Skip to content

Instantly share code, notes, and snippets.

Brice M. bricemaurin

View GitHub Profile
View gist:f193ed64ba67b2d0ef68
class Post < ActiveRecord::Base
default_scope order('votes DESC')
belongs_to :user
validates :name, :url, :user, presence: true
validates :name, length: { minimum: 5 }
validates :name.downcase, uniqueness: { case_sensitive: false }
validates :url, format: { with: /\Ahttps?\:\/\/(?:www\.|)?\w+\.\w{2,3}(?:\/\w+)?/, message: "invalid url" }
end
class User < ActiveRecord::Base
View Google Docs Script
function FBshares(url) {
var jsondata = UrlFetchApp.fetch("http://graph.facebook.com/"+url);
var object = Utilities.jsonParse(jsondata.getContentText());
return object.shares;
}
function Tweets(url) {
var jsondata = UrlFetchApp.fetch("http://urls.api.twitter.com/1/urls/count.json?url="+url);
var object = Utilities.jsonParse(jsondata.getContentText());
return object.count;
You can’t perform that action at this time.