Skip to content

Instantly share code, notes, and snippets.

View samcre's full-sized avatar
🧱

Samuel Crespo samcre

🧱
View GitHub Profile
@samcre
samcre / optIMG.sh
Created August 20, 2020 15:41
Optimize images for web
# Optimize PNG files with pngcrush
find . -type f -iname "*.png" -exec pngcrush -ow {} \;
# Optimize JPG & JPEG files with ImageMagick following this recommendations: https://dev.to/feldroy/til-strategies-for-compressing-jpg-files-with-imagemagick-5fn9
find . -type f -iname "*.jpg" -exec convert {} -sampling-factor 4:2:0 -strip -quality 85 -interlace Plane -gaussian-blur 0.05 -colorspace RGB {} \;
find . -type f -iname "*.jpeg" -exec convert {} -sampling-factor 4:2:0 -strip -quality 85 -interlace Plane -gaussian-blur 0.05 -colorspace RGB {} \;
# Optimize SVG images using SVGO
find . -type f -iname "*.svg" -exec svgo -i {} \;
@samcre
samcre / findio.md
Created November 15, 2019 12:54
I/O Redirections inside find

SOURCE

1. Simple way: for loop

If you want to process just the files under A/, then a simple for loop should be enough:

for file in A/*.dat; do ./a.out < "$file" > "${file%.dat}.ans"; done
@samcre
samcre / clean.sh
Created October 28, 2019 14:50
Get all namespaces with tiller deployment, and remove al Pull Request deployed with Helm
#!/usr/bin/env bash
#shellcheck disable=SC2116
TILLER_NS=$( kubectl get pods --all-namespaces --selector name=tiller --output custom-columns=:.metadata.namespace | grep -v ^$ )
export TILLER_NS
for ns in $( echo "$TILLER_NS" )
do
helm ls --tiller-namespace "$ns" \
| cut -f1 \
@samcre
samcre / gist:dfeb5146e7b4f71a9c92fb176f079e2b
Created July 18, 2019 14:49
PostgreSQL dumps without owner and ACLs
# Source: https://serverfault.com/questions/228170/export-and-import-a-postgresql-database-with-a-different-name
pg_dump --no-owner --no-acl blah > blah.psql
psql blah_devel < blah.psql > /dev/null
@samcre
samcre / eks.tf
Last active December 7, 2018 12:48
EKS module
module "eks" {
source = "terraform-aws-modules/eks/aws"
cluster_name = "${var.cluster_name}"
subnets = "${module.vpc.private_subnets}"
vpc_id = "${module.vpc.vpc_id}"
}
@samcre
samcre / vpc.tf
Created December 7, 2018 12:43
VPC Module
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
name = "${var.vpc_name}"
cidr = "${var.vpc_cidr}"
azs = "${var.azs}"
private_subnets = "${var.priv_subnets_cidrs}"
public_subnets = "${var.pub_subnets_cidrs}"
@samcre
samcre / gist:549aa7efd60b1c40251d803781730669
Created September 3, 2018 12:50
Unofficial Bash Strict Mode
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
@samcre
samcre / deploy-rolebinding.yaml
Created August 17, 2018 12:38
Deploys Role for Kubernetes
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: deployer-binding
namespace: ${NAMESPACE}
subjects:
- kind: Group
name: deploys
namespace: ${NAMESPACE}
@samcre
samcre / gist:506268b99189f6bcbcb569321926549a
Created March 5, 2018 09:49
Print file without line comment
grep -E -v "^\s*(#|$)" ${FILENAME}
git branch -m old_branch new_branch # Rename branch locally
git push origin :old_branch # Delete the old branch
git branch --unset-upstream new_branch # Unset the tracking info, so it doesn't push with the old name
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote