Skip to content

Instantly share code, notes, and snippets.

@EricLondon
EricLondon / 1_usage.sh
Created September 12, 2018 18:33
Ruby stream command output
./parent.rb
command: ./child.rb 1
2018-09-12 14:32:09: stdout
2018-09-12 14:32:09: stderr
2018-09-12 14:32:11: stdout
2018-09-12 14:32:11: stderr
pid 97509 exit 1
97509
false
command: ./child.rb 0
@EricLondon
EricLondon / s3_sns_lambda.js
Last active September 19, 2018 12:39
AWS Lambda S3 Notification to SNS with S3 MetaData
'use strict';
// ENV vars
const AWS_REGION_STRING = process.env.AWS_REGION || 'us-east-1';
const AWS_ACCOUNT_ID = process.env.AWS_ACCOUNT_ID;
const SNS_TOPIC_NAME = process.env.SNS_TOPIC_NAME;
const SNS_TOPIC_ARN = `arn:aws:sns:${AWS_REGION_STRING}:${AWS_ACCOUNT_ID}:${SNS_TOPIC_NAME}`;
const AWS = require('aws-sdk');
AWS.config.update({
@EricLondon
EricLondon / pipe-count.sh
Last active September 21, 2018 13:52
Shell script to append missing character to end of line based on count of occurrence
#!/usr/bin/env bash
INPUT_FILE=some-input-file.txt
OUTPUT_FILE=output.txt
while read p; do
pipecount=$(echo $p | awk -F"|" '{print NF}')
if [ $pipecount == 45 ]; then
echo "$p|" >> $OUTPUT_FILE
else
@EricLondon
EricLondon / .terraform-version
Created October 18, 2018 10:34
Terraform S3 backend
0.11.8
@EricLondon
EricLondon / .nvmrc
Last active October 23, 2018 16:21
Lamba, NodeJS, API Gateway, Terraform
8.10.0
@EricLondon
EricLondon / .ruby-gemset
Created November 9, 2018 13:41
Ruby populate person objects in S3
person-data
@EricLondon
EricLondon / launch.json
Created December 19, 2018 14:33
VSCode debug nodejs with NVM launch config
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/test.js",
"runtimeExecutable": "${workspaceRoot}/node.sh"
}
@EricLondon
EricLondon / color.rb
Created February 13, 2019 17:31
Rails other/remaining scopes
# frozen_string_literal: true
class Color < ApplicationRecord
scope :red, -> { where(color: 'red') }
scope :yellow, -> { where(color: 'yellow') }
scope :blue, -> { where(color: 'blue') }
scope :non_primary, -> { where.not(id: red).where.not(id: yellow).where.not(id: blue) }
end
@EricLondon
EricLondon / helpers.rb
Created February 19, 2019 20:25
RSpec helper capture stdout
module Helpers
def with_captured_stdout
original_stdout = $stdout
$stdout = StringIO.new
yield
$stdout.string
ensure
$stdout = original_stdout
end
end
@EricLondon
EricLondon / setenv.sh
Created April 8, 2022 19:23
set environment variable outside script
#!/bin/sh
# Usage:
# . ./setenv.sh
#
# echo $ENV1
# blah1
#
# echo $ENV2
# blah2