Yet another site to maintain!

Android Jellybean 4.2 Developer Options Missing

I just updated my GNex to AOSP 4.2 and started developing against it and low and behold, the Developer Options in the Settings menu were missing.

I looked through all the setting menu items to see if it had been moved but no, it was simply gone.

Turns out that you have to hit a certain menu item in the settings seven times (yep, seven times) in order to acknowledge your developer coolness.

Go to Settings -> About Phone then scroll down until you see Build Number and start tapping. Seven times in total will enable the Developer Options in their original place :)

Swift Mailer mail attachment example

After a quick google, all the email attachment examples were crap, using antiquated versions of the library and even PHP v4 code!

Here’s my working example for taking a registration form with a file upload INPUT element that get’s directly attached to an email and sent.

	require_once('swift/lib/swift_required.php');
	$transport = Swift_SendmailTransport::newInstance('/usr/sbin/sendmail -n -t');
	$mailer = Swift_Mailer::newInstance($transport);

	$message = Swift_Message::newInstance('EMAIL SUBJECT')->setFrom('FROM EMAIL ADDRESS')->setTo('TO EMAIL ADDRESS');

	$body = "*** REGISTRATION FORM ***\n\n";
	$body .= 'First Name: ' . \WIC\Core::c()->qs('fname') . "\n";
	$body .= 'Last Name: ' . \WIC\Core::c()->qs('lname') . "\n";
	$body .= 'Address: ' . \WIC\Core::c()->qs('address') . "\n";
	$body .= 'Suburb: ' . \WIC\Core::c()->qs('suburb') . "\n";
	$body .= 'Postcode: ' . \WIC\Core::c()->qs('postcode') . "\n";
	$body .= 'Mobile: ' . \WIC\Core::c()->qs('mobile') . "\n";
	$body .= 'Home: ' . \WIC\Core::c()->qs('home') . "\n";
	$body .= 'Email: ' . \WIC\Core::c()->qs('email') . "\n";
	$body .= 'Keyboard Data Entry Operator: ' . \WIC\Core::c()->qs('data') . "\n";
	$body .= 'Clerical/Administrative: ' . \WIC\Core::c()->qs('administrative') . "\n";
	$body .= 'Additional Skills: ' . \WIC\Core::c()->qs('additional') . "\n";

	if (file_exists('/tmp/' . $_FILES['resume']['name'])) {
		unlink('/tmp/' . $_FILES['resume']['name']);
	}

	move_uploaded_file($_FILES['resume']['tmp_name'], '/tmp/' . $_FILES['resume']['name']);

	$message->setBody($body)->attach(Swift_Attachment::fromPath('/tmp/' . $_FILES['resume']['name']));
	$mailer->send($message);

This simply takes the form fields and dumps them to an email (not pretty I know), but then takes the uploaded file from /tmp/ and then attaches the file contents directly to the email and sends it :)

How to use a SqlDataReader within another SqlDataReader

MSSQL has a restriction on by default which prevents using another SqlDataReader within a SqlDataReader without modification of the Connection String.

For example, say you want to get Table A, then for each record in Table A you want all records linked to Table A in Table B, a pretty normal request, one would typically get each record from SqlDataReader 1, then make a request to another SqlDataReader 2 and grab the child data there.

Doing this off the bat will fail unless you add the following parameter to your Connection String:

SqlConnection con = new SqlConnection("Data Source=[server];Initial Catalog=[dbName];User Id=[user];Password=[pass];MultipleActiveResultSets=true;");

Notice the MultipleActiveResultSets=true; value at the end? Enable this and you’ll be able to create secondary SqlDataReaders within a parent :)

How to remove .svn folders in one hit

I frequently have junior staff members who give me “clean” copies of new projects and upon the initial commit to SVN we find that the commit dies horribly for one reason or another.

Typically the new project will need to be scoured, folder by folder, to rid us of .svn folders from other repo’s which usually is a massive pain in the ass.

So here’s a command (to be used sparingly) “for NEW projects only“, that will wipe your entire project folder clean of all .svn (well, you can change the .svn to anything else such as “_notes”, etc.) in one fell swoop.

find . -name '.svn' | xargs rm -fr

Like I said, this is for new projects only as existing projects with VALID .svn folders will also be destroyed (FUBAR) by it.

SVN and svn:ignore

Just recently we had a dev in my team restore a customers’ site from our backup repo which had images that our customer had since modified and so, our restore process overwrote those images the customer modified. Not a very happy customer ;)

In order to avoid this we simply needed to ignore the folder where our system uploads customer images to, since this folder truly is of no concern to our source management and typically binaries shouldn’t be committed unless they are to be versioned!

Enter SVN:IGNORE

I instructed the dev to add the svn:ignore property to the upload directory but the files still continued to be added to the repo.

svn propset svn:ignore uploads .

Explanation of this command

In order to understand WHAT the dev executed I had to explain what this command was doing. First, svn propset asks SVN to set a property for a working copy.

Second, the property being set is svn:ignore. The value of WHAT is being ignored is “uploads” (ie. we want to ignore the uploads directory).

Lastly, “where” does this directory exist? Well that’s what the period (.) at the end says (ie. it’s the uploads directory in the CURRENT path).

SVN ADD still adds the ignored directory

The dev then issues a standard add command and presto, the uploads directory is added, regardless of the svn:ignore. WTF?!

It turns out that the command being used to add included an asterisk (*) which, on the command line, expands all the entities within the directory, including the uploads directory which we wanted ignored.

Invalid SVN ADD command

svn add --force *

Correct SVN ADD command

svn add --force .

After executing the correct svn add command ALL the folders (and other entities) that need to ignored are correctly ignored :)

.htaccess catch all for mod_rewrite

One of the most pain in the ass things I’ve come across in the past is that URL rewriting is almost always conditional, and configuring the .htaccess file to allow for this is incredibly annoying to remember.

Scenario

I have a web app that needs to use pretty URL’s to index better. My primary app structure is as follows:

  1. Have general access to all files within the filesystem if they are accessed directly
  2. Have a pseudo entry point to allow routing through a centralised script to handle web app routing
  3. Have any other pseudo entry point available IF we need to expose an entry point for something OTHER than routing

Entry Points

My base URL will be http://example.com/. From here I would usually like a routing entry point called /admin which will handle all web app traffic. I would also like to have any other entry point that I so desire respond as well (eg. /someOtherEntryPoint)

.htaccess file

The best way I can describe the system is through the .htaccess file below:

RewriteEngine on
RewriteCond %{REQUEST_URI} admin
RewriteRule ^(.*?)$ php/index.php?$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*?)$ php/cms.php?$1 [QSA,L]

The first RewriteRule is responsible for handling any direct URI’s that might need to bypass the rules completely.

The first RewriteCond checks whether my webapp entry point has been encountered (ie. /admin) and routes the data to php/index.php?$1 which acts as my router for the webapp.

The second RewriteCond finally checks whether the requested file is actually a physical file. If it isn’t then it routes the traffic to php/cms.php?$1 which acts as my “catch all” for any entry point that I so desire (also, if crap is sent to my site I can handle it gracefully).

Lastly, if the requested file IS actually a file, it slips through all the rules without rewriting the URL and actually accesses the file.

iPhone 5 – The hype (or lack thereof) and its reception

Lackluster Reception

Well the iPhone 5 has been released to the world and the amount of flack the phone has copped in the last 24 hours is beyond incredible! The last release was surrounded with so many people desperately trying to get theirs first whereas the iPhone 5′s release paled in comparison.

Apple as a company has
been acting like a bully

Apple as a company has been acting like a bully company of late and the animosity generated from this type of behaviour has more than likely attributed to the lackluster reception.

We expected Android fans to hit the iPhone 5 hard, but after recent events it seems that everyone from every other camp has joined forces and is laying it on exceptionally thick!

Apple bullying the little guy

Just when you thought that Apple couldn’t go any sink any lower we find out that the billion dollar company has decided to come down like a tonne of bricks on an Online Grocery Store in Poland because of their domain name!

The polish grocery store registered a.pl and according to Apple, apparently Apple customers might get confused IF a.pl comes up in a Google search for “Apple”.

that Apple honestly does
not believe that its customers
are smart enough

First I find this incredibly degrading (for Apple customers) in that Apple honestly does not believe that its customers are smart enough to know one search result from another, otherwise, why would they pursue such a lawsuit!

Secondly, what does Apple think will happen when their lawsuit wins (due to the almost unlimited resources Apple has at their disposal as opposed to the “lesser” resources that Delikatesy Internetowe have at their disposal)? How does that effect Apples’ image? Going after anyone and anything?

Lack of Geek Support

Whenever a new tech device comes on the market we expect a certain level of support from the Geek Community, but when you fail to conjure enough Geek support as well as have the general public question your capacity to innovate you’re already spiraling towards the event horizon of the public relations nightmare black hole!

According to this article, “is this really the best we can expect from an outfit that claims to be the most innovative company in the world? This is the sixth version of the iPhone, and the user interface still looks almost exactly like the original iPhone in 2007.

Looking towards the mobile market in general we have, “No wonder the Android platform, where new models appear every week, now represents 68% of the smartphone market, up from 47% a year ago, while Apple slid to 17% over the same period.

chief executive Tim Cook,
whose claim to fame involves
running an efficient supply chain

What’s more is the lack of confidence in Apple’s new leader, “A company that once was run by a product visionary now is run by a number-cruncher – chief executive Tim Cook, whose claim to fame involves running an efficient supply chain and beating ever lower prices out of Asian subcontractors and component suppliers.

Customers Respond to the new iPhone 5

When Jimmy Kimmel played this practical joke on the general public it was a clear indicator that not only is the phone completely indistinguishable from iPhone 4S but more importantly customers wouldn’t notice the difference if they were to purchase one or not as the experience would be more or less identical to the iPhone 4S. Does that warrant forking out for a device that is almost identical to it’s predecessor?

A word from the Apple camp

Though my article thus far has been extremely negative against Apple and the iPhone 5 it’s vital that we consider both sides of the coin and hear from an Apple supporter as to how he feels Apple is still pushing the envelope.

In the following article, “Apple isn’t a company that flails around for new ideas and rushes them to market. It conceives products before the technology exists to make them. Then it refines them for as long as it takes to get them right.

I feel this is just a cop-out
in that he’s claiming that
the only reason there are
only a few improvements
on the iPhone 5 is due to
the fact that it takes so
long to actually make
those improvements

This suggests that Apple have already thought of the next big thing but aren’t rushing it to market because they feel it’s not perfect! Unfortunately I feel this is just a cop-out in that he’s claiming that the only reason there are only a few improvements on the iPhone 5 is due to the fact that it takes so long to actually make those improvements.

He also mentions, “The “upgraded guts” of the iPhone 4S included a CPU chip twice as fast as its predecessor, powered by a battery redesigned to keep it going for the same amount of time per charge, shoehorned into a case that was still the world’s slimmest, since no other smartphone maker had been able to match it.

Again these improvements are hardly revolutionary. Every mobile hardware manufacturer is looking to do the same and will most likely succeed soon. This argument he makes is like saying the iPhone 2 was such a revolutionary step forward, but compared to the iPhone 3G it makes the iPhone 2′s hardware look pathetic. All improvements on hardware will make its predecessors look the same so I hardly think that CPU speed and improved battery design is enough without significant UI upgrades or other features that are different enough.

The article also makes the argument of, “By moving to a larger screen, reckons Lyons, Apple is merely being a “copycat”, since makers of rival devices based on the Android platform have already moved to larger screens. But those makers – including Samsung, the copycat that faces paying Apple $1.05bn (£665m) in patent damages – have given app developers a nightmare by proliferating the number of screen shapes and sizes they have to support.

But this is the same thing Apple has just done, increased the screen size and changed the screen shape, something iOS developers are also going to have to contend with.

I don’t feel that any of this articles points do anything other than compound the problem in that the Apple community in general just can’t see the forest through the trees. I also feel that the comments on his article speak to the man in that they have completely picked the article to pieces (as I expect this one to be :))

Conclusion

The barrage of ridicule, the constant jokes and digs at the device itself, and the hole Apple continues to dig itself by suing anyone or anything that is different will end exactly where it is meant to end, a company who’s products are boring, lack the ability to compete with their most basic competitors and in the end, will replace Microsoft as the “evil” company.

If you are looking to waste a couple hundred bucks on an iPhone 5, my recommendation is to check out ANY Android device before you do. Compare the features and performance of the devices and then decide whether you want to support a company who would sue you just for looking at it wrong or a community supported device that is better in every sense of the word!

Quick MySQL Executor

For a while now I’ve been wanting to access MySQL quickly through a web ui when I haven’t had direct access to the CLI/Workbench/phpMyAdmin and so I finally wrote something that my fellow coders have found useful and have decided to share it with the world.

Please note: This is a TOOL that you should use then remove from the site. This script CAN be used to compromise your MySQL/Web server if found by hackers. Remove this (or secure it properly) after you’ve finished with it (just like a normal tool, put it away in your toolbox when you’re finished with it!)

Download the script here. (WP won’t allow ZIP uploads so download the “PNG” and rename it to “ZIP”).

Please comment on the script/suggest improvements as you see fit and we will built an awesome version for everyone to share!

Gmail – Too Many Redirects On Login

Gmail will sometimes bail on me with a “Too Many Redirects” HTTP message (actually it’s doing exactly what it’s supposed to under those circumstances) and for the life of me I couldn’t figure out why.

It seems that a dud cookie between accounts.google.com and mail.google.com exists which cause the app to attempt to redirect to each other in order for one of them to figure out what to do but since neither know what’s going on it just loops infinitely until the browser gives up (which it does correctly).

Simply open your cookies and delete anything from .google.com (yeah I know it’ll stuff up any other Google things you might be using but it’s not going to take long before they’re back) and the problem should be resolved!

Web: The end is nigh

A little hypocritical sending you this message via the medium through which the claim is stated but hey!

Here is a warning, to all in the IT industry that is a very big cause for alarm.

Those that do not heed it may end up falling behind like the monolithic companies of yole!