Set wp_is_mobile() to true

Sometimes you’ll want to set wp_is_mobile() to true by default for testing purposes. You can find the file under

~/wp-includes/vars.php

function wp_is_mobile() {
	static $is_mobile;

	if ( isset($is_mobile) )
		return $is_mobile;

	if ( empty($_SERVER['HTTP_USER_AGENT']) ) {
		$is_mobile = false;
	} elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Mobile') !== false // many mobile devices (all iPhone, iPad, etc.)
		|| strpos($_SERVER['HTTP_USER_AGENT'], 'Android') !== false
		|| strpos($_SERVER['HTTP_USER_AGENT'], 'Silk/') !== false
		|| strpos($_SERVER['HTTP_USER_AGENT'], 'Kindle') !== false
		|| strpos($_SERVER['HTTP_USER_AGENT'], 'BlackBerry') !== false
		|| strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mini') !== false
		|| strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mobi') !== false ) {
			$is_mobile = true;
	} else {
		$is_mobile = false;
	}
	return $is_mobile;
}

Simply change that code to

function wp_is_mobile() {
	static $is_mobile;

	if ( isset($is_mobile) )
		return $is_mobile;

	if ( empty($_SERVER['HTTP_USER_AGENT']) ) {
		$is_mobile = false;
	} elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Mobile') !== false // many mobile devices (all iPhone, iPad, etc.)
		|| strpos($_SERVER['HTTP_USER_AGENT'], 'Android') !== false
		|| strpos($_SERVER['HTTP_USER_AGENT'], 'Silk/') !== false
		|| strpos($_SERVER['HTTP_USER_AGENT'], 'Kindle') !== false
		|| strpos($_SERVER['HTTP_USER_AGENT'], 'BlackBerry') !== false
		|| strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mini') !== false
		|| strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mobi') !== false ) {
			$is_mobile = true;
	} else {
		$is_mobile = false;
	}
	$is_mobile = true;    // sets wp_is_mobile() to true at every call
	return $is_mobile;
}

There are better ways to get around this, but this is the fastest I’ve found. Make sure you’re not using this in production, and change it back before launch!

Posted in How To, wordpress | Leave a comment

Ridiculous idea update…

I’ve modified a last.fm plugin so that it can play spotify tracks through the website. It plays inside of an iFrame though. I’ll need to get it so that the content’s being played from inside the actual website. Not sure if Spotify offer that as a service, perhaps it’s time to look at SoundCloud.

At the minute, the code is pretty poor (did it in an hour in the evening the other day). At the minute it checks if it’s parsing the first returned song in my last.fm “recent” list, if it is, then it goes and gets the new last.fm api call to get a spotify URI based on that track. It then generates a little iframe above the last.fm plugin and lets you play whatever I’m listening to at the minute (not guaranteed to be good!)

Offending code:

//appendHtml+='<li class="theCurrentTrack">'+chanson+'<br />'+name+'</li>';
				jQuery.ajax({
					type:"POST",
					url:"http://ws.audioscrobbler.com/2.0/?method=track.getPlaylinks&artist[]="+name+"&track[]="+chanson+"&api_key=ec377ef696eeb6d28a9d03953d385cb3"
				}).success(function(msg2){
					var response2=msg2;
					jQuery(response2).find('externalids').each(function(){
						spotifyURI=jQuery(this).find('spotify').text();						appendHtml+='<iframe src="https://embed.spotify.com/?uri=spotify:track:0S0sPQMiDcgWzKgegcuFVw" width="160" height="80" frameborder="0" allowtransparency="true"></iframe>';
					});
				jQuery("#interiorhok").html("<h2>Right Now:<br />"+chanson+"<br />"+name+"</h2><iframe src='https://embed.spotify.com/?uri="+spotifyURI+"' width='80' height='80' frameborder='0' allowtransparency='true'></iframe>");
				});
			}
			appendHtml+='<li><a target = "blank" title = "'+name+', '+chanson+'" href = "'+url+'"><img src = "'+image+'" alt = "'+name+', '+chanson+', '+album+'" width = "'+tumblrFm.size+'" height = "'+tumblrFm.size+'"/></a></li>';

If you’ve got Spotify installed it’s going to try and launch that though, or pause what you’re already playing. I don’t like that functionality, so I’ll get that changed soon.

Link to the original dev here

Link to my github repo for my edits here

Posted in Music, music dev | Leave a comment

Here’s a ridiculous idea…

I’m going to make a web-based Fast Fourier Transformer. Then I’m going to get it to load in Spotify/Soundcloud tracks. Then I’m going to write a random-story generator. Then I’m going to make the Fast Fourier Transformer select the direction the story goes. Then I’ll add some graphics to tell the story. Started as a small idea, in the space of one paragraph it’s become a bit of work…

I think for the start I’ll use an existing FFT lib in JS. I’ve found a SO question here that’ll help me with this:

http://stackoverflow.com/questions/7821473/fft-in-javascript

First step is the minimum viable product. So I’ll just get that FFT lib linked into Spotify/Soundcloud and changing an image. Then I’ll move onto the more complicated bits (like generating story… The most I did at uni was random name/role generators).

Second step, get the FFT to modify the image based on BPM, and a couple of other things. Third, grab the lyrics from some website’s API (maybe Spotify/Last.fm already offer these services). Next step, parse each of the lyrics files for keywords, and display those on screen. Next, step will be to build the generator. When/if I ever get up to there I’ll think about the next steps.

Posted in Game Dev, Music | Leave a comment

How to change Swappiness in Ubuntu

It’s likely that if you don’t know how to change the Swappiness value, you don’t know what you should be changing it to, and maybe don’t know what Swap is at all, so this is actually a few questions

What is Swappiness?

Swappiness is the setting relating to how aggressively your linux system will use the Swap Memory.

What is Swap Memory?

Swap memory is a type of overflow memory that is used to prevent your system crashing when the memory required approaches or passes the size of RAM on a linux system. It is a partition of your Hard Drive or SSD that is dedicated to “act like” RAM. Remember that Hard Disk Drives are physical drives that need to mechanically spin to retrieve data. You should not use Swap as a permanent replacement for RAM. Solid State Drives are faster than HDDs, but they’re not as fast as RAM. A 128GB SSD shouldn’t be viewed as 128GB of cheap RAM.

How much Swap Memory do I need?

How long is a piece of string? The answer varies depending on a number of circumstances that your environment has.  The minimum you should aim for is at least the same size as the RAM you have available. If you’ve got a simple 512MiB RAM installation, then you should have at least 512MiB HDD space.  If HDD space is at a premium as well as your RAM size, then you’ll have to make considerations. For example if you’ve got 4GB RAM and a 20GB HDD (for some insane reason) then you’re not going to want to spend 4GB of your HDD on Swap.  If HDD space is plentiful then go for at least the size of your RAM, and see how that works. If you’re reaching 100% of your swap memory on a regular basis, consider increasing your RAM alongside the size of your swap.

If HDD space is sparse compared to your RAM then make a reasonable swap partition, monitor it for a few days, particularly under high load, and see how the server runs.

So, what should my Swappiness be set to?

Annoyingly for anyone looking for a quick-fix it’s not as simple as just saying “60″. You need to take a few things into consideration:

Swapiness can be configured to anything between 0-100. The 0 and 60 aren’t %ges of Swap that will be used, they’re an aggression variable. A low aggression means that your system will prefer to steal pages form cache, a high aggression means that it prefers move to swap memory. Your mileage may (will) vary from system to system.

Adding to swap and taking from swap is in itself quite expensive on the system. Having said that, it’s also generally less expensive than grabbing from a (potentially external) Hard Drive.

A good number to start with is 50. Then work from there. If you find that your system is slowing, or locking up more often than you’d like, then check the status of your system in #top or #free. If the RAM usage is too high, then increase the swappiness, if the swap is too high then decrease swappiness. If you’re getting as low as 10-15 and still not seeing an improvement, then you’ll want to start looking into other issues. Equally, if you’re getting as high as 80-90 and not seeing an improvement then you’ve likely got issues elsewhere (consider checking MySQL buffers, and your actual RAM size).

How to Change Swappiness

You’ll need to have super user privileges for most of the following, and you’ll need to be able to turn off the system to reboot.

First let’s check swappiness.

cat /proc/sys/vm/swappiness
60

So mine was 60 (it’s actually the default, because I spun up the server for this tutorial). The server is an 8GB one, and it’s got a 4GB database running on it, I expect that Apache is going to take up a lot of memory, and then the actual site running will take up quite a bit too. Since in this instance I’ve got a big DB that I want kept mainly in RAM I’ll set the Swappiness quite low.

sudo nano /etc/sysctl.conf

then either find or change this line:

vm.swappiness = 60

to whatever you choose. I made it 20 as a start.

Next you’ll want to reboot the system. Once it’s back online run

cat /proc/sys/vm/swappiness
20

again and make sure it returns the number you input.

Posted in How To, Memory configuration, Technical, Ubunutu | Leave a comment

How to kill a process by its name in Ubuntu

Sometimes you want to end a process in Ubuntu, but have no idea what the process number is – alternatively you may be writing a script where the process ID is obviously going to be dynamic. Here’s a quick guide to ending a process by its name via command line:

Some services has slightly obscure names, for instance if you’re running a test server with skip-grant-tables version of MySQL it’ll be called mysqld. You’ll want to check and make sure you’re killing the correct process

ps -aux

This shows you a list of all the services running.  If that’s a little too much, narrow it down a little. Grep will display all processes containing the string searched. The service mysqld will show up in this Grep search:

ps -aux | grep "mysql"

Now that you’ve got the correct name out of the service list you can use the killall command properly like so:

killall -v mysqld

run ps again to double check that it’s been killed properly.

Posted in How To, Technical, Ubunutu | Comments Off

My Cron job is running multiple times in Ubuntu

If your Cron is a wget command you’ll need to set it so that it “gets” only one time irrelevant of the http response. Wget will re-attempt a connection until it receives a 2XX response. It’s possible under some CMS that you’ll have jobs that run from a Wget’d page.

The correct syntax for using a Wget only one time is:

0 * * * * wget -t 1 "http://example.com/wget/command.html"

This tells the Wget command to only get the page one time. If your page is dynamically generated it can take longer than the minimum response from Wget, at which point the Cron will appear to run a second time (and a third, fourth, fifth, until your server is overloaded).

The first 5 characters are time in Minutes, Hours, Days, Weeks, Years. The above example runs on the hour every hour of every day, every week, every year.

Posted in Cron, How To, Technical, Ubunutu | Comments Off

How to copy contents of one directory into another directory in Ubuntu

This one’s quite simple, but is often forgotten. The syntax for copying from one directory to another in Ubuntu is:

cp -a /path/to/source/folder/. /path/to/destination/folder

The -a keeps the file attributes and symlinks, the period at the end of the source folder makes sure that you get hidden folders too (important for .htaccess/.htpasswd files).

If your directories have high level access privileges you might need to use the sudo command to enact root privileges.

Posted in How To, Technical, Ubunutu | Comments Off

Technical Jelly Limited

January 2014 – Present

I am currently the joint owner of Technical Jelly Ltd a software/server engineering company providing consultation and development services to SMEs and Enterprise level businesses, as well as third party support & overflow development services to software companies throughout the UK and Ireland. The company specialises in LAMP stack server & application management/optimisation, Web & Graphic Design, and general software engineering. I’m a RackSpace certified partner, but also have the ability to work in the Azure environment depending on our client requirements.

Posted in Projects | Leave a comment

Hacktivist & The Algorithm

I went to see Hacktivist in Edinburgh. Ended up also seeing The Algorithm. They were incredible.

Posted in Gigs, Music | Leave a comment

First4Websites rebrand & website relaunch

August – October 2013

Redesign and redevelopment of the First4Websites flagship website in line with the final stage of rebranding from First For Websites Ltd to First4Websites.

The site was a team effort, including input from all members of staff including the named members above, Laura Thompson, Sheila Nicholson, Reece Vail, and Corinne Spencer. Outside consultancy was offered from Mike Jobson from Oxford Innovations.

The site is designed and built using cutting edge CSS and HTML techniques in order to fully showcase the companies capabilities and rigid commitment to future development. The site uses CSS3 and HTML5 and is based on a stripped back of the WordPress CMS, and was designed to reflect that First4Websites, though being based in the countryside, has an infinite amount of inspiration and in-house design talent

Posted in Projects | Leave a comment