Skip to content

Instantly share code, notes, and snippets.

Kurt Roberts kurtroberts

Block or report user

Report or block kurtroberts

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@kurtroberts
kurtroberts / session.sh
Created Dec 19, 2018
Silly Perl Tricks
View session.sh
# remove a string from all lines in a file
cat thing-groups.csv | perl -ne 's/,SmartGroup//g; print $_' -
# just the ones with that smartgroup, but remove it
cat thing-groups.csv | perl -ne 'while(/(.*),SmartGroup(.*)/g){ print "$1$2\n" };' -
# just the ones with that smartgroup, but make it the last one
cat thing-groups.csv | perl -ne 'while(/(.*)(,SmartGroup)(.*)/g){ print "$1$3$2\n" };' -
@kurtroberts
kurtroberts / session.sh
Last active Oct 31, 2018
Script Alerting Options
View session.sh
#/bin/bash
# Built in:
osascript <<EOF 2>/dev/null
display notification "test message" with title "title"
EOF
# yo- https://github.com/sheagcraig/yo
yo_scheduler -t "Title" -n "test message"
@kurtroberts
kurtroberts / logging-docker-to-cloudwatch.md
Created Sep 21, 2018
Using awslogs driver for docker with docker-machine
View logging-docker-to-cloudwatch.md

Make a docker-machine with AWS Credentials

Obviously, you'll need to make credentials first.

$ docker-machine create -d virtualbox \
    --engine-env AWS_REGION=us-east-1 \
    --engine-env AWS_ACCESS_KEY_ID=xxxxxxxxxxxxxxxx \
    --engine-env AWS_SECRET_ACCESS_KEY=xxxxxxxxxxxxxxxxxxxxxx \
    awslogs
@kurtroberts
kurtroberts / demos.sh
Created Sep 5, 2018
Strategies for parsing JSON on the Mac without installing anything
View demos.sh
# using OSAScript's JavaScript support
osascript -l JavaScript -e "console.log(($(cat /Users/$(whoami)/Library/Application\ Support/Google/Chrome/Local\ State)).profile.info_cache.Default.user_name)"
# using python
cat /Users/$(whoami)/Library/Application\ Support/Google/Chrome/Local\ State | python -c 'import json,sys;obj=json.load(sys.stdin);print obj["profile"]["info_cache"]["Default"]["user_name"];'
View list-command-pattern.sh
#!/bin/bash
tasklist="Task1 Task2"
Task1 () {
echo "task 1"
}
Task2 () {
echo "task 2"
@kurtroberts
kurtroberts / Bottleneck.js
Last active Aug 14, 2018
Strategies for meeting API Limits with Promises
View Bottleneck.js
const _ = require('lodash'),
Bottleneck = require('bottleneck'),
limiter = new Bottleneck({
minTime: 333,
maxConcurrent: 1
}),
Promise = require('bluebird'),
promises = [];
_.range(10).forEach(function (x) {
@kurtroberts
kurtroberts / index.js
Created Aug 9, 2018
Handling HTTP/HTTPS redirection in a Lambda function
View index.js
'use strict';
/****
Set up as a lambda function, it doesn't need any special permissions.
To test, you'll use a CloudFrontHTTPRedirect template.
Then, you'll create a CloudFront Distribution and attach this as a behavior.
Use the Event Type "ViewerRequest" to trigger it.
@kurtroberts
kurtroberts / drop-all.sql
Created Aug 4, 2018
Drop all tables in a PSQL schema
View drop-all.sql
-- Liberally borrowed from - https://stackoverflow.com/questions/3327312/drop-all-tables-in-postgresql
-- If you happen to be working on a jira database, you're going to have to do it twice to resolve all the cascades
DO $$ DECLARE
r RECORD;
BEGIN
-- if the schema you operate on is not "current", you will want to
-- replace current_schema() in query with 'schematodeletetablesfrom'
-- *and* update the generate 'DROP...' accordingly.
@kurtroberts
kurtroberts / shell-session.md
Last active Jul 6, 2018
I really, really love `jq`
View shell-session.md

Wow, that's a lot of JSON for my bio...

$ cat data/bio/kurt-roberts.json
{"sys":{"space":{"sys":{"type":"Link","linkType":"Space","id":"----------"}},"id":"------------","type":"Entry","createdAt":"-------","updatedAt":"-------","environment":{"sys":{"id":"master","type":"Link","linkType":"Environment"}},"revision":2,"contentType":{"sys":{"type":"Link","linkType":"ContentType","id":"bio"}},"locale":"en-US"},"fields":{"name":"Kurt Roberts","title":"Chief Creative Technologist?","description":"Senior engineering and design team lead with 15+ years of experience creating solutions for high-profile brands such as Coca-Cola, BlueCross BlueShield America, General Mills and DirecTV, and powerful forces for change such as Facing History and Ourselves, The Washington Area Women's Foundation, Humane Society of the United States and Planned Parenthood.","pastClients":["Coca-Cola","BlueCross BlueShield America","General Mills","DirecTV","Facing History and Ourselves","Humane Society of the United States","Planned P
@kurtroberts
kurtroberts / index.js
Last active Jul 6, 2018
Semicolon insertion
View index.js
var x = 0
/***
While this comment seems like it might be the
beginning of a new statement, you should be careful what
your believe. ;) You should always check */+2/* or *+3* times
what the code is doing and what someone is explaining
in the comments. Sometimes crazy code likes to hide
inside really big comments.
Automatic semicolon insertion is great, until it isn't.
You can’t perform that action at this time.