How to add an application to the ‘Other Applications’ list in Ubuntu

Posted May 6th, 2012 (Updated 9 May 2012) in Linux

It seems Gnome 3 removed the button allowing users to add specified applications into the ‘Other Applications’ list under ‘Open With’ in file properties. Until the functionality is restored, you can add applications manually by doing the below:

cp /usr/share/applications/gedit.desktop ~/.local/share/applications/your_app.desktop

Modify the contents of your_app.deskop to look something like the below:

[Desktop Entry]
Name=your_app
GenericName=Your App
Comment=Edit text files
Keywords=Plaintext;Write;
Exec=your_app %U
Terminal=false
Type=Application
StartupNotify=true
MimeType=text/plain;
Icon=accessories-text-editor
Categories=GNOME;GTK;Utility;TextEditor;
Actions=Window;Document;
X-Ubuntu-Gettext-Domain=your_app

You can copy any .desktop file from /usr/share/applications so pick the one that closest resembles the application you’re adding. Below you can see komodo added to mine:

Komodo has been added to my 'Open With' list
Komodo has been added to my ‘Open With’ list

Read More »

Change default ‘From’ email name from www-data in PHP

Posted April 19th, 2012 (Updated 22 Apr 2012) in Linux, PHP

I’ve been seeing up an Amazon EC-2 server with Debian Squeeze and used tasksel to install Web Server and Mail Server. Like all things debian, this worked pretty well after the installation completed and everything ‘just worked’ however I wasn’t happy with the default from name and email address assigned to emails sent by PHP – www-data <[email protected]>.

I discovered a quick and simple fix to change these defaults for all mail sent with PHP:

Open /etc/php5/apache2/php.ini and set

sendmail_path = '/usr/sbin/sendmail -t -i [email protected] -Fno-reply'

You can see a list of sendmail arguments and what they do here.

Restart apache and you’re good to go:

sudo service apache2 restart

Read More »

Cross Domain AJAX with JQuery

Posted April 11th, 2012 in Javascript

Anyone attempting to do cross domain AJAX will be familiar with the following message:

XMLHttpRequest cannot load http://domain.com/page.php. Origin http://yoursite.com is not allowed by Access-Control-Allow-Origin.

However if you own the server you’re AJAXing data from, there’s a simple way to make this possible using a callback. Here’s an example:

server.php (On a different domain):

<?php
	$response = 'your response here'.
 
	if ( !isset($_GET['callback']) ) $_GET['callback'] = '';
 
	echo $_GET['callback'] . '('.json_encode(array('response'=>$response)).');';

client.php (with JQuery):

$.getJSON('http://yourdomain.com/server.php?callback=?', function(json) {
	alert( json.response );
});

That’s all there is to it. Remember the ?callback=? URL segment or it won’t work.

Read More »

Use Apache Alongside Nginx Without Requiring a Subdomain

Posted March 18th, 2012 in Linux, PHP

I’ve been looking for ways to speed up my site recently and came across this interesting article on seamlessly integrating nginx with Apache to handle asset files without requiring a CDN subdomain. This works by checking the requests file extension for .js, .jpg, .pdf etc and if not found, proxies the request to Apache and serves the results.

Benefits

You won’t need to modify all your pages/posts updating asset locations to point to a subdomain! Everything will ‘just work’.

Issues/Drawbacks

There are 2 issues I’ve found with this setup:

  • Because Apache is now running on port 8080, your mod_rewrite redirects will now redirect to that port. You won’t be able to use RedirectMatch anymore, however below is the solution I came up with:
    RewriteEngine on
    RewriteRule ^foo.php$ http://%{HTTP_HOST}:80/bar.php [R=301,L]
  • You can no longer use .htaccess redirects for any asset files nginx is serving. Instead, use nginx redirects. Below is an example:
    rewrite ^/foo.jpg$ http://173.255.221.210/bar.jpg permanent;

    For more information on nginx redirects, see the official documentation.

Read More »

Forward Email from a Specified Address

Posted March 7th, 2012 (Updated 20 Apr 2012) in Linux

A couple of times now we’ve needed to forward [email protected] to [email protected]. If you’re running postfix here’s how to do that.

nano /etc/postvix/virtual

Add

[email protected] [email protected]

then run

postmap /etc/postfix/virtual

If the above doesn’t work, make sure you have the following line in /etc/postfix/main.cf:

virtual_alias_maps = hash:/etc/postfix/virtual

and type

service postfix reload

Thanks to Matt Simmons of ServerFault for his answer.

Read More »

Hide the Attention Button in Pidgin

Posted February 16th, 2012 in Linux
Pidgin Attention button successfully hidden
Pidgin Attention button successfully hidden

Ever since the developers added the Attention button to Pidgin, one of the most common questions asked is how to remove it. I finally set some time aside to answer this question.

  • Download the plugin that does exactly this from the Pidgin developer page.
  • Install the Pidgin developer dependencies if you haven’t already:
    sudo apt-get install ubuntu-dev-tools subversion g++ pidgin-data libpurple0 libpurple-dev pidgin-dev libgtk2.0-dev

    This step is important or you’ll receive errors like the following:

    $ make
    [CC] hide_attention_button.o
    Package pidgin was not found in the pkg-config search path.
    Perhaps you should add the directory containing `pidgin.pc'
    to the PKG_CONFIG_PATH environment variable
    No package 'pidgin' found
    Package purple was not found in the pkg-config search path.
    Perhaps you should add the directory containing `purple.pc'
    to the PKG_CONFIG_PATH environment variable
    No package 'purple' found
    Package gobject-2.0 was not found in the pkg-config search path.
    Perhaps you should add the directory containing `gobject-2.0.pc'
    to the PKG_CONFIG_PATH environment variable
    No package 'gobject-2.0' found
    Package gtk+-2.0 was not found in the pkg-config search path.
    Perhaps you should add the directory containing `gtk+-2.0.pc'
    to the PKG_CONFIG_PATH environment variable
    No package 'gtk+-2.0' found
    hide_attention_button.c:24:20: fatal error: plugin.h: No such file or directory
    compilation terminated.
    make: *** [hide_attention_button.o] Error 1
  • Drop the .c and Makefile into a folder and in a terminal run the following commands:
    make
    sudo make install

    If all went well you’ll see:

    $ make
    [CC] hide_attention_button.o
    [SHLIB] hide_attention_button.so
    $ sudo make install
    mkdir -p /`pkg-config --variable=prefix purple`/lib/purple-2
    install hide_attention_button.so /`pkg-config --variable=prefix purple`/lib/purple-2

Restart pidgin and enable the plugin under Tools – Plugins – Hide Pidgin Attention Button.

Close but not Perfect

Although this plugin really does hide your Attention button, it still exists if you hover over where it used to be:

The button is much smaller but still clickable
The button is much smaller but still clickable

At least it’s much smaller now and less likely to be accidentally clicked!

Read More »

PHP WebSocket Chat Application 2.0

Posted February 15th, 2012 (Updated 29 Oct 2013) in Javascript, PHP

Even though it hasn’t worked for quite some time now, my previous PHP WebSocket chat application has garnered quite a bit of attention and is still one of my most heavily trafficked posts. As a result I thought I’d provide you all with a working script as of Feb 15, 2012. Also, because I’m your typical lazy developer, I’ll be building on top of other peoples’ work – most notably PHPWebSocket.

You can download the final script here. According to the Wikipedia article on WebSockets, it should work in IE10+, Firefox 7+ and Chrome 14+. Personally I tested with Chrome 17.0.963.46 and Firefox 10.0.1.

I want to stress that this tutorial is designed to be extremely basic and as such does not give alot of functionality out of the box (but provides all the tools required to add more). It’s simply a working example of a PHP-based WebSocket server.

Read More »

Change Default Language/Subtitles in MKV Files

Posted January 15th, 2012 (Updated 14 Oct 2013) in Linux

Tonight I discovered I had an entire folder of dual audio MKV files with the wrong default language and wrong default subtitle track. I could have used mkvpropedit to manually change each file but that’s such a hassle. Instead, here’s a bash script to do them all at once (You’ll need to tweak the highlighted rows accordingly):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/bin/bash
OIFS="$IFS"
IFS=$'n' 
for file in "/path/to/files/"*.mkvdo
	echo $file
	#Update audio track defaults
	mkvpropedit "${file}" --edit track:2 --set flag-default=0	mkvpropedit "${file}" --edit track:3 --set flag-default=1	#Update subtitle track defaults
	mkvpropedit "${file}" --edit track:4 --set flag-default=0	mkvpropedit "${file}" --edit track:5 --set flag-default=1done
IFS="$OIFS"

You’ll need mkvtoolnix installed for the mkvpropedit command. To determine what the various tracks contain, do a

1
mkvinfo /path/to/file.mkv

or mkvinfo -g for you GUI users :)

As an added bonus, here’s the Windows equivalent of this script:

1
2
3
4
5
6
7
8
9
@echo off
FOR /f "tokens=*" %%G IN ('dir /a-d /b') DO (
	mkvpropedit.exe "%%G" --edit track:2 --set flag-default=0
	mkvpropedit.exe "%%G" --edit track:3 --set flag-default=0
	mkvpropedit.exe "%%G" --edit track:4 --set flag-default=1
	mkvpropedit.exe "%%G" --edit track:5 --set flag-default=0
	echo.
)
pause

I’ve been told the Windows version works but haven’t tested personally.

Happy viewing!

Read More »

LemonStand: Maximum function nesting level of ’100′ reached

Posted January 12th, 2012 (Updated 3 Sep 2012) in Lemonstand, PHP

Last night I was getting a strange error in LemonStand administration area when attempting to edit a product or category:

Fatal error: Maximum function nesting level of ’100′ reached, aborting! in /path/to/phproad/modules/phpr/helpers/phpr_inflector.php on line 322

If you’re also experiencing this error, it’s caused by XDebug and can be solved by adding

1
ini_set('xdebug.max_nesting_level', 200);

to your config/config.php file.

Thanks to Aleksey Bobkov and EHLOVader for their help in solving this issue. Here is the official LemonStand forum thread on the issue.

Read More »

Moving WordPress Multi-Site Between Servers

Posted January 11th, 2012 (Updated 22 May 2014) in Database, Linux, PHP

Tonight I had to move my WPMU install from my local development machine to the live server – this meant a change in installation path which is always a hassle with WordPress. Below I’ll detail my issues and the corresponding fixes in the hopes it will make life easier for others experiencing the same problems.

Redirection to wp-signup.php

First thing I noticed was that when loading the site on a live domain, I’d get instantly redirected to mydomain.com/wp-signup.php?new=mydomain.com. With a bit of Googling I came across this forum thread which recommended adding the following to my wp-config.php:

1
2
define( 'NOBLOGREDIRECT', '' );
define( 'SUBDOMAIN_INSTALL', false );

Don’t do this! It will get the site closer to working order but it’s not going to help you in the long run – especially when you need the other domains working too. Instead here’s what you should be doing:

1
2
3
4
5
6
7
#Dump your DB
mysqldump - u<username> -p<password> -h<host> <dbname> > test.sql
 
#Update folder path to that of the new servers
sed -i "s/path/to/install/new/path/to/install/g" test.sql 
#If you installed into localhost/foo/bar/mysite, change that to your live servers domain
sed -i "s/url/path/to/site/www.domain.com/g" test.sql

This is pretty standard behavior for moving WordPress sites, however if you load the above dump up on your live domain you’ll probably be greeted with the dreaded Error establishing a database connection.

Error establishing a database connection

Heading to www.domain.com/wp-admin will shed a little more light on the situation – you need to update your wp_blogs table for the main site. WPMU is currently using your development servers URL from this table and ignoring what’s in wp-config.php. To play things safe we’ll update any occurrances of our test servers domain in test.sql:

1
2
#Update your live servers subdomain in wp_blogs to your live servers domain
sed -i  "s/yoursite.localhost.com/www.yourdomain.com/g" test.sql

This should do the trick. Load that bad boy into your live server and you should be good to go!

Read More »

Page 5 of 14« First...34567...10...Last »