Skip to content

Instantly share code, notes, and snippets.

@MrTin
MrTin / async.js
Created March 9, 2018 15:45 — forked from bschwartz757/async.js
Async/await function to fetch data from multiple URLs in parallel
/* Client side, works in Chrome 55 and Firefox 52 without transpilation */
//https://blogs.msdn.microsoft.com/typescript/2016/11/08/typescript-2-1-rc-better-inference-async-functions-and-more/
async function fetchURLs() {
try {
// Promise.all() lets us coalesce multiple promises into a single super-promise
var data = await Promise.all([
/* Alternatively store each in an array */
// var [x, y, z] = await Promise.all([
// parse results as json; fetch data response has several reader methods available:
//.arrayBuffer()
@MrTin
MrTin / gist:152062a6547a6660b6ae9e176f3ad01f
Created September 20, 2017 16:15
Self-signed Wildcard SSL
openssl genrsa 2048 > host.key
openssl req -new -x509 -nodes -sha1 -days 3650 -key host.key > host.cert
#[enter *.domain.com for the Common Name]
openssl x509 -noout -fingerprint -text < host.cert > host.info
cat host.cert host.key > host.pem
chmod 400 host.key host.pem
@MrTin
MrTin / tableau-read-access.sql
Created July 26, 2017 10:08
Setup read access on select tables to Tableu Server.
CREATE ROLE tableau WITH LOGIN ENCRYPTED PASSWORD 'secretpassword123' NOSUPERUSER INHERIT NOCREATEDB NOCREATEROLE NOREPLICATION VALID UNTIL 'infinity';
GRANT CONNECT ON DATABASE 'my_database' TO tableau;
GRANT USAGE ON SCHEMA public TO tableau;
GRANT SELECT ON public.my_table, public.another_table, public.third_table TO tableau;
GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO tableau;
@MrTin
MrTin / tableau-read-access.sql
Last active July 26, 2017 10:07
Setup read access Tableu user
CREATE ROLE tableau WITH LOGIN ENCRYPTED PASSWORD 'secretpassword123' NOSUPERUSER INHERIT NOCREATEDB NOCREATEROLE NOREPLICATION VALID UNTIL 'infinity';
GRANT CONNECT ON DATABASE 'my_database' TO tableau;
GRANT USAGE ON SCHEMA public TO tableau;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO tableau;
GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO tableau;
@MrTin
MrTin / aws-elasticsearch_rails.rb
Created July 2, 2017 19:50
AWS Elasticsearch and Rails
require "faraday_middleware/aws_signers_v4"
class AmazonElasticSearchClient
def self.client
return Elasticsearch::Client.new(url: ENV["AWS_ELASTICSEARCH_URL"]) do |f|
f.request :aws_signers_v4,
service_name: 'es',
credentials: Aws::Credentials.new(ENV["AWS_ACCESS_KEY_ID"], ENV["AWS_SECRET_ACCESS_KEY"]),
region: ENV["AWS_REGION"],
# This is standard for Net::HTTP, if you
docker rmi $(docker images | grep "^<none>" | awk '{print $3}')
docker rmi -f $(docker images --filter "dangling=true" | awk '{print $3}')
@MrTin
MrTin / Gemfile
Last active June 2, 2017 15:18 — forked from jrgifford/Gemfile
Using Amazon Elasticsearch securely (signed requests) with Rails & searchkick gem on Heroku.
gem 'elasticsearch', '>= 1.0.15'
gem 'elasticsearch-model'
gem 'elasticsearch-rails'
gem 'patron'
gem 'faraday_middleware-aws-signers-v4'
gem 'searchkick'
from raven.contrib.django.raven_compat.models import client as sentry_client
class SentryMiddleware(object):
def on_error(self, error):
# Track error with sentry...
# I intentionally left this part out as I have not been able to try it out.
# You can look at my first example for inspiration.
def resolve(self, next, root, args, context, info):
return next(root, args, context, info).catch(self.on_error)
@MrTin
MrTin / django-graphene_sentry.py
Created March 2, 2017 22:43
Make django-graphene send errors to Sentry
# views.py
from graphene_django.views import GraphQLView
from raven.contrib.django.raven_compat.models import client as sentry_client
class SentryGraphQLView(GraphQLView):
def execute_graphql_request(self, *args, **kwargs):
"""Extract any exceptions and send them to Sentry"""
result = super().execute_graphql_request(*args, **kwargs)
if result.errors:
@MrTin
MrTin / install-comodo-ssl-cert-for-nginx.rst
Created December 27, 2016 01:11 — forked from bradmontgomery/install-comodo-ssl-cert-for-nginx.rst
Steps to install a Comodo PositiveSSL certificate with Nginx.

Setting up a SSL Cert from Comodo

I use Namecheap.com as a registrar, and they resale SSL Certs from a number of other companies, including Comodo.

These are the steps I went through to set up an SSL cert.

Purchase the cert