About Tinsley

See the about page

Amazon Tools 1.4

Version 1.4 of Amazon Tools has been released.
You can download the free version from wordpress.org or get the premium version Here.

This version includes more changes and additions than any update so far. Here are some of the highlights:

  • Added the ‘post’ amazon shortcode attribute which can be used to retrieve post data.
    Ex: [ amazon post="permalink"]
  • A major overhaul of the random, similar, and foreach shortcode attributes which will allow you to use the random attribute in conjunction with the similar or foreach attribute. For example, if you wanted to select 3 similar products at random you could use the following shortcode: [amazon similar="3" random="" template="My Template"]
  • A new feature called ‘Quick Search’ adds a meta box to the post editing page that will allow you to look up products as you write. You can see this new feature in the screenshot below.

Continue reading

Google is translating my code!

Recently I added the ‘Google Translate’ widget to my sidebar. After some testing I noticed something problematic: All of the code snippets in my posts were also being translated. Unfortunately the PHP interpreter does not speak Spanish (it’s not that kind of interpreter apparently). Fortunately there is a simple solution. The content of any HTML element with the class ‘notranslate’ will not be translated; all you have to do is add the class ‘notranslate’ to the element containing your code.

If you’re using a plugin to format and display your code this may not be so simple. Currently I’m using SyntaxHighlighter Evolved which has a convenient field in the settings page for adding addition classes to the ‘pre’ element used to display code. If this isn’t the case for you you’ll have to do some digging in the plugin code. Alternatively you could use javascript to add the class to a particular element. This way you won’t have to make any modifications to core plugin files, which will be overwritten if you decide to update.

Here is a 100% untested example (using jQuery):

$("pre").addClass("notranslate");

The above code should prevent any content within a ‘pre’ element from being translated by Google.

PHP json_encode and json_decode Alternatives

The number of APIs and other remote services that either support or require json as a means for transferring data is growing. However, PHP does not have guaranteed support for json encoding or decoding functions until version 5.2, which means if you want your application to be as portable as possible you’ll need to find an alternative. The following functions should provide that. Note that I haven’t exhaustively tested either of these functions and they may not completely replicate all of the functionality of their built in counterparts, but they should be sufficient for basic usage:
Continue reading

NoSQL

Recently I’ve been working with a non-relational, graph DBMS called Neo4j. I’ve really only scratched the surface and it might just be a the temporary euphoria of working with something so new, but it feels liberating to be able to approach problems in a new way. It might also be that for the first time in a long time I’m working in Java. At this point I’ve written far more PHP code than Java, but I still feel like Java is my native language.

I think anyone who works with database driven applications should at least try some form of non-relational database, if only just to see things from another perspective.

Is SHA1 Still Viable?

Lately whenever I see discussion regarding SHA1 in the context of password hashing or user management it usually involves someone claiming that SHA1 has been ‘cracked’ or is otherwise not viable as a hashing algorithm. I think there is some degree of truth to these claims. In spite of this however, I think that many of these conclusions are based on a misinterpretation of the evidence.

Before I explain myself I want to say this: If you are reading this article because you intend to implement something that require a secure hashing algorithm stop thinking about SHA1. There are a lot of more collision resistant algorithms for you to chose from. You might be thinking that this fact defeats the purpose of discussing the viability of SHA1, but considering all of the existing system that rely on SHA1 I think the discussion is valid. Here we go:
Continue reading

Fetching Remote Content in PHP

Reading in remote content with PHP can be an incredibly simple task:

$url = 'http://example.com/foo.php?bar=1';
$remote_content = file_get_contents($url);

One problem with the above solution is that it requires allow_url_fopen to be enabled in your php.ini. If you’re writing a portable application that depends on being able to fetch remote content you probably don’t want to tell your users to modify their php.ini. Doing so would mean turning away users who don’t have access to their php.ini (as is the case with some shared hosts). Ideally you would want a solution that offers some redundancy.
Continue reading

Representing Time

1999 AD:

Arrrg! Why did those idiots use only two digits to represent the year?!

2037 AD:

Who's idea was it to store timestamps as 32-bit integers?!

292,277,026,595 AD:

What do you mean we're using signed integers to represent time?! Bring me the last man in the universe who knows C++.

I’ve been to the future and the only thing keeping the universe intact is a googol lines of cobol. The only person who knows how to maintain it rules the galaxy with an iron keyboard.

Managing URL Parameters in PHP

This is a function that I find myself using more and more often to create or modify URLs that contain a query string:

function build_query($params = array(), $keep_get = true, $unset = null)
{
	if($keep_get)
	{
		$params = array_merge($_GET, $params);
		if(is_array($unset))
		{
			foreach($unset as $key)
				unset($params[$key]);
		}
	}
	return http_build_query($params);
}

Continue reading

Opera 11 Beta

Opera 11 Beta is out ( http://www.opera.com/browser/next/ ).

There are a lot of new features and improvements, but one in particular has blown my mind. Tabs are now stackable! Within minutes I became so dependent upon this feature that I’ve migrated completely to the new version in spite of it still being in beta.

In addition to this Opera now supports extensions. Technically Opera has supported extensions for a long time through userJS, but the new system seems to be a big improvement. I’m definitely considering creating a Tab Override extension for Opera.