This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Me = 5.freeze | |
# => 5 | |
Me.frozen? | |
# => false | |
#??? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Rails | |
class << self | |
def configuration | |
@@configuration | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Who's up to a post-railsconfeu08-coolest-quotes-tshirt-site? | |
Rails doesn't scale! (Oscar Wilde) | |
Look at all the things I'm not doing! (DHH) | |
Most people don't need Zulu on your website. (Josh Harvey) | |
That is sooo "Linux"! (Jeremy Kemper) | |
Fork this + add your favorite quotes! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class StarWarsCharacters < ActiveRecord::Base | |
named_scope :born_on_tatooine, :conditions => ["birthplace LIKE ?", "Tatooine"] | |
end | |
class Jedi < StarWarsCharacters | |
end | |
class Sith < StarWarsCharacters | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Username or email login for restful_authentication in user.rb model | |
def self.authenticate(login, password) | |
return nil if login.blank? || password.blank? | |
u = find_in_state :first, :active, :conditions => ["email = ? OR login = ?",login,login] # need to get the salt | |
u && u.authenticated?(password) ? u : nil | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module VersioningMethods | |
def self.included(klass) | |
klass.instance_eval <<-EOF | |
def deleted_list | |
deleted_item_list = [] | |
Version.all.sort_by{ |version| version[:created_at] }.reverse!.each do |version| | |
if version.item_type == "#{klass.name}" && version.event == 'destroy' | |
deleted_item_list << version.reify |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module VersioningMethods | |
def self.included(klass) | |
klass.instance_eval <<-EOF | |
def deleted_list | |
deleted_item_list = [] | |
Version.all.sort_by{ |version| version[:created_at] }.reverse!.each do |version| | |
if version.item_type == "#{klass.name}" && version.event == 'destroy' | |
deleted_item_list << version.reify |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
desc "populate dataset table" | |
task :load_sources => :environment do | |
Dataset.delete_all | |
user = User.find_by_username "WCMC" | |
Dataset.create :citation => "WDPA v1", :user => user | |
sources = DataImport.find_by_sql(["SELECT DISTINCT(source) from data_import"]) | |
sources.each do |source| | |
if (data_there? source.source) | |
Dataset.create :citation => source.source, :user => user | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#CLUSTERING OF PA'S FOR ABSTRACT AND RELATEDNESS MEASURES | |
#1) AIM: CREATE A DICTIONARY OF "BAD TERMS" TO EXCLUDE FROM FURTHER ANALYSIS | |
# METHOD: TOKENISE ALL WORDS AND HISTOGRAM. SORT. | |
tokens = {} | |
pas = Pa.find_each( :select => 'DISTINCT name_eng, gid', :batch_size => 100 ) do |p| | |
p.name_eng.split(/\W/).each do |t| | |
tokens[t] ||=0 | |
tokens[t] += 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module GeomHelper | |
def self.geojson_to_wkt geojson | |
#PARSE GEOJSON INTO NICE RING STRINGS | |
json = JSON.parse geojson | |
polys = json["coordinates"] | |
polygons = [] | |
polys.each do |poly| | |
rings = [] | |
poly.each do |ring| |
OlderNewer