Skip to content

Instantly share code, notes, and snippets.

@camallen
camallen / readme.md
Created June 21, 2017 09:49 — forked from cosmincatalin/ readme.md
AWS EMR bootstrap to install R packages from CRAN

AWS EMR bootstrap to install R packages from CRAN

This bootstrap is useful if you want to deploy SparkR applications that run arbitrary code on the EMR cluster's workers. The R code will need to have its dependencies already installed on each of the workers, and will fail otherwise. This is the case if you use functions such as gapply or dapply.

How to use the bootstrap

  1. You will first have to download the gist to a file and then upload it to S3 in a bucket of your choice.
  2. Using the AWS EMR Console create a cluster and choose advanced options.
  3. In Step 3 you can configure your bootstraps. Choose to Configure and add a Custom action
@camallen
camallen / pre-commit
Created December 15, 2016 10:27 — forked from zwolf/pre-commit
A pre-commit hook for git to alert if ":focus" (or similar) is found in a + line of a diff
#!/usr/bin/env ruby
if `git diff HEAD spec` =~ /^\+.*,\s?(:focus|focus:\s?true|:focus\s?=>\s?true)/
puts "\e[31mPlease focus and remove your :focus tags before committing :)"
exit 1
end
@camallen
camallen / openid_access_token-decode.md
Created December 9, 2016 11:55 — forked from rafaeltuelho/openid_access_token-decode.md
Decoding an encoded oAuth JSON Web Token (JWT): access_token

Given an encoded (base64) JWT (access_token).

For example, see this sample OAuth2 response generated by JBoss APIMan/Keycloak

HTTP/1.1 200 OK
Connection: keep-alive
Content-Type: application/json
Date: Tue, 25 Aug 2015 19:25:12 GMT
@camallen
camallen / dump_mailer_worker_spec.patch
Last active December 8, 2016 12:28
dump_mailer_worker_spec.patch
diff --git a/spec/workers/concerns/dump_mailer_worker_spec.rb b/spec/workers/concerns/dump_mailer_worker_spec.rb
index e8e14c1..1e51277 100644
--- a/spec/workers/concerns/dump_mailer_worker_spec.rb
+++ b/spec/workers/concerns/dump_mailer_worker_spec.rb
@@ -1,8 +1,10 @@
require 'spec_helper'
describe DumpMailerWorker do
- let(:resource) { double(id: 1) }
-
@camallen
camallen / pg_find_unused_indexes.sql
Created December 2, 2016 13:44
PostgreSQL - find unused indexes
SELECT
relid::regclass AS table,
indexrelid::regclass AS index,
pg_size_pretty(pg_relation_size(indexrelid::regclass)) AS index_size,
idx_tup_read,
idx_tup_fetch,
idx_scan
FROM
pg_stat_user_indexes
JOIN pg_index USING (indexrelid)
@camallen
camallen / pg_locks.sql
Last active February 8, 2020 04:37 — forked from parrish/pg_locks.sql
Show info on postgres locks
SELECT bl.pid AS blocked_pid,
a.usename AS blocked_user,
ka.query AS current_statement_in_blocking_process,
now() - ka.query_start AS blocking_duration,
kl.pid AS blocking_pid,
ka.usename AS blocking_user,
a.query AS blocked_statement,
now() - a.query_start AS blocked_duration
FROM pg_catalog.pg_locks bl
JOIN pg_catalog.pg_stat_activity a ON a.pid = bl.pid
# IN PANOPTES
# link the legacy_zoo_id (old zoo home) to the new panoptes project id
migrated_ps = Project.where(migrated: true)
migrated_ps.map { |p| "#{p.name} - #{p.configuration["zoo_home_project_id"]} - #{p.id}" }
#=> ["penguin_watch - 35 - 55", "chimp_&_see - 41 - 60", "moon_zoo - 2 - 22", "galaxy_zoo - 1 - 21", "stardate_m83 - 29 - 49", "plankton_portal - 26 - 46", "galaxy_zoo_mergers - 4 - 24", "cyclone_center - 16 - 36", "chicago_wildlife_watch - 37 - 57", "microplants - 24 - 44", "science_gossip - 38 - 58", "whale_fm - 12 - 32", "bat_detective - 17 - 37", "asteroid_zoo - 33 - 53", "operation_war_diary - 28 - 48", "snapshot_serengeti - 20 - 40", "solar_stormwatch - 3 - 23", "ancient_lives - 10 - 30", "old_weather - 8 - 28", "galaxy_zoo_supernova - 5 - 25", "radio_galaxy_zoo - 27 - 47", "milky_way_project - 7 - 27", "worm_watch_lab - 25 - 45", "notes_from_nature - 22 - 42", "disk_detective - 30 - 50", "condor_watch - 32 - 52", "orchid_observers - 40 - 59", "ice_hunters - 9 - 29", "andr
@camallen
camallen / intersection_vs_include?.rb
Last active August 29, 2015 14:21
Array Intersection vs find / include?
require 'benchmark'
num = 1000000
uss = []
up_to_num = (1..num).to_a
repeat = 100
num_class_subject_ids = 5
Benchmark.bm do |x|
#full set intersection
x.report { repeat.times do |num| ; (up_to_num & [num]).empty? ; end }
@camallen
camallen / refactored_routes.rb
Created October 3, 2014 11:22
Example refactored routes
def post_link_relation(resource, constraint)
post "/links/:link_relation",
to: "#{resource}#update_links",
constraints: { link_relation: constraint },
format: false
end
def delete_link_relation(resource, constraint)
delete "/links/:link_relation/:link_ids",
to: "#{resource}#destroy_links",
@camallen
camallen / UniqueUserValidation.rb
Last active August 29, 2015 14:04
Quick spec to show the UriName model doesn't handle case-insensitive duplicate names
describe '#login' do
it 'should validate presence' do
expect{ User.create!(name: 't', password: 'password1', email: 'test@example.com') }.to raise_error
end
it 'should validate uniqueness' do
expect{ User.create!(name: 't', login: 't', password: 'password1', email: 'test@example.com') }.to_not raise_error
expect{ User.create!(name: 't', login: 't', password: 'password1', email: 'test2@example.com') }.to raise_error
expect{ User.create!(name: 'T', login: 'T', password: 'password1', email: 'test3@example.com') }.to raise_error
end