Skip to content

Instantly share code, notes, and snippets.

View TopherGopher's full-sized avatar

Topher Sterling TopherGopher

View GitHub Profile
@TopherGopher
TopherGopher / python_logging.py
Created October 24, 2017 14:45
Logging in Python
class CustomJsonFormatter(jsonlogger.JsonFormatter):
"""
Class that helps redefine the log message format
"""
def add_fields(self, log_record, record, message_dict):
super(CustomJsonFormatter, self).add_fields(log_record, record, message_dict)
if not log_record.get('timestamp'):
# this doesn't use record.created, so it is slightly off
now = datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%S.%fZ')
log_record['timestamp'] = now
@TopherGopher
TopherGopher / osx_voice_sampler.sh
Created November 26, 2016 23:43
Runs through the available voices in OSX and says a sample phrase in each
for X in $(say -v ? | cut -d' ' -f1); do echo $X && say -v "$X" "Welcome Professor"; done
@TopherGopher
TopherGopher / databag_main.yml
Created August 3, 2016 21:13
Loading databags in using ansible
- name: Get the databag data for this site/env
local_action: command knife data bag show nmdhosting {{ item.path | basename }} -F yaml
register: bag
when: current_directory.stat.exists is defined and current_directory.stat.exists
- name: Get that data into a YAML file
local_action: copy content="{{ bag.stdout }}" dest="/tmp/{{ item.path | basename }}_generated.yml"
when: current_directory.stat.exists is defined and current_directory.stat.exists
- name: Get those vars
<?php
// YOUR LOGIN INFO HERE:
$email = '';
$password = '';
// RUNNING IT FOR A PANTHEON ONE "ORGANIZATION": UNCOMMENT AND ADD YOUR UUID HERE
// $organiztion_uuid = 'some-org-uuid-here';
// helper function
function terminus_json($command) {
/**
* Sets an iFrame ID to no_name_iframe if there is no ID. You can then add a Switch to iFrame step after it using the na_name_iframe ID.
*
* @Given /^I the set the iframe located in element with an id of "([^"]*)"$/
*/
public function iSetTheIframeLocatedInElementWithAnIdOf($element_id) {
$element = $this->getMainContext()->getSession()->getPage()->findById($element_id);
if ($element == NULL) {
throw new \Exception(sprintf("Element with ID '%s' not found", $element_id));
@TopherGopher
TopherGopher / unsubmodulify_in_git
Created January 7, 2014 16:52
Ever had a submodule that you wanted to keep the full history of, but you no longer wanted it is a submodule? You want it as part of the main project. This set of commands allows you to do just that - pulling the submodule's history and incorporating it into the main project.
#!/bin/bash
# Just in case something goes wrong, let's do this un-submodulifying on a new branch.
git checkout new_branch
# You need to go in and remove the SUBMODULE_DIR project from your .gitmodules file
# Save the URL that the submodule points to.
vim .gitmodules
# We're going to completely wipe out the SUBMODULE_DIR from your project...trust me...
@TopherGopher
TopherGopher / update_unversioned_drupal_modules.php
Created January 7, 2014 16:39
When you use git to keep modules up to date in Drupal, the .info file does not get wrapped with the correct versioning information since all of the versioning you could ever want is in the .git blobs. If you want to take the module out of git and allow Drupal to natively handle the module updates from now on, the easiest method is just to downlo…
<?php
// What is the drush command you wish to run?
// Some people just might use `php /usr/bin/drush/drush.php`, but I wanted to specify further options explicitely.
$drush='/Applications/MAMP/bin/php/php5.4.4/bin/php -d memory_limit=128M /drush/drush.php --php="/Applications/MAMP/bin/php/php5.4.4/bin -d memory_limit=128M"';
// Where is the module directory you are trying to update?
$folders = scandir('/data/releases/homepage/dev/profiles/cu_homepage/modules/contrib');
// Get rid of . and ..
unset($folders[0]);
@TopherGopher
TopherGopher / get_from_rss_feed.pl
Created January 4, 2014 01:59
This script goes into the rss files specified and downloads the end file specified. I used this to help me grab the keynotes from the DEFCON conferences because the videos took forever to buffer online. Grab the RSS files for the podcasts in order to get the video URLs.
#!/usr/bin/perl -w
use strict;
use LWP::Simple;
use XML::RSS;
my @files = qw(defcon-10-video.rss
defcon-11-video.rss
defcon-12-video.rss
defcon-13-video.rss
@TopherGopher
TopherGopher / git_config
Created January 4, 2014 01:50
Just sets the configuration options you need for git on a new machine with a BASH wrapper.
#!/bin/bash
#Change these to tailor git to you
USER_NAME="Chris Sterling"
USER_EMAIL="sterlincexc@colorado.edu"
LOG_MESSAGES_EDITOR="vim"
DIFF_PROGRAM="meld"
echo "Configure GIT"
echo ""
echo "What user name would you like to use? ex) John Doe"
@TopherGopher
TopherGopher / convert_svn_to_git
Created January 4, 2014 01:10
This helps create a new git repo from an existing svn repo. It uses git-svn to create a hybrid of your svn repo, then it creates a clean repo at REPONAME. It should maintain your history for your branch. I've setup the framework so that you can add more branches, but I never implemented the logic because we didn't need it. It should be extensibl…
#!/bin/bash
#What is the name of your repo? This will serve as the folder name.
REPO_NAME="my-repo"
# Do NOT point to the trunk
URL_OF_REPO="https://myserver.example.com/svn/roommate-agreement"
# This is probably just "trunk"
TRUNK_LOCATION="trunk"
BRANCH_LOCATION="branches"