Skip to content

Instantly share code, notes, and snippets.

View supermethod's full-sized avatar

Chris Toppon supermethod

View GitHub Profile
@supermethod
supermethod / gist:377878fce40d49a44b06
Created July 11, 2014 12:25
Create a Brewfile for migrating your homebrew Cellar
#Create the Brewfile
touch Brewfile
# tap homebrew versions repo
echo 'tap homebrew/versions' >> Brewfile
# add install commands for everything installed in the Cellar
for i in `ls /usr/local/Cellar/`; do echo "install $i" >> Brewfile; done;
# to use run 'brew bundle' with the Brewfile in the current directory
@supermethod
supermethod / update_git_repos.sh
Last active August 29, 2015 14:03 — forked from douglas/update_git_repos.sh
Update all svn repos in a directory, supports nested directory structure
#!/bin/bash
set -eu
# store the current dir
CUR_DIR=$(pwd)
# Let the person running the script know what's going on.
echo -e "\n\033[1mPulling in latest changes for all repositories...\033[0m\n"
@supermethod
supermethod / gist:913396
Created April 11, 2011 11:56
Format SimpleXML xml output
$doc = new DOMDocument('1.0');
$doc->preserveWhiteSpace = false;
@$doc->loadXML( $xml->asXML() );
$doc->formatOutput = true;
//return as string
return $doc->saveXML();
//save as file
//return $doc->save('data.xml');
@supermethod
supermethod / gist:913394
Created April 11, 2011 11:53
Convert a PHP array into XML file using SimpleXML
class ArrayToXML
{
/**
* The main function for converting to an XML document.
* Pass in a multi dimensional array and this recrusively loops through and builds up an XML document.
* Based on: http://snipplr.com/view/3491/convert-php-array-to-xml-or-simple-xml-object-if-you-wish/
*
* @param array $data
* @param string $rootNodeName - what you want the root node to be - defaultsto data.
* @param SimpleXMLElement $xml - should only be used recursively
@supermethod
supermethod / gist:913379
Created April 11, 2011 11:26
String to Slug
function slug($str)
{
$str = strtolower(trim($str));
$str = preg_replace('/[^a-z0-9-]/', '-', $str);
$str = preg_replace('/-+/', "-", $str);
return $str;
}
@supermethod
supermethod / gist:913378
Created April 11, 2011 11:24
Close open tags and remove certain html for CDATA inclusion
//from http://codesnippets.joyent.com/posts/show/959
function close_dangling_tags($html){
#put all opened tags into an array
preg_match_all("#<([a-z]+)( .*)?(?!/)>#iU",$html,$result);
$openedtags=$result[1];
#put all closed tags into an array
preg_match_all("#</([a-z]+)>#iU",$html,$result);
$closedtags=$result[1];
$len_opened = count($openedtags);
@supermethod
supermethod / gist:913375
Created April 11, 2011 11:22
Convert HTML entities to XML entities - optionally coverts special characters
function xmlEntities($string, $specialchars = false) {
$translationTable = get_html_translation_table(HTML_ENTITIES, ENT_QUOTES);
foreach ($translationTable as $char => $entity) {
$from[] = $entity;
$to[] = '&#'.ord($char).';';
}
//convert special characters &, ", ', <, > to html entities
if ($specialchars) {
$string = htmlspecialchars($string);
@supermethod
supermethod / Wordpress RSS 2.0 image enclosure
Created March 8, 2011 15:09
How to add an enclosure to a wordpress RSS feed using the first image of the post - add to functions.php
function feedFilter($query) {
if ($query->is_feed) {
add_filter('rss2_item', 'feedContentFilter');
}
return $query;
}
add_filter('pre_get_posts','feedFilter');
function feedContentFilter($item) {