Skip to content

Instantly share code, notes, and snippets.

@betweenbrain
betweenbrain / gist:5917439
Created July 3, 2013 12:18
Joomla! home (default menu item) page only module position with multi-lingual support.
<?php
$app = JFactory::getApplication();
$menu = $app->getMenu();
$lang = JFactory::getLanguage();
$isHome = $menu->getActive() == $menu->getDefault($lang->getTag());
?>
<?php if ($isHome) : ?>
<jdoc:include type="modules" name="home"/>
<?php endif ?>
@betweenbrain
betweenbrain / gist:6083354
Created July 25, 2013 20:19
Recursively trim non-alphanumeric characters from the end of a string.
$string = "Mary had a little lamb :#$";
$length = strlen($string);
$regex = "/[^a-z0-9]/i";
for ($i = 1; $i <= $length; $i++) {
if (preg_match($regex, substr($string, $length - 1, 1))) {
$string = substr($string, 0, $length - 1);
$length = $length - 1;
} else {
break;
@betweenbrain
betweenbrain / A-Pen-by-Matt-Thomas.markdown
Last active December 21, 2015 15:19
(jQuery) Adds touch support to CSS Suckerfish menus
@betweenbrain
betweenbrain / gist:6331991
Last active December 21, 2015 16:09
Update Git on Ubuntu 12.04

Important: The contents of Personal Package Archives are not checked or monitored. You install software from them at your own risk. This PPA is maintained by the Ubuntu Git Maintainers team. https://launchpad.net/~git-core/+archive/ppa

$ sudo add-apt-repository ppa:git-core/ppa If you get a sudo: add-apt-repository: command not found error, then you need to run $ sudo apt-get install python-software-properties

$ sudo apt-get update

$ sudo apt-get upgrade

@betweenbrain
betweenbrain / gist:6332044
Last active December 21, 2015 16:09
Upgrade PHP on Ubuntu 12.04 to most recent version

WARNING: This procedure may have adverse side effects. You have been warned!

As the latest official version of PHP supported by Ubuntu 12.04 is 5.3.10, you need to add an external source for more recent versions. The source used is Dotdeb. "The packages from Dotdeb should work on Ubuntu, but no additional support will be provided." - http://www.dotdeb.org/about/

Add Dotdeb as package sources $ sudo nano /etc/apt/sources.list and add:

  • deb http://php53.dotdeb.org squeeze all
  • deb-src http://php53.dotdeb.org squeeze all
@betweenbrain
betweenbrain / gist:6370134
Created August 28, 2013 19:23
SQL Find and Replace - CLI
update [table_name] set [field_name] = replace([field_name],'[string_to_find]','[string_to_replace]');
update jos_content set `fulltext` = replace(`fulltext`,'foo','bar')
See: http://stackoverflow.com/questions/7615659/sql-fulltext-returning-null
@betweenbrain
betweenbrain / gist:6400643
Created August 31, 2013 21:07
Fix /usr/local/ddos/ddos.conf: unexpected operator
Change
#!/bin/sh
to
#!/bin/bash
@betweenbrain
betweenbrain / gist:6402286
Created September 1, 2013 04:08
Joomla SEF URLs Nginx

Edit corresponding file in /etc/nginx/sites-enabled and change # try_files $uri $uri/ /index.php?$args; to try_files $uri $uri/ /index.php?q=$request_uri;

@betweenbrain
betweenbrain / gist:6440817
Created September 4, 2013 18:25
PHP usort anonymous function alphabetize
usort($this->item->tags, function ($a, $b) {
return strcmp(strtolower($a->name), strtolower($b->name));
});
@betweenbrain
betweenbrain / gist:6888212
Created October 8, 2013 17:22
FeedGator Multiple Category Import Fix
// Replaces /administrator/components/com_feedgator/helpers/feedgator.helper.php:303-308
if ($fgParams->get('save_feed_cats')) {
if ($categories = $item->get_categories()) {
foreach ($categories as $category) {
$metakey[] = $category->get_label();
}
}
$content['metakey'] .= implode(', ', $metakey);
}