Skip to content

Instantly share code, notes, and snippets.

View samcre's full-sized avatar
🧱

Samuel Crespo samcre

🧱
View GitHub Profile
@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'

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 / 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
@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 / 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_%'