Skip to content

Instantly share code, notes, and snippets.

View kfriend's full-sized avatar

Kevin Friend kfriend

  • 742 Evergreen Terrace
View GitHub Profile
@kfriend
kfriend / respond_and_process.php
Created March 11, 2016 01:35
PHP: Send response and continue processing
<?php
// Buffer all upcoming output...
ob_start();
// Send your response.
echo "Testing response";
// Get the size of the output.
$size = ob_get_length();
@kfriend
kfriend / gist:9669711
Created March 20, 2014 17:47
PHP: Get list of all tags used in an XML document
<?php
ini_set('memory_limit', '400M');
$doc = new DOMDocument();
$doc->loadXML(file_get_contents('/path/to/xml/file.xml'));
$xpath = new DOMXpath($doc);
$nodes = $xpath->query('//*');
@kfriend
kfriend / gist:6690005
Created September 24, 2013 19:28
PHP: array_splice_assoc() helper
<?php
function array_splice_assoc($array, $key, $replacement = array())
{
// Get numeric offset of the key to remove
$offset = array_search($key, array_keys($array));
if (!is_int($offset)) return $array;
unset($array[$key]);
@kfriend
kfriend / gist:5966561
Last active December 11, 2018 21:59
wget command tasks
# Scape a site w/ a few retries
wget -m -r --tries=5 "http://foo.bar"
# Scape a site w/o images
wget -m -r --tries=5 -R jpg,jpeg,png,gif,bmp "http://foo.bar"
@kfriend
kfriend / gist:0c81cd0b0bcd5dec2b9f
Created December 14, 2015 04:42
OS X: Create El Capitan ISO compatible with VirtualBox
#!/usr/bin/env bash
# All credit goes to http://apple.stackexchange.com/a/211722, and thanks to Jesse Web
# for posting the article at http://apple.stackexchange.com/questions/198737/install-el-capitan-in-virtual-box-for-testing-purposes
hdiutil attach "/Applications/Install OS X El Capitan.app/Contents/SharedSupport/InstallESD.dmg" -noverify -nobrowse -mountpoint /Volumes/esd
hdiutil create -o elcapitan.cdr -size 7316m -layout SPUD -fs HFS+J
hdiutil attach elcapitan.cdr.dmg -noverify -nobrowse -mountpoint /Volumes/iso
asr restore -source /Volumes/esd/BaseSystem.dmg -target /Volumes/iso -noprompt -noverify -erase
rm /Volumes/OS\ X\ Base\ System/System/Installation/Packages
@kfriend
kfriend / gist:6ac6b0d54bdfc5c7544304945ce004a0
Created September 13, 2017 20:17
Windows: Proxy Windows VM HTTP traffic to host machine
netsh interface portproxy add v4tov4 listenport=80 connectport=80 connectaddress=[HOST MACHINE IP]
@kfriend
kfriend / gist:38d93627f3d1c4fb99b21d03aeb115e5
Created July 27, 2017 18:35
Example ExpressionEngine to Wordpress Import Format
<?php $authors = array() ?>
<?= '<?' ?>xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
xmlns:excerpt="http://wordpress.org/export/1.0/excerpt/"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:wp="http://wordpress.org/export/1.0/"
>
<channel>
@kfriend
kfriend / gist:bf9a014818f3a4fd903ad1d44ceb5212
Created March 22, 2017 01:43
644 and 755 files and directories
# Source: http://stackoverflow.com/a/37287625/419673
chmod -R 644 dirName
chmod -R +X dirName
@kfriend
kfriend / gist:6706218
Last active August 11, 2016 00:20
PHP: Quick and dirty JIT image resizing (i.e. thumbnails) with built-in caching
<?php
$storagePath = './img';
$cachePath = $storagePath.'/cache';
// Maximum requestable dimensions
$maxWidth = 1000;
$maxHeight = 1000;
$forceJpeg = true;
@kfriend
kfriend / gist:4a4b36d5c3143b5feb12
Last active August 11, 2016 00:19
PHP: Very simple PDO DB wrapper
<?php
class Db
{
protected $connection;
public function __construct(PDO $connection)
{
$this->connection = $connection;