Skip to content

Instantly share code, notes, and snippets.

View tokumine's full-sized avatar

tokumine

  • London, UK
View GitHub Profile
# 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:
#
Recording a users classification
================================
POST /classifications/1
variables expected:
value = true/false
method = 'PUT'
// 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
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|
#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
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
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
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
# 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
class StarWarsCharacters < ActiveRecord::Base
named_scope :born_on_tatooine, :conditions => ["birthplace LIKE ?", "Tatooine"]
end
class Jedi < StarWarsCharacters
end
class Sith < StarWarsCharacters
end