Category Archives: Code Snippets

Here you will find various snippets and code examples that I have used to make some thing in my life a little easier to deal with.

MYSQL: Get Flag Emoji Unicode from ISO 3166-1 Alpha-2 Country Codes

Today I had to figure out the most efficient way to generate Emoji from ISO 3166-1 Alpha-2 country codes such as US, GB, etc. I opted to go for a for 100% SQL solution.

The most efficient way to convert each ASCII letter to their Unicode Regional Indicator Symbol Letter that I determined is provided below (simplified)… Continue reading MYSQL: Get Flag Emoji Unicode from ISO 3166-1 Alpha-2 Country Codes

Create a Windows Batch (.bat) File to Test Your Internet Connectivity

I have been having issues with my ISP‘s WiFi router, so I decided to create a batch file I could run as-needed to check internet connectivity.

@echo off
cls
set "router=192.168.0.1"
set /p "router=Enter router IP address or press [ENTER] for default [%router%]: "
@ping %router% -n 1 | FIND "Reply"
@ping google.com -n 1 | FIND "Reply"
@ping bing.com -n 1 | FIND "Reply"
echo Press any key to exit...
pause >nul

Save that as `ping.bat` and put in somewhere convenient. Then… Continue reading Create a Windows Batch (.bat) File to Test Your Internet Connectivity

SEO URLs for OpenCart Using a “web.config” File on Windows IIS Server

I always suggest Linux hosting for any OpenCart installations. The main OC developers either don’t know much about Windows IIS or neglect to include the necessary SEO URL configuration file for it to work.

This omission results in “not found” 404 (dead link) errors when you visit a page with an SEO URL assigned after enabling SEO URLs in your OpenCart store settings.
Continue reading SEO URLs for OpenCart Using a “web.config” File on Windows IIS Server

PHP Function to Sum or Concatenate Associative Array Values

Here is a quick function I created to merge multiple arrays and sum or concatenate the values thereof. If the values are numeric they will be added together (sum). Otherwise the values will be appended to each other (concatenation).

function arrayMergedSumConcat() {
	$out = array();

	$num_args = func_num_args();
	
	$arg_list = func_get_args();
	
	for ($i = 0; $i < $num_args; $i++) { $in = $arg_list[$i]; foreach ($in as $key => $value) {
			if (isset($out[$key])) {
				if (is_numeric($in[$key]) && is_numeric($out[$key])) {
					$out[$key] += $in[$key];
				} else {
					$out[$key] .= $in[$key];
				}
			} else {
				$out[$key] = $in[$key];
			}
		}
	}
	
	return $out;
}

Stop Annoying favicon.ico 404 errors

If you’re like me, you don’t like cluttering your main folder with unnecessary files. This is why I hate that some browsers are still looking for ‘favicon.ico’ in the main folder even when you indicate in <head> that’s not where the agent should be looking…

Here is a way to eliminate those PITA 404’s from your error logs… Continue reading Stop Annoying favicon.ico 404 errors

PHP: Check MySQL database to see if table, field, or value exists

This procedural function will tell you if the table you are looking for is found within your currently selected MySQL database. Optionally, it will also determine if a column exists within the specified table. You can even pass the a value as the optional third parameter to see if the field’s value is also what you expect. Continue reading PHP: Check MySQL database to see if table, field, or value exists

Quickly Hide Trending Tags and Topics from Facebook

Here is a bookmarklet you can use to quickly hide the “Trending” [Tags and Topics] panel from your Facebook wall…

javascript:document.getElementById('pagelet_trending_tags_and_topics').style.display='none';void(0);

That should work in nearly all modern browsers since it uses basic JavaScript that has worked for quite some time to apply element styles.

You may also be able to right-click the following link and save it as a bookmark 😉

FB: Hide Trending Tags/Topics

Automatically expand textarea to fit content using jQuery without autogrow or autosize plugins

I’m sure there is a more efficient way to do this, but it suited my needs.

<script>
$(function() {
    $('textarea').keyup(function(){
        $(this).each(function(index, element) {
            $(element).height(element.scrollHeight);
        });
    }).keyup(); //trigger event to initialize pre-filled textareas
});
</script>

Enjoy 🙂