Skip to content

Instantly share code, notes, and snippets.

class BQDatasetAuthorizer(ContextDecorator):
def __init__(self, target, profile_file):
self.target = target
self.profile_file = profile_file
# this dict maps a dataset to a list of BigQuery Access entries defined by code.
# We expect groupByEmail and View.
# https://googleapis.dev/python/bigquery/latest/generated/google.cloud.bigquery.dataset.AccessEntry.html
self.auth_dict = defaultdict(list)
def __enter__(self):
@stujo
stujo / GitHub curl.sh
Last active February 15, 2019 21:39 — forked from Integralist/GitHub curl.sh
Download a single file from a private GitHub repo. You'll need an access token as described in this GitHub Help article: https://help.github.com/articles/creating-an-access-token-for-command-line-use
#!/usr/bin/env bash
TOKEN="INSERTACCESSTOKENHERE"
OWNER="BBC-News"
REPO="responsive-news"
FILE_PATH="scripts/build/tabloid.sh"
FILE="https://api.github.com/repos/$OWNER/$REPO/contents/$FILE_PATH"
curl --header "Authorization: token $TOKEN" \
--header 'Accept: application/vnd.github.v3.raw' \
@stujo
stujo / ab.sh
Created April 3, 2018 18:15 — forked from brentertz/ab.sh
Apache Bench - Load test a protected page
#!/bin/bash
COOKIE_JAR="ab-cookie-jar"
COOKIE_NAME="_myapp_session"
USERNAME="[email protected]"
PASSWORD="password"
LOGIN_PAGE_URI="http://localhost:3000/users/sign_in"
TEST_PAGE_URI="http://localhost:3000/dashboard"
echo "Logging in and storing session id."
@stujo
stujo / ab.sh
Created April 3, 2018 18:15 — forked from brentertz/ab.sh
Apache Bench - Load test a protected page
#!/bin/bash
COOKIE_JAR="ab-cookie-jar"
COOKIE_NAME="_myapp_session"
USERNAME="[email protected]"
PASSWORD="password"
LOGIN_PAGE_URI="http://localhost:3000/users/sign_in"
TEST_PAGE_URI="http://localhost:3000/dashboard"
echo "Logging in and storing session id."
@stujo
stujo / atom_helper_sample.txt
Created January 24, 2017 19:03
Atom Helper Sample During Freeze with webpack esformatter and eslint
Sampling process 7644 for 3 seconds with 1 millisecond of run time between samples
Sampling completed, processing symbols...
Analysis of sampling Atom Helper (pid 7644) every 1 millisecond
Process: Atom Helper [7644]
Path: /Applications/Atom.app/Contents/Frameworks/Atom Helper.app/Contents/MacOS/Atom Helper
Load Address: 0x10279b000
Identifier: com.github.atom.helper
Version: 1.13.0 (1.13.0)
Code Type: X86-64
Parent Process: Atom [6943]
@stujo
stujo / session-auth-sinatra-app.rb
Created January 6, 2017 00:28
sinatra session auth example (without database)
require 'sinatra'
enable :sessions
# helpers/session_helper.rb
helpers do
def session_user_id
session[:user_id]
end
@stujo
stujo / codewars-test-stubs.js
Last active January 2, 2017 06:21
code-wars-test-stubs.js
var Test = {
describe: Test_describe,
before: Test_before,
expect: Test_expect,
it: Test_it,
context: Test_context,
contexts: [],
assertEquals: Test_assertEquals,
logError: Test_logError,
logSuccess: Test_logSuccess,
@stujo
stujo / example-extends-vs-includes.rb
Last active December 19, 2016 18:24
How to include a module
module Timeable
def start_timer
@timeable_timer = Time.now.utc
end
def end_timer
Time.now.utc - @timeable_timer
end
end
class DragRace
@stujo
stujo / mutable_string.rb
Last active December 19, 2016 18:23
Mutable Strings in Ruby
puts "Assign bob = \"bob\""
bob = "bob"
puts "bob_smith is also a bob"
puts "So bob_smith = bob (the variable reference)"
bob_smith = bob
puts "We want to capitalize bob so : bob.capitalize!"
@stujo
stujo / abstract_method_pattern.rb
Created December 12, 2016 22:39
Using Mix-Ins with the Abstract Method Pattern
# The SuperPower blast_them method depends on the abstract method projectile
module Blastable
def blast_them
puts "BLASTING: #{projectile} (#{self.class.name})"
end
end
class Tyrannosaurus
include Blastable