Skip to content

Instantly share code, notes, and snippets.

Avatar

Jesse Cotton JCotton1123

View GitHub Profile
@JCotton1123
JCotton1123 / Jenkinsfile
Last active Oct 5, 2021
Sample Jenkinsfile for Python project
View Jenkinsfile
pipeline {
options {
buildDiscarder(logRotator(numToKeepStr: '10')) // Retain history on the last 10 builds
ansiColor('xterm') // Enable colors in terminal
timestamps() // Append timestamps to each line
timeout(time: 20, unit: 'MINUTES') // Set a timeout on the total execution time of the job
}
agent {
// Run this job within a Docker container built using Dockerfile.build
// contained within your projects repository. This image should include
@JCotton1123
JCotton1123 / fetchenv.sh
Created Jun 9, 2016
Export env variables for each AWS CloudFormation stack output
View fetchenv.sh
#!/bin/bash
# This script will find all AWS CloudFormation stacks matching the supplied filter
# and export the outputs into environment variables.
#
# This script is assumed to be run on a host with an IAM profile matching the following:
#
# {
# "Version": "2012-10-17",
# "Statement": [
@JCotton1123
JCotton1123 / parse-slow-log.sh
Last active Oct 30, 2020
Parse php-fpm slow log
View parse-slow-log.sh
## Slow requests grouped by function call
cat /var/log/php-fpm/www-slow.log | grep -A 1 script_filename | \
grep -v script_filename | grep -v -e "--" | cut -c 22- | sort | uniq -c | sort -nr
## Slow requests grouped by minute
cat /var/log/php-fpm/www-slow.log | grep 'pool www' | \
cut -d' ' -f2 | sort | cut -d: -f1,2 | uniq -c
## Top 25 1 minute groups of slow requests
cat /var/log/php-fpm/www-slow.log | grep 'pool www' | cut -d' ' -f2 | \
@JCotton1123
JCotton1123 / export.sh
Last active Sep 14, 2020
AWS Export IP Addresses
View export.sh
# Export IP addresses to support vulnerability scanning
# Public IPs
touch /tmp/public-ips.txt
aws ec2 describe-instances \
--query "Reservations[*].Instances[*].PublicIpAddress" \
--output=text \
>>/tmp/public-ips.txt
@JCotton1123
JCotton1123 / stocktwits-message-scraper.js
Created Aug 16, 2020
Stocktwits Message Scraper using Headless Browser
View stocktwits-message-scraper.js
const puppeteer = require('puppeteer');
const debug = process.env.DEBUG == 'true';
const url = 'https://stocktwits.com/mrinvestorpro';
const main = async () => {
const browser = await puppeteer.launch({ headless: !debug });
try {
console.log('Launching page');
@JCotton1123
JCotton1123 / export-puppet-classification-data.rb
Created Jun 14, 2020
Puppet Enterprise Node Group (Classification) data export
View export-puppet-classification-data.rb
#!/usr/bin/env ruby
# Export node group data from Puppet Enterprise
# Setup:
# export PATH=$PATH:/opt/puppetlabs/puppet/bin
# gem install --user-install puppetclassify
# puppet-access login --lifetime 8h
require 'csv'
@JCotton1123
JCotton1123 / foreman-uninstall.sh
Last active Jun 10, 2020
Uninstall Foreman RHEL
View foreman-uninstall.sh
#!/bin/sh
service xinetd stop
service foreman-proxy stop
service httpd stop
killall -9 sidekiq
service puppet stop
service puppetserver stop
service postgresql stop
service rh-redis5-redis stop
@JCotton1123
JCotton1123 / main.go
Created Mar 4, 2020
CloudTrail Log Decompression Lambda
View main.go
package main
import (
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
"github.com/aws/aws-sdk-go/service/s3/s3manager"
"github.com/pkg/errors"
@JCotton1123
JCotton1123 / server.sh
Created Feb 28, 2020
Netcat HTTP Server
View server.sh
cat >index.http <<EOF
HTTP/1.1 200 OK
Content-Type: text/html; charset=UTF-8
Server: netcat!
<!doctype html>
<html><body><h1>A webpage served by netcat</h1></body></html>
EOF
while true; do cat index.http | nc -l 8000; done
@JCotton1123
JCotton1123 / s3-restore.sh
Created Apr 30, 2019
Restore files from latest version in s3
View s3-restore.sh
#!/bin/bash
if [ -z "$1" ]; then
echo "An input file is required"
echo "usage: $0 <input-file>"
exit 1
fi
files=$(cat $1)
for f in $files; do