Skip to content

Instantly share code, notes, and snippets.

@wykhuh
wykhuh / readme.md
Last active February 11, 2019 21:21

SWDchallenge Febraury Challenge

I examined the number of recreational visitors to the nine California National Parks in 2017. I used a combination of charts to examine the attendance variation between parks, months, and even temperatures.

Charts created with Flourish.

SELECT
(
SELECT ARRAY_AGG(coalesce(ncbi_nodes.superkingdom, '--') || '|' || coalesce(ncbi_nodes.kingdom, '--'))
FROM ncbi_nodes
WHERE taxon_id in (SELECT ncbi_names.taxon_id from ncbi_names where lower(gbif_ct.class_name) = lower(ncbi_names.name))
) AS ncbi_taxa
FROM combine_taxa as gbif_ct

fine prior to 5.1

class A < ApplicationRecord

has_many :foo, through: :boo
has_many :boo
@wykhuh
wykhuh / code.rb
Last active June 8, 2018 20:52
Ruby: splat array with string interpolation
# https://bugs.ruby-lang.org/issues/10930
ids = [1, 2, 3]
sql = "SELECT * FROM table WHERE id IN (#{ids.to_s[1..-2]})"
ActiveRecord::Base.connection.execute(sql)
@wykhuh
wykhuh / commands.bash
Last active May 25, 2018 23:41
import specific tables into heroku
// export tables from local database
pg_dump -Fc --no-acl --no-owner -t taxa -t taxa_names --data-only my_database > taxa.dump
// import tables into heroku
pg_restore --verbose --no-acl --no-owner -t taxa -t taxa_names -d postgres://user:password@host:port/database taxa.dump
@wykhuh
wykhuh / controller.rb
Created May 25, 2018 23:21
autocomplete
class AutocompleteController < ApplicationController
def index
query = params[:query].downcase
taxa = ::Taxon.where('lower("name") like ?', "#{query}%")
.limit(10)
render json: taxa
end
end
@wykhuh
wykhuh / .block
Last active April 20, 2018 18:24
Stacked Bar Chart
license: mit
@wykhuh
wykhuh / .block
Created April 17, 2018 23:19
fresh block
license: mit
@wykhuh
wykhuh / .block
Last active April 17, 2018 23:16
fresh block
license: mit
connect to database
var file = './db/library.db';
var sqlite3 = require('sqlite3').verbose();
var db = new sqlite3.Database(file);