Skip to content

Instantly share code, notes, and snippets.

View samcre's full-sized avatar
🧱

Samuel Crespo samcre

🧱
View GitHub Profile
@samcre
samcre / mysql_grants_regex.sql
Last active September 27, 2017 10:52
SQL grants with regex
SELECT CONCAT('GRANT SELECT ON test.', TABLE_NAME, ' to ''foouser'';')
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'test'
AND TABLE_NAME LIKE 'foo_%'
@samcre
samcre / nginx.conf
Created September 27, 2017 11:57
nginx: block IPs
map $http_x_forwarded_for $denied {
default allow;
~\s*111.222.333.444$ deny;
~\s*123.456.789.*$ deny;
}
location / {
[...]
if ( $denied = "deny" ) { return 403; }
[...]
@samcre
samcre / extract_table.sh
Created October 9, 2017 08:08
Extract one table from MySQL dump
sed -n -e '/DROP TABLE.*mytable/,/UNLOCK TABLES/p' mydump.sql > tabledump.sql

Keybase proof

I hereby claim:

  • I am samcre on github.
  • I am samcre (https://keybase.io/samcre) on keybase.
  • I have a public key whose fingerprint is E06E 5EF6 F831 3979 B62B 3B88 9AFE 2B31 12AB 02CC

To claim this, I am signing this object:

@samcre
samcre / gist:fdf2d34e430a278fda7d152c50ea7d86
Created February 13, 2018 15:16
Extract data from path
f='/path/to/complex/file.1.0.1.tar.gz'
# Filename : 'file.1.0.x.tar.gz'
echo "$f" | awk -F'/' '{print $NF}'
# Extension (last): 'gz'
echo "$f" | awk -F'[.]' '{print $NF}'
# Extension (all) : '1.0.1.tar.gz'
echo "$f" | awk '{sub(/[^.]*[.]/, "", $0)} 1'
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
@samcre
samcre / gist:506268b99189f6bcbcb569321926549a
Created March 5, 2018 09:49
Print file without line comment
grep -E -v "^\s*(#|$)" ${FILENAME}
@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:549aa7efd60b1c40251d803781730669
Created September 3, 2018 12:50
Unofficial Bash Strict Mode
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
@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}"