Skip to content

Instantly share code, notes, and snippets.

@brycefisher
brycefisher / keybase.md
Created December 9, 2017 03:47
keybase.md

Keybase proof

I hereby claim:

  • I am brycefisher on github.
  • I am bff (https://keybase.io/bff) on keybase.
  • I have a public key ASBZB5Tjeib9trqDLSZppdt5o1m8d8wAylr_Jmdkl3fMJgo

To claim this, I am signing this object:

@brycefisher
brycefisher / math.py
Last active May 12, 2017 00:26
Estimate Costs for Burst Mode
#!/usr/bin/env python3
# TODO -- Debug this logic. It doesn't quite seem to give the expected results.
import csv
filename = 'pre-failover.csv'
HOUR = 60
max_wait = 1
TASKS_PER_INSTANCE = 6
@brycefisher
brycefisher / restore-fo-api.sh
Created October 4, 2016 16:15
Mongorestore fulfillment options
#!/bin/bash
mongorestore --drop -d fulfillment_options_development $HOME/.goodeggs-data-dumps/fulfillment-options/
<!DOCTYPE html>
<html>
<head>
<title>Play Time</title>
</head>
<body>
<form>
<input type="file" id="file-chooser" />
<button id="upload-button">Upload to S3</button>
<div id="results"></div>
// Implements the signing example w/out AWS SDK in nodejs. See:
// http://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-streaming.html
const crypto = require('crypto');
function signingKey(secretAccessKey, region, service, datetime) {
var date = datetime.substr(0, 8);
var kDate = crypto.createHmac('sha256', 'AWS4' + secretAccessKey).update(date).digest();
var kRegion = crypto.createHmac('sha256', kDate).update(region).digest();
var kService = crypto.createHmac('sha256', kRegion).update(service).digest();
return crypto.createHmac('sha256', kService).update('aws4_request').digest('hex');
@brycefisher
brycefisher / settings.php
Created November 12, 2013 16:55
How to Retrieve Environment Variables in Drupal settings.php
<?php
//...
// Store the database credentials serialized in an environmental variable.
$db_creds = unserialize(getenv('DRUPAL_DB_CRED'));
$databases = array (
'default' =>
array (
'default' => $db_creds,
@brycefisher
brycefisher / gist:7344428
Created November 6, 2013 21:29
Drupal6: Create dummy translations of all nodes in a content type via drush script
<?php
/**
* @file
* This is a drush script designed to create fake translations of the genera pages for development purposes ONLY.
*
* NOTE:
* -----
* This file must be located somewhere inside the drupal root.
*
* USAGE:
@brycefisher
brycefisher / gist:7328057
Created November 5, 2013 23:12
drupal - create arbitrary number of placeholders for a SQL injection resistant db_query() call
<?php
$nids = array(1, 2, 3, 4, 5);
// This is the key piece to understand -- it creates as many placeholder as you want based on the length of $nids array.
$placeholders = implode(',', array_fill(0, count($nids), '%d'));
$results = db_query("
select r.title
from {node_revisions} r
join {node} n
@brycefisher
brycefisher / gist:7030684
Created October 17, 2013 19:20
Create Related Partner Nodequeue
/**
* Create a nodequeue.
*/
function _brightcove_marketing_solutions_create_nodequeue() {
$nodequeue = new stdClass;
// $nodequeue->api_version = 2;
$nodequeue->name = 'marketing_solutions_related_partners';
$nodequeue->title = 'Marketing solutions - related partners';
$nodequeue->subqueue_title = '';
$nodequeue->size = 0;
@brycefisher
brycefisher / find_deep_needle.php
Last active December 25, 2015 00:29
Like var_dump, but it prints out the whole expression "path" to the given string.
<?php
/**
* Like var_dump, but it prints out the whole expression "path" to the given string.
*
* @param mixed $haystack
* The object or array with many levels of nested arrays or objects containing your needle
* @param str $php_exp
* The php expression for the initial $haystack param
* @return str
* No return value. Prints output to stdout (assumed to be a browser).