Skip to content

Instantly share code, notes, and snippets.

@hatzopoulos
hatzopoulos / .vimrc
Last active August 29, 2015 13:58
#vim #vimrc
colorscheme molokai
" Allow cursor keys in insert mode
set esckeys
" Allow backspace in insert mode
set backspace=indent,eol,start
" Use UTF-8 without BOM
set encoding=utf-8 nobomb
" Don't add empty newlines at the end of files
set binary
set noeol
@hatzopoulos
hatzopoulos / ua.js
Last active April 22, 2019 10:23
Optimized Google Universal Analytics
// Optimized Google Universal Analytics
// optional requirement 1:
// if using ga_track_pre_url feature;
// the DOM element must exist before document.getElementById('ga_track_pre_url').value
// like going just before the closing </body> tag
// optimized http://mathiasbynens.be/notes/async-analytics-snippet#universal-analytics
(function(G,o,O,g,l){G.GoogleAnalyticsObject=O;G[O]||(G[O]=function(){(G[O].q=G[O].q||[]).push(arguments)});G[O].l=+new Date;g=o.createElement('script'),l=o.scripts[0];g.src='//www.google-analytics.com/analytics.js';l.parentNode.insertBefore(g,l)}(this,document,'ga'));
@hatzopoulos
hatzopoulos / ip-white-list-cron.php
Created January 21, 2015 02:54
IP White List Update Cron
<?php
## ./ip-white-list-cron.php
$whitelist_json = __DIR__.'/whitelist.json';
$cache_mtime = filemtime($whitelist_json);
$write_error = 'Write Error. This needs to be properly setup to be able to write to '.$whitelist_json.PHP_EOL;
if ( $cache_mtime === false ) {
if ( touch($whitelist_json) === false) {
@hatzopoulos
hatzopoulos / Git.md
Last active August 29, 2015 14:13
Git, GitHub, and Git Workflows
@hatzopoulos
hatzopoulos / command_exists.inc.php
Last active August 29, 2015 14:13
Miscellaneous PHP Functions
<?php
function command_exists($cmd) {
return shell_exec('command -v '.$cmd.' >/dev/null && echo 1 || echo 0');
}
@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
@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 / 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 / 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"' _ {} \;
}