Skip to content

Instantly share code, notes, and snippets.

View hatzopoulos's full-sized avatar

Anthony Hatzopoulos hatzopoulos

View GitHub Profile
@hatzopoulos
hatzopoulos / image-optimization-tools.md
Last active April 23, 2023 03:47
WPO : Image Performance Optimization
@hatzopoulos
hatzopoulos / linux-bash-and-git-tricks.md
Last active August 29, 2015 14:24
linux bash and git tricks
# find and group by extension
# http://serverfault.com/a/183432/128858
find ./ -type f -not -path "./.git/*" | grep -E ".*\.[a-zA-Z0-9]*$" | sed -e 's/.*\(\.[a-zA-Z0-9]*\)$/\1/' | sort | uniq -c | sort -n
      1 .GIF
      1 .JPG
 1 .bash
# Safer pushes. Other values: nothing, matching, upstream, simple
git config --local push.default current
# colorize output (Git 1.5.5 or later)
git config --local color.ui auto
# and from 1.5.4 onwards, this will works:
git config --local color.interactive auto
# better colors for spotting whitespace
@hatzopoulos
hatzopoulos / talks.md
Last active August 29, 2015 14:17
Talks by Anthony Hatzopoulos #wpo
@hatzopoulos
hatzopoulos / wtf-find.bash
Last active August 29, 2015 14:17
recursively fix whitespace using https://github.com/hatzopoulos/wtf
# download wtf somewhere in your path and make it executable
curl https://raw.githubusercontent.com/hatzopoulos/wtf/entropy/wtf.py > ~/bin/wtf.py && chmod 0755 !#:3
# declare a function similar to
wtf-find() {
find "${@: -1}" -not \( -name .svn -prune -o -name .git -prune \
-o -name .hg -prune \) -type f -exec bash -c \
'grep -Il "" "$1" &>/dev/null && wtf.py '"${*:1:$#-1}"' "$1"' _ {} \;
}
@hatzopoulos
hatzopoulos / preg_replace-for-lazy-load.php
Last active August 29, 2015 14:16
preg_replace for lazy-load
<?php
$content = '<img data-should-not-get-stripped src="https://example.com/example.jpg" alt="Not a real image." width="630" height="420">';
echo $content.PHP_EOL.str_repeat('-', 40).PHP_EOL;
$content = preg_replace(
"/<img(?! (data-src|data-img-src|data-orig))([^']*?) src=\"([^']*?)\"([^']*?)>/",
'<img$2$1 data-img-src="$3" src="/r/1.2.3/t.gif'.'"$4>',
$content
);
@hatzopoulos
hatzopoulos / curl.bash
Created February 4, 2015 23:58
curl performance tricks
## All Stats
curl -o /dev/null -s -w "\n\
url_effective: %{url_effective}\n\
http_code: %{http_code}\n\
http_connect: %{http_connect}\n\
time_namelookup: %{time_namelookup}\n\
time_connect: %{time_connect}\n\
time_appconnect: %{time_appconnect}\n\
time_pretransfer: %{time_pretransfer}\n\
time_redirect: %{time_redirect}\n\
@hatzopoulos
hatzopoulos / 503.php
Last active October 29, 2021 00:39
PHP Example, 503 Header + Retry After
<?php
ob_start();
// 503 Header
header('HTTP/1.1 503 Service Temporarily Unavailable', true, 503);
// Retry-After header. Two examples of its use are:
// 1. Retry-After: 120
header('Retry-After: '.(1 * 60 * 60));
// 2. Retry-After: Fri, 31 Dec 1999 23:59:59 GMT