This file contains hidden or 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
# Backup Configuration File | |
# | |
# Use the "backup" block to add backup settings to the configuration file. | |
# The argument before the "do" in (backup "argument" do) is called a "trigger". | |
# This acts as the identifier for the configuration. | |
# | |
# In the example below we have a "mysql-backup-s3" trigger for the backup setting. | |
# All the configuration is done inside this block. To initialize the backup process for this block, | |
# you invoke it using the following command: | |
# |
This file contains hidden or 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
Recording a users classification | |
================================ | |
POST /classifications/1 | |
variables expected: | |
value = true/false | |
method = 'PUT' |
This file contains hidden or 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
// Countries will be returned in an array when doing a search or index | |
// Limited to 10 results per query/page | |
// /api2/countries -> All countries | |
// /api2/countries?page=2 -> Paginatable | |
// /api2/countries?q="Britain" (Or Great Britain) -> free text search | |
// /api2/countries?iso="GB" (searches ISO2 and ISO3) -> ISO specific search | |
// /api2/countries?lat=x&lng=y -> GIS search point data | |
// /api2/countries?blx=x&bly=y&trx=a&try=b -> GIS search BBOX |
This file contains hidden or 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| |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 | |