Skip to content

Instantly share code, notes, and snippets.

View ghidinelli's full-sized avatar

Brian ghidinelli

View GitHub Profile
@ghidinelli
ghidinelli / docker-entrypoint-oncontainerend.bash
Last active April 19, 2023 23:41
Docker entrypoint wrapper runs shutdown tasks before a container exits
#!/bin/bash
# exit if any pipeline exits non-zero
set -e
# capture stdout and stderr
exec 2>&1
if [[ "$CONTAINER_SHUTDOWN_CLEANUP_ENABLE" = true || "$CONTAINER_SHUTDOWN_CLEANUP_ENABLE" = 1 ]]; then
echo "Feature: Enabling shutdown cleanup against ${CONTAINER_SHUTDOWN_CLEANUP_URL:=http://localhost:3000/your/route/to/check/ok_to_shutdown}"
# send a waiver to a mobile phone for signing
curl -X POST https://speedwaiver.com/api/v1/waiver_invitations -H 'Content-Type: application/json' \
-H 'X-Tenant-ID: ...' \
-H 'x-api-key: ...' \
-d '[{"family_name": "Alonso", \
"given_name": "Fernando", \
"waiver_template_group_id": "...", \
"event_id": "...", \
"send_notification_via": "sms". \
"sms_number": "+1-415-555-1212", \
@ghidinelli
ghidinelli / gist:6221e0b126f934fdcd1b3b54074691da
Created June 10, 2018 23:33
Open Chrome on Mac OSX to Google Flights with criteria pre-filled for batch searching
#!/bin/bash
[ "$#" -eq 1 ] || (echo "Destination airport code(s) (e.g. 'RNO' or 'RNO DEN') argument required" && exit 1)
for destination in "$@"
do
for origin in SFO AVL,GSP AUS MKE MEM DEN ONT IAD
do
if [ "$destination" = "$origin" ]; then
echo "No flight required for $origin -> $destination"
@ghidinelli
ghidinelli / oauth_node_example.js
Created July 29, 2017 20:53 — forked from jonmaim/oauth_node_example.js
OAuth 1.0 3-legged server side flow (motorsportreg example)
'use strict';
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
var localtunnel = require('localtunnel');
var request = require('request');
var qs = require('querystring');
var url = require('url');
var http = require('http');
@ghidinelli
ghidinelli / rank-kalzumeus-microconf-tweets.txt
Last active April 12, 2016 18:48
Ranking @patio11's tweets at #microconf
# fetch @patio11's tweets from microconf (roughly apr 3 on)
# signature generated from https://dev.twitter.com/rest/reference/get/statuses/user_timeline
curl --get 'https://api.twitter.com/1.1/statuses/user_timeline.json' --data 'count=200&screen_name=patio11&since_id=717036680947965953' --header 'Authorization: OAuth oauth_consumer_key="x6nmC5cEByCeyudJjVKsMA", oauth_nonce="56b83cf5f068e31996fc484364e99423", oauth_signature="0vY6VEDKTI2Bb8J09osG0yqTA6M%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1460264255", oauth_token="49019793-1cje0xH21w4OsEudjSXTIj1hDQhorGifIrfuBQ0Eb", oauth_version="1.0"' --verbose > tweets.json
# import into postgres
psql -d test -c "CREATE TABLE pgtweets (data json)"
psql -d test -c "COPY pgtweets FROM '$(pwd)/tweets.json'"
# total activity over these 200 tweets
@ghidinelli
ghidinelli / gist:e01b83b6a2e628c17cd5
Created September 13, 2015 23:20
getRemoteAddress() for ColdFusion with or without common load balancers/firewalls
<cffunction name="getRemoteAddress" output="false" access="public" returntype="string" hint="Identify the remote user IP address">
<cfset var pc = getHTTPRequestData().headers />
<cfset var arrIP = "" />
<cfif structKeyExists(pc, "X-Forwarded-For") AND len(pc["X-Forwarded-For"])>
<!--- the x-forwarded-for header sometimes includes values that are too long like "172.27.156.64, 67.98.222.16". The regexp picks out just the matches. http://support.f5.com/kb/en-us/solutions/public/12000/200/sol12264.html --->
<cfset arrIP = reMatch('\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b', pc["X-Forwarded-For"]) />
<cfif arrayLen(arrIP)>
<cfreturn arrIP[1] />
<cfelse>
@ghidinelli
ghidinelli / gist:2e7fb5962f39b7cc6508
Created September 13, 2015 23:19
getIsSecure() for ColdFusion with or without common load balancers/firewalls
<cffunction name="getIsSecure" output="false" access="public" returntype="any" hint="Determine if the request is encrypted via HTTPS directly or via BIG/IP">
<cfreturn (structKeyExists(CGI, "server_port_secure") AND isBoolean(CGI.server_port_secure) AND CGI.server_port_secure EQ true)
OR (structKeyExists(CGI, "bigipssl") AND isBoolean(CGI.bigipssl) AND CGI.bigipssl EQ true)
OR (structKeyExists(getHTTPRequestData().headers, "X-Forwarded-Proto") AND getHTTPRequestData().headers["X-Forwarded-Proto"] EQ "https") />
</cffunction>
@ghidinelli
ghidinelli / gulpfile.js
Last active October 4, 2018 11:41
Creating rev-manifest file after gulp-rev runs in parallel
// I have a bunch of style/script tasks running in parallel which
// were overwriting or garbling my rev-manifest.json file when using
// gulp-rev directly. It works great if you only have one task
// but falls down when you have tasks running simultaneously as they
// overwrite each other's changes in the manifest. My approach runs
// all of the processing in parallel but generates the manifest as a
// second step in the 'build' task using the run-sequence plugin.
// Include gulp
var gulp = require('gulp');
@ghidinelli
ghidinelli / web.xml
Created September 1, 2015 17:25
Adobe ColdFusion 10 locked down web.xml - disables flash remoting, etc.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app id="adobe_coldfusion">
<display-name>Adobe ColdFusion 10</display-name>
<description>Adobe ColdFusion 10</description>
<context-param id="coldfusion_context_1">
<param-name>cftags</param-name>
<param-value>/WEB-INF/cftags</param-value>
<description>Path to search for built-in tags. Relative to application root.
This parameter can only be one path element.</description>
@ghidinelli
ghidinelli / jstatall.sh
Created August 20, 2015 17:50
jstatall.sh - shell script for displaying jstat metrics of two JREs side by side in the console
#!/bin/bash
# bug in JDK > 1.7 u75 where root can't see non-root JVMs, so specify the username of the process owner (lazy approach)
USER=nobody
# Tweak the grep for whatever JVM-based applications you're looking to monitor
INST1=`/bin/ps -ef |/bin/grep "INSTANCE1/bin/cf-bootstrap.jar" | /bin/grep -v grep | /usr/bin/awk -F" " '{print $2}'|/usr/bin/head -1`
INST2=`/bin/ps -ef |/bin/grep "INSTANCE2/bin/cf-bootstrap.jar" | /bin/grep -v grep | /usr/bin/awk -F" " '{print $2}'|/usr/bin/tail -1`
# catch ctrl-c and clean up jstat