Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Happenings

Matt mjy

💭
Happenings
View GitHub Profile
@mjy
mjy / tw_api_basic_specimens.rb
Created Dec 1, 2020
A basic request to get specimen data back
View tw_api_basic_specimens.rb
require 'json'
require 'csv'
require 'amazing_print'
require 'uri'
require 'net/http'
project_token = 'adhBi59dc13U7RxbgNE5HQ'
URL = 'https://sfg.taxonworks.org/api/v1/'
url = URL + '/collection_objects' + '?project_token=' + project_token
View gist:02fc0bec94a3f0f4da792baad0df1a3f
Reinstalled MacOS from scratch once more to be absolutely sure the procedure works. The list of commands after this second reinstall were these:
(Installed Xcode and Firefox first)
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
\curl -sSL https://get.rvm.io | bash -s stable --ruby
brew edit proj
(Added patch referenced above)
brew install proj -s # Pay attention to -s argument, the patch won't be applied oherwiese.
brew install postgis
brew services start postgresql
View gist:9f49c6b108b1c7282dcd
concern :data_routes do |options|
collection do
get 'download'
get 'list'
post 'batch_preview'
get 'autocomplete'
end
member do
post 'search'
end
View index.html
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Edit point location (with georeferencing)</title>
<style type="text/css">
body {
margin: 0;
padding: 40px;
@mjy
mjy / gist:1319716
Created Oct 27, 2011
:constraint Route matching
View gist:1319716
The problem is pretty straightforward, for a rails 3.0.10 app (upgrading form 2.3.10, which uses match style routes), ruby, 1.9.2.
I have basic routes:
/projects/1/foo/bar/1.json # controller => foo, :action => bar, etc...
/projects/1/public/foo/bar/1.json # controller => public/foo, :action => bar, etc..
I need to match the "public/foo" controller first, if no public provided just match "foo" as the controller. The format needs to be optional.
My routes.rb:
View gist:855964
Solved by adding AllowEncodedSlashes On to the httpd.conf (must be in the virtual if using virtual).
I'm stumbling here because this is a problem that does not occur in dev, but does occur in production.
Last three routes-
map.connect ':controller/:action/:id.:format',
:controller => 'proj',
:requirements => {:action => /\w*/}
View gist:726098
named_scope :that_are_homonyms, {
:group => "sensus.label_id",
:joins => 'JOIN sensus on labels.id = sensus.label_id',
:select => "labels.*, count(distinct sensus.ontology_class_id) as total",
:having => 'total > 1'
}
When I do
bar.foo.that_are_homonyms.size # => 1000s (wrong)
View gist:724736
@specimens = Specimen.find(:all,
:include => [:ce, :otus],
:joins => "LEFT JOIN otu_groups_otus og ON otus.id = og.otu_id",
:conditions => "og.otu_group_id = 124")
View variants_generator.rb
require 'test/unit'
##
# Variant generator returns all possible combinations of elements of all given arrays.
# Running this gist will run the tests. For normal usage, simply copy VariantsGenerator module.
module VariantsGenerator
module_function
##
# Operates on arrays.
View VariantGenerator.rb
require 'test/unit'
#require 'ruby-debug'
##
# Variant generator returns all possible combinations of elements of all given arrays.
# Running this gist will run the tests. For functionality only this module is needed.
module VariantsGenerator
extend self
##
You can’t perform that action at this time.