Skip to content

Instantly share code, notes, and snippets.

View a1phanumeric's full-sized avatar

Ed Rackham a1phanumeric

  • Select Trade Brands
  • Torbay, UK
View GitHub Profile
@a1phanumeric
a1phanumeric / index.php
Created June 20, 2018 15:48
PHP redirect to HTTPS if htaccess if giving you bare grief
if(empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == "off"){
$redirect = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
header('HTTP/1.1 301 Moved Permanently');
header('Location: ' . $redirect);
exit();
}
@a1phanumeric
a1phanumeric / gist:5474848
Created April 27, 2013 21:41
HTTrack - Scan just a sub-directory of domain
httrack "http://domain.com/path/?querystring" '-*' '+http://domain.com/path/*' -v
@a1phanumeric
a1phanumeric / gist:5442288
Created April 23, 2013 09:54
Find strings within files using find to filter the searched files.
find /home/*/www/lib -name "functions.php" -exec grep --color -H -n "functionName" {} \;
@a1phanumeric
a1phanumeric / gist:5346170
Created April 9, 2013 14:35
Grep exclusions. Demonstrates how to exclude multiple directories, and files.
grep -r --color --exclude-dir={custom,lib,scripts} --exclude={*.xml,error_log} "beta" .
@a1phanumeric
a1phanumeric / gist:5293430
Created April 2, 2013 16:05
Total dovecot_logins based on the latest exim_mainlog
egrep -o 'dovecot_login[^ ]+' /var/log/exim_mainlog | sort|uniq -c|sort -nk 1
@a1phanumeric
a1phanumeric / batch_ai_to_svg.jsx
Created March 19, 2013 10:28
ESTK .jsx script to open directory of .ai files and save them as SVGs with standardised artboards (an artboard which perfectly fits the image).
#target illustrator
var sourceDir,
destDir,
files,
sourceDoc;
sourceDir = Folder.selectDialog( 'Select the import directory.', '~' );
destDir = Folder.selectDialog( 'Select the export directory.', sourceDir.sourceDir );
@a1phanumeric
a1phanumeric / gist:4491744
Created January 9, 2013 09:06
Remove extra attributes from file permissions for files in path '.' (OSX)
xattr -cr .
@a1phanumeric
a1phanumeric / gist:4491730
Created January 9, 2013 09:04
Find and replace string in all files OSX
find /path/to/dir/* -type f -exec sed -i '' 's/FIND_STRING/REPLACE_STRING/g' {} \;
@a1phanumeric
a1phanumeric / gist:4284225
Created December 14, 2012 10:02
Find process of long running script (php in this case)
pgrep -fl filename.php
# returns something like:
# 4676 /usr/bin/php /path/to/file.php
@a1phanumeric
a1phanumeric / gist:4284074
Created December 14, 2012 09:39
Removes files older than one day
<?php
// Removes files older than a day
$dir = '/path/to/dir';
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
$filelastmodified = filemtime($dir . '/' . $file);
$filetype = filetype($dir . '/' . $file);