Skip to content

Instantly share code, notes, and snippets.

View ethangardner's full-sized avatar

Ethan Gardner ethangardner

View GitHub Profile
@ethangardner
ethangardner / xsl-restaurant-menu-2.xsl
Created June 28, 2011 23:49
XSL Restaurant Menu 2
<xsl:template match="/">
<!-- creates a template and the match="/" applies
it to the root (document element). This also sets the
context of the other match statements in the XSL.
If the conditions of the match statement are true,
some other code will be processed and output.
-->
<html>
<head>
<link rel="stylesheet" href="restaurant-menu.css" />
@ethangardner
ethangardner / xsl-restaurant-menu-3.xsl
Created June 28, 2011 23:51
XSL Restaurant Menu 3
<xsl:template name="section" match="menu/section">
<!-- This begins a new template called "section." Providing a name
attribute for a template helps with code organization and also
allows the template to be explicitly called by another template.
Remember our XML structure. The match statement will apply the
template to the all of the section tags which are children of the
menu tag.
-->
<h2><xsl:value-of select="@name" /></h2>
@ethangardner
ethangardner / xsl-restaurant-menu-4.xsl
Created June 28, 2011 23:52
XSL Restaurant Menu 4
<xsl:template name="item" match="item">
<!-- This is a new template that is being called from the section template -->
<dt><xsl:value-of select="title" /></dt>
<dd><xsl:value-of select="description" /></dd>
<dd class="price">$<xsl:value-of select="price" /></dd>
<dd><xsl:value-of select="img" /></dd>
<dd class="options"><xsl:value-of select="options" /></dd>
<dd class="category"><xsl:value-of select="category" /></dd>
<!-- The above block of code renders out a definition list based on the
matched items.
@ethangardner
ethangardner / php-gzip-optimization.php
Created June 29, 2011 00:25
PHP Gzip Optimization
<?php
if(extension_loaded('zlib')){
ob_start('ob_gzhandler');
}
header ('content-type: text/css; charset: UTF-8');
header ('cache-control: must-revalidate');
$offset = 60 * 60;
$expire = 'expires: ' . gmdate ('D, d M Y H:i:s', time() + $offset) . ' GMT';
header ($expire);
ob_start('compress');
@ethangardner
ethangardner / Restore MySQL Database
Created August 16, 2011 13:32
Restore MySQL Database
# Removes the database
mysqladmin -u USERNAME -p drop DATABASE
# Recreates the database
mysqladmin -u USERNAME -p create DATABASE
# Restores the database
mysql -u USERNAME -p DATABASE < FILENAME.mysql
@ethangardner
ethangardner / gist:1169249
Created August 24, 2011 21:08
Backup MySQL database
mysqldump --add-drop-table -u db_username -p db_name > mybackup.sql
@ethangardner
ethangardner / disable-wp-rss.php
Created September 21, 2011 17:31
Disables Wordpress RSS feeds
/**
* Disable RSS feeds for Wordpress
*/
function fb_disable_feed() {
wp_die( __('No feed available,please visit our <a href="'. get_bloginfo('url') .'">homepage</a>!') );
}
add_action('do_feed', 'fb_disable_feed', 1);
add_action('do_feed_rdf', 'fb_disable_feed', 1);
add_action('do_feed_rss', 'fb_disable_feed', 1);
@ethangardner
ethangardner / string-replace.sql
Created September 21, 2011 17:33
MySQL String Replace
UPDATE [table name] SET [table column] = REPLACE([table column],"[original string]","[new string]")
@ethangardner
ethangardner / using-temlates.xsl
Created September 21, 2011 17:35
Using templates instead of foreach in XSL
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<h3 id="keynotes">Keynotes</h3>
<ul class="none" id="speakers">
<xsl:apply-templates />
</ul>
</xsl:template>
@ethangardner
ethangardner / remove-script-from-joomla.php
Created September 21, 2011 17:39
Remove script tag from the head of Joomla templates for non-admin users
<?php
$user =& JFactory::getUser();
if ($user->get('guest') == 1) {
$headerstuff = $this->getHeadData();
$headerstuff['scripts'] = array();
$this->setHeadData($headerstuff);
}
?>