Skip to content

Instantly share code, notes, and snippets.

View cablespaghetti's full-sized avatar

Sam Weston cablespaghetti

View GitHub Profile
package com.pulselive.cms.api.common.session;
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
@cablespaghetti
cablespaghetti / resize.sh
Created June 5, 2020 14:41
Resize and recompress pngs
#!/bin/bash
for image in *.png
do
width=$(identify -format '%w' $image)
height=$(identify -format '%h' $image)
cp $image $image.original
if [ $width -gt 350 ]
then
echo "$image - width: $width height: $height"
# Resize to 350px width keeping aspect ratio
@cablespaghetti
cablespaghetti / s3-content-type-fix.sh
Last active October 6, 2023 06:52
Find all files in S3 bucket with specific content-type
aws s3 ls s3://mybucket/ --recursive | awk '{print $4}' | parallel 'echo {}; if [ "$(aws s3api head-object --bucket mybucket --output json --key {} | jq .ContentType -r)" = "binary/octet-stream" ]; then echo {} >> dodgy.txt; fi'
cat dodgy.txt | grep png | parallel 'echo {}; aws s3 cp --content-type="image/png" --metadata-directive="REPLACE" s3://mybucket/{} s3://mybucket/{}'
@cablespaghetti
cablespaghetti / gist:54de0ae93449e4698f0206a0e85514be
Last active November 2, 2022 14:20
Example terraform for ASG with spot instances
#
# Configuration for Autoscaling group.
#
resource "aws_launch_template" "eks-cluster-worker-nodes" {
iam_instance_profile = { name = "${aws_iam_instance_profile.eks-cluster-worker-nodes.name}" }
image_id = "${data.aws_ami.eks-worker.id}"
name = "${var.cluster-name}-eks-cluster-worker-nodes"
vpc_security_group_ids = ["${aws_security_group.eks-cluster-worker-nodes.id}"]
key_name = "${var.ssh-key-name}"
instance_type = "${local.host-types[0]}"
@cablespaghetti
cablespaghetti / thrift.sh
Created July 26, 2018 11:00
Installing thrift 0.9.1 on Fedora 28
#!/bin/bash -ex
dnf install -y thrift-devel libtool m4 automake byacc flex
mkdir thriftbuild
cd thriftbuild
wget https://github.com/apache/thrift/archive/0.9.1.tar.gz
tar xvf 0.9.1.tar.gz thrift-0.9.1/
cd thrift-0.9.1/
curl http://cdn-fastly.deb.debian.org/debian/pool/main/t/thrift-compiler/thrift-compiler_0.9.1-2.1.debian.tar.xz -o thrift-debian-patches.tar.xz
tar xvf thrift-debian-patches.tar.xz
cd compiler/
@cablespaghetti
cablespaghetti / ecr-cred-updater.sh
Last active November 18, 2023 09:16
Automatic Updating Amazon ECR Credentials in Kubernetes
#!/bin/bash
# Get directory of script
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
if [[ $# -ne 1 ]]
then
echo "ERROR: This script expects the namespace name to be given as an argument"
echo "e.g. ./ecr-cred-updater.sh my-namespace"
exit 1
@cablespaghetti
cablespaghetti / gist:28be487f20dda0d53f49f709fae28d69
Created June 11, 2018 12:15
Cheapest Instances for CPU in eu-west-1
Processing Instance Type List from https://www.ec2instances.info/
Getting Current Spot Prices from AWS
Processing AZ eu-west-1a
You will pay $0.0047 per core for m1.small. It has 1 cores and 1.7GB RAM. Spot price is $0.0047 per hour or $3.384 per month.
You will pay $0.0073 per core for m3.medium. It has 1 cores and 3.75GB RAM. Spot price is $0.0073 per hour or $5.256 per month.
You will pay $0.0074 per core for c1.medium. It has 2 cores and 1.7GB RAM. Spot price is $0.0148 per hour or $10.656 per month.
You will pay $0.0085 per core for c1.xlarge. It has 8 cores and 7.0GB RAM. Spot price is $0.0678 per hour or $48.816 per month.
You will pay $0.0095 per core for m1.xlarge. It has 4 cores and 15.0GB RAM. Spot price is $0.0379 per hour or $27.288 per month.
You will pay $0.0095 per core for m1.medium. It has 1 cores and 3.75GB RAM. Spot price is $0.0095 per hour or $6.84 per month.