Skip to content

Instantly share code, notes, and snippets.

@adamjarret
adamjarret / grep-a-not-b.sh
Last active March 23, 2024 02:44
grep for files that contain "string-a" but not "string-b"
# Thanks https://unix.stackexchange.com/a/128436
grep -le "string-a" * --null | xargs -0 -n 1 -I {} grep -Le "string-b" "{}"
# Simplified version can be used if file paths have no spaces:
grep -Le "string-b" $(grep -le "string-a" *)
@adamjarret
adamjarret / yqblank
Created March 22, 2024 20:14
Update yaml file preserving empty lines
# Usage:
#
# yqblank '. | .some-prop = false' file.yml
#
# Thanks https://github.com/mikefarah/yq/issues/515#issuecomment-1113957629
yq "$1" "$2" | diff -B "$2" - | patch "$2" -
@adamjarret
adamjarret / getJSON.js
Last active January 31, 2022 04:58
Node.js: Fetch and parse JSON content from a URL (no dependencies)
const { get } = require('https');
function getJSON(url, options) {
return new Promise((resolve, reject) => {
get(url, options, (res) => {
let body = '';
res.setEncoding('utf8');
res.on('data', (data) => {
body += data;
});
@adamjarret
adamjarret / c9ssh.sh
Last active April 11, 2018 12:45
Get ssh command for connecting to AWS Cloud9 EC2 Environment (forward port 8080)
#!/bin/bash
WAN=$(curl -s https://api.ipify.org)
LAN=$(ip addr show eth0 | grep "inet\b" | awk '{print $2}' | cut -d/ -f1)
echo "ssh ec2-user@$WAN -L 8080:$LAN:8080"
@adamjarret
adamjarret / LogShipToCloudWatch.js
Created October 13, 2017 00:34
AWS Lambda for shipping logs from S3 to CloudWatch
const aws = require('aws-sdk');
const s3 = new aws.S3({apiVersion: '2006-03-01'});
const cw = new aws.CloudWatchLogs({apiVersion: '2015-01-28'});
const AlreadyExists = 'ResourceAlreadyExistsException';
const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
// Thanks https://github.com/caolan/async/blob/master/lib/waterfall.js
function cascade(tasks, callback, ignoreError)

Keybase proof

I hereby claim:

  • I am adamjarret on github.
  • I am atj (https://keybase.io/atj) on keybase.
  • I have a public key ASD05HPxI3ZcvsRS52voRRB4HaIcVOzCw2yKVxRbISlQ2wo

To claim this, I am signing this object: