Skip to content

Instantly share code, notes, and snippets.

View petrabarus's full-sized avatar

Petra Barus petrabarus

View GitHub Profile
@petrabarus
petrabarus / git-squash.sh
Created October 24, 2024 02:52
Git Squash
#!/usr/bin/env bash
# This will receive arguments of number of commits to squash
# and use the earliest commit message as the new commit message
# Function to show usage
show_usage() {
echo "Usage: ./git-squash.sh <number_of_commits>"
echo "Example: ./git-squash.sh 3"
exit 1
}
@petrabarus
petrabarus / script.sh
Last active August 30, 2023 04:02
Find all files in a directory, flatten, and rename to UUID
#!/usr/bin/env bash
# This script will find all files in the current directory and rename them using UUID and flatten the directory structure.
# This script is useful when you have a directory structure like this:
# src/dir1/dir2/dir3/file1.txt
# src/dir1/dir2/dir4/file2.txt
# src/dir1/dir2/file3.txt
#
# And you want to flatten it to this:
@petrabarus
petrabarus / invalidate_cloudfront_and_wait.sh
Last active April 18, 2022 04:31
Invalidate CloudFront Distribution and Wait
#!/usr/bin/env bash
# Requirements
# - AWS
# - jq
# Variables
PROFILE=
DISTRIBUTION_ID=
PATHS="/*"
@petrabarus
petrabarus / 1passwordtoenv.sh
Last active December 2, 2021 06:56
1Password to Environment Variables
#!/usr/bin/env bash
# Load environment variables from 1password
# To execute this script, execute the command below.
# source 1passwordtoenv.sh 'Name of the item'
ITEM_NAME=$1
# Signin
eval $(op signin)
# Load environment variables
@petrabarus
petrabarus / aws-batch-empty-delete.bash
Last active May 4, 2021 02:30
Batch Empty and Delete S3 Bucket with Grep Pattern
#!/usr/bin/env bash
# Sometimes we create a lot of S3 Bucket with similar names.
# The command below will find all buckets in the region with pattern `bucket_pattern`,
# then empty the bucket and then delete the bucket.
BUCKET_PATTERN=bucket_pattern
aws s3api list-buckets |\
jq -r '.Buckets[].Name' |\
grep $BUCKET_PATTERN |\
xargs -n 1 -I {} sh -c 'aws s3 rm s3://{} --recursive && aws s3 rb s3://{}'
#!/bin/bash
# Resize disk for AWS Cloud9
# https://docs.aws.amazon.com/cloud9/latest/user-guide/move-environment.html#move-environment-resize
# Specify the desired volume size in GiB as a command line argument. If not specified, default to 20 GiB.
SIZE=${1:-20}
# Get the ID of the environment host Amazon EC2 instance.
INSTANCEID=$(curl http://169.254.169.254/latest/meta-data/instance-id)
@petrabarus
petrabarus / Dockerfile
Last active November 5, 2021 13:21
Part 3 Using DynamoDB for Session Management in PHP/Yii2 Application
version: '3'
services:
php:
build: .
volumes:
- ~/.composer-docker/cache:/root/.composer/cache:delegated
- ./:/app:delegated
ports:
- '8080:80'
environment:
Resources:
ecsCluster15812518:
Type: AWS::ECS::Cluster
Metadata:
aws:cdk:path: WebStack/ecsCluster/Resource
ecsClusterVpcFF32B42F:
Type: AWS::EC2::VPC
Properties:
CidrBlock: 10.0.0.0/16
EnableDnsHostnames: true
#!/usr/bin/env node
import 'source-map-support/register';
import cdk = require('@aws-cdk/core');
import ecs = require("@aws-cdk/aws-ecs");
import ecsPatterns = require("@aws-cdk/aws-ecs-patterns");
export class WebStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
this.createECSCluster();
@petrabarus
petrabarus / modern-yii1-app_part-1.patch
Last active December 22, 2019 15:26
Modern Yii2 Application - Part 1 Patch
diff --git a/.dockerignore b/.dockerignore
new file mode 100644
index 0000000..b2ef806
--- /dev/null
+++ b/.dockerignore
@@ -0,0 +1 @@
+cdk.out
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
index 5bd9be8..8600814 100644