Skip to content

Instantly share code, notes, and snippets.

View cmbuckley's full-sized avatar

Chris Buckley cmbuckley

View GitHub Profile
@cmbuckley
cmbuckley / comments.php
Last active May 13, 2018 00:15
Emit WordPress comments as YML
<?php
$file = $argv[1];
$header = null;
$spec = array(
'_id' => function ($data) {
return intval($data['comment_ID']);
},
'name' => 'comment_author',
@cmbuckley
cmbuckley / air-cert-dates.sh
Last active July 27, 2021 12:24
Verify Adobe AIR code signing certificate
#!/bin/bash
# Usage: ./air-cert-dates.sh /path/to/app.air
signatures="$(unzip -p "$1" META-INF/signatures.xml)"
xpath '//Signature[@Id="PackageSignature"]//X509Certificate[1]/text()' <<< "$signatures" 2>/dev/null \
| sed -e $'1s/^/-----BEGIN CERTIFICATE-----\\\n/;$s/$/\\\n-----END CERTIFICATE-----/' \
| openssl x509 -dates -noout \
| sed -e $'1s/^/metric,date\\\n/;s/=/,/'
@cmbuckley
cmbuckley / rounded.sh
Last active September 21, 2018 16:01
ImageMagick rounded corners
#!/bin/bash
# usage: rounded.sh INFILE RADIUS [OUTFILE]
# if OUTFILE is omitted, outputs to STDOUT
size=$2
convert $1 \( +clone -alpha extract -draw "fill black polygon 0,0 0,$size $size,0 fill white circle $size,$size $size,0" \( +clone -flip \) -compose Multiply -composite \( +clone -flop \) -compose Multiply -composite \) -alpha off -compose CopyOpacity -composite ${3:-png:-}
@cmbuckley
cmbuckley / trapper.js
Last active November 21, 2018 12:56
JavaScript Cookie Trapper
// Use to detect calls to document.cookie="xxx"
(function (){
var s = document.__lookupSetter__('cookie').bind(document),
g = document.__lookupGetter__('cookie').bind(document);
Object.defineProperty(document, 'cookie', {
get() {
return g();
},
set(n) {
function nestingLolz(count) {
return [...Array(count)].reduce(function (a, c, i) {
return a + ' or my ' + Array(i + 1).fill('son').join('’s ');
}, 'Don’t talk to me') + ' ever again';
}
// haven't decided which I prefer :-)
function nestingLolzAlternate(count) {
return ['Don’t talk to me']
.concat([...Array(count)].map((e, i) => Array(i + 1).fill('son').join('’s ')))
<?php
$char = 'イ';
// What's the UTF-8 encoding of this character? (This file is saved in UTF-8)
var_dump(bin2hex($char)); // e382a4
// What does another encoding look like?
// See http://www.fileformat.info/info/unicode/char/30a4/charset_support.htm
var_dump(bin2hex(mb_convert_encoding($char, "EUC-JP", "UTF-8"))); // a5a4
@cmbuckley
cmbuckley / outer-glow.sh
Created February 21, 2019 16:59
Add outer glow to images with transparent background
# Add 5px transparent border
convert file.png -bordercolor transparent -border 5 file-border.png
# Add a 3px blur based on the alpha channel
convert file-border.png \( +clone -background '#777777' -shadow 100x1+0+0 -channel A -level 0,100% -blur 0x3 \) -compose DstOver -gravity center -composite file-glow.png
# TODO combine the above
@cmbuckley
cmbuckley / p.sh
Last active September 13, 2021 12:53
Use 1Password to copy a password to the clipboard
#!/bin/bash
check_session() {
[ -f $HOME/.op/token ] && export OP_SESSION_my="$(cat $HOME/.op/token)"
# attempt sign in if session is not active
if ! op get account &> /dev/null; then
signin
check_session
fi
}
@cmbuckley
cmbuckley / fd.sh
Last active June 12, 2019 12:30
Firedrill script
#!/bin/bash
webhook_url="URL HERE"
role=Firedrill
icon=bust_in_silhouette
channel="#lotto-support-3p"
roles=(
"marketing,Marketing:female-technologist::skin-tone-2"
"crm,CRM:male-singer::skin-tone-3"
"core,Core on-call:bearded_person::skin-tone-2"

This is just an example for https://stackoverflow.com/q/58283005/283078.

The following commands were run to create this history:

git checkout -b dev
git commit --allow-empty -m 'Dev commit 1'
git commit --allow-empty -m 'Dev commit 2'
git commit --allow-empty -m 'Dev commit 3'
git checkout master