Skip to content

Instantly share code, notes, and snippets.

View betweenbrain's full-sized avatar
🎯
Focusing

Matt Thomas betweenbrain

🎯
Focusing
View GitHub Profile
@betweenbrain
betweenbrain / gist:1277937
Created October 11, 2011 12:21
Regex to find name attribute containing any single word
name\=\"\b[a-zA-Z0-9_]*"
  • More complex usage using a tagged expression to move contents of the anchor to after it

Search with \<a name="">([a-zA-Z0-9_]*)\&lt;\/a\&gt; to replace with \</a><a name="">\&lt;\/a\&gt;$2

@betweenbrain
betweenbrain / gist:1336627
Created November 3, 2011 14:31
Example Joomla 1.7 Menu Image Sprite CSS for Construct Template Framework
#nav ul.menu li a {
display:block;
text-indent: -999em;
width:55px;
height:46px;
background-image:url('../images/menu.png');
background-repeat: no-repeat;
}
#nav ul.menu li.item-435 a{
background-position: -170px 0.9px;
@betweenbrain
betweenbrain / gist:1650738
Created January 21, 2012 01:54
Add Joomla Menu Item ID as Body Class
In your template:
-------------------
<?php defined('_JEXEC') or die;
// Menu Item ID
$itemId = JRequest::getInt('Itemid', 0); ?>
<body class="<?php echo 'item-' . $itemId;?>">
...
</body>
@betweenbrain
betweenbrain / gist:1650746
Created January 21, 2012 01:58
Automatically Detect and Insert Image [name based on alias] Into Joomla Template
<?php
$itemId = JRequest::getInt('Itemid', 0);
if ($itemId) {
$currentAlias = JSite::getMenu()->getActive()->alias;
$altText = str_replace("-"," ",$currentAlias);
$fileTypes = array('png','jpg','jpeg','gif');
foreach ($fileTypes as $fileType) {
$headerImage = JPATH_BASE . '/images/banners/' . $currentAlias . '.' . $fileType;
if(JFile::exists($headerImage)) {
list($width, $height, $type, $attr) = getimagesize($headerImage);
@betweenbrain
betweenbrain / gist:1731407
Created February 3, 2012 17:58 — forked from ryanlindsey/gist:1332237
.htaccess
AddDefaultCharSet utf-8
DefaultLanguage en-US
# Activate rewrite engine
Options +FollowSymLinks
RewriteEngine on
# Redirect to wwww
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
@betweenbrain
betweenbrain / gist:1782739
Created February 9, 2012 20:08
Bash readline example that includes default answer from http://stackoverflow.com/a/4480034/901680
#!/bin/bash
read -p "Enter IP address: " -e -i 192.168.0.4 IP
echo $IP
@betweenbrain
betweenbrain / gist:2033316
Created March 14, 2012 01:51
jQuery toggle with hashtag detection
$(document).ready(function() {
$('dt').prepend('<img class="toggle" src="images/arrow.png" width="9" height="9" /> ');
var hashTag = window.location.hash.substring(1);
$('dd').each(function(i) {
var itemAnchor = $(this).prev('dt').find('a[name]').attr("name");
if ( itemAnchor == hashTag ) {
$(this).show();
}
else {
$(this).hide();
@betweenbrain
betweenbrain / gist:2284129
Created April 2, 2012 14:56
Git command to export only changed files between two commits
git archive --output=file.zip HEAD $(git diff --name-only SHA1 SHA2)
@betweenbrain
betweenbrain / gist:2644421
Created May 9, 2012 13:17
Add heading to absolute first article of first page of Joomla 2.5 category blog
Add the following to your /com_content/category/blog.php template override just before <?php $this->item = &$item; echo $this->loadTemplate('item'); ?> of the class="leading" item.
<?php if ($this->pagination->get('pages.current') == 1) echo '<h1>Absolute First Article</h1>' ?>