Archive for the ‘Technical Articles’ Category

Music: Own vs. Stream

Monday, August 22nd, 2011

To begin, I’m someone who loves music.  And while there are some bands I can never grow tired of, I really like discovering new music and keeping up with the latest trends in a variety of genres.  I have a vast catalog of music on my computer(s) that amounts to around 11,000 songs.  30+ days according to iTunes.  I have been wrestling with the idea of music ownership for a while now and thought I would write up a post discussing the direction of music to streaming services, possibly moving away from owning a copy on ones hard drive.

There isn’t any doubt that with the dawn of Spotify in the U.S. and the appearance of Rdio in the last year that the trend is moving toward streaming.  My biggest hurdle… does subscribing to one of these services make my music collection amounting to thousands of dollars worth pretty much nothing?  That’s a tough pill to swallow.  But I’m not sure I have a choice. On average I would say I buy 3 or 4 albums a month.  I usually try and wait for good deals on Amazon, but don’t always.  So let’s say I spend roughly $25 / month on music.  This typically satisfies my craving for new music, but not always.  And I rarely buy just one song which means I rarely own the latest pop hit.  So where am I going with this?  The typical all access streaming service costs about $10 / month, and gives you access to just about everything, even the guilty pleasures you wouldn’t dare spend your hard earned money on.  Seems as though moving to a service like this is a no brainer.

A common question when it comes to streaming music is access.  Meaning will I be able to play my music wherever I am, even if there is no internet access.  The simple answer is yes.  These streaming services have a number of pricing tiers, and while about $5 / month gets you unlimited streaming, $10 / month provides you with the ability to download music and play when your offline (using approved applications and devices).  So if you own a smart phone you are good to go as that will usually allow you to play on most modern music playing devices.

So what are the down sides?  There are a few.  If your someone who still has a 5 disc carousel in the living room, and relies on the CD player in the car you pretty much out of luck.  You can’t burn any of this music to a disc, at least not legally.  Another down side is the player.  I personally like iTunes as a media player, and there are other good ones out there as well.  With these services you typically won’t be able to use this familiar software, which means the software provided needs to be really good since it will be all you can use.  If you regularly use AirPlay as a means of broadcasting audio, not having iTunes is a real problem.  There are alternatives though.  You can purchase for about $25 an application called AirFoil.    This does a really slick job of replacing the AirPlay feature within iTunes, as a matter of fact I think it may be better.  So there is a little start up cost but this makes up for the money you’ll likely save not buying albums.

Music as a service likely won’t interest someone who is content listening to their existing collection and seldom buys new music.  So going this route isn’t for everyone, and I don’t think buying music outright will go away any time soon. An audiophile may not be interested in this approach either as the music is typically 128 and up bitrate quality.  It isn’t loss-less, though technically neither are compact discs.  Still, shrinking 800 Mb down to 80 is going to sacrifice some music quality.  While I can tell a difference it isn’t too big of an issue.  Plus a keen ear will only be able to hear a difference on really high end speakers.  Probably 95+% of listeners have average speakers or headphones, so this won’t matter.  Additionally I expect the quality of these services to only increase as time goes on.

Listeners with a unique taste in music not found in most stores will still have options if they can’t find their interests online.  Services like Spotify take your existing purchased library and integrates the music into the provided player.  This is a nice feature, though not all services do this.

I expect there to be a lot of development in this area of technology in the upcoming year.  There are small inconveniences with the various services that will hopefully be worked out.  As of writing this article only Rdio has an iPad app, and devices like Apple TV do not natively support browsing and playing these collections.  You do have the option of Air Play as I mentioned previously which is a big help for those with an iPad, Laptop, and in some cases a smart phone. Apple has iCloud coming out around the corner.  This makes use of your purchased music, and Apple has a lot of interest in selling albums via iTunes at fairly high rates, so I don’t know how much cooperation there will be from them.  But they have surprised me before.

Lastly, I’ll briefly touch on the music industry.  These kind of services will certainly cut down on pirated music which is a big plus.  Though the amount the artists are receiving is drastically smaller.  A while back I saw this info graphic which pretty much says it all. Bands trying to make it will need a fair amount of plays to be able to support themselves.  Though, I will say that in general I am a fan of the free market when it comes to these kind of things and I think the best bands will prevail.  It just means that some people who may have been able to get by before may have to get real jobs that the rest of us.

I have personally tried a few of these services.  I will be comparing a few of these services in an upcoming post.

 

Redirecting for a mobile site

Saturday, August 20th, 2011

An extremely common requirement for a website is to redirect to an alternative site or page when visiting on a mobile application.  So how does one quickly implement a proven solution without reinventing the wheel and wondering if it even does everything it is supposed to?  I recently decided the last time I needed to implement this feature that I would make a simple portable solution available here for others to use.

What I came up with is a simple php class that will handle everything.  You just need to include some code referencing this class on your index page as well as the main page of your mobile site.  Here is an example index page…

<?php
include_once('mobile_redirect.class.php');
$redirect = new mobile_redirect();
$redirect->homepage = 'index.php';
$redirect->mobile_redirect = 'mobile.php';
$redirect->detect();
?>
<h1>INDEX page</h1>
<?php
print 'device: '.$redirect->device;
if ($redirect->device != 'normal') {
print '<br /><a href="mobile.php?mobi=1">View Mobile Site</a>';
}
?>

If you want to force the user into mobile mode you can pass the mobi querystring parameter. The same can be done to force the user back into regular mode (or disable the mobile version) by using the nomobi parameter. Once a page has been initialized with one version or another it will stay that way until it is forced back into another mode.

<?php
include_once('mobile_redirect.class.php');
$redirect = new mobile_redirect();
$redirect->homepage = 'index.php';
$redirect->mobile_redirect = 'mobile.php';
$redirect->detect();
?>
<h1>MOBILE page</h1>
<?php
print 'device: '.$redirect->device;
print '<br /><a href="mobile.php?nomobi=1">Disable Mobile Site</a>';
?>

You can find the code here on GitHub: https://github.com/mbopp/PHP-Mobile-Redirect The only file you are required to use is the .class.php file.

Let me know if you see ways to improve this.

Reference Application Data files when creating a Titanium Desktop Application

Wednesday, April 6th, 2011

As part of a recent project we were tasked with creating a desktop application in addition to an iPad application.  As we have in the past we used Appcelerator Titanium as the platform for building these applications.  A project with a lot of potential, but it currently has very poor documentation. In short Titanium allows the development of iOS and desktop application with the use of HTML and Javascript.

A mac or iOS application has a Application Data directory stored (in the Library directory on a mac).  This is really the only place one has the ability to write files within the application being developed.  However, when developing a page in javascript (and generated HTML) there isn’t a documented way to reference one of these files.  This is a problem for anyone who wants to update their application via the web.

After digging in the Titanium Desktop SDK we located the solution.  The location (src attribute for an image) needs to be prefixed with file:///. This is similar to using the app:// prefix which refers to the location of the application resources itself.

So for an example, an image tag would look like the following…


<img src="file:///Users/me/Library/Application%20Support/Titanium/appdata/com.company.project.desktop/image.jpg" title="test image" />

There may be other undocumented prefixes as well, but this get’s us where we need to be.  If anyone else has any similar undocumented hints leave a comment.

Adding “hidden” checkbox to node menu edit fieldgroup

Tuesday, January 4th, 2011

Quick tip on showing the one menu field not displayed in the node edit form.  If you want to display a field for hiding a menu item for a particular node you need to create a form_alter hook.  In this hook you simply create a field named “hidden” using the standard form api underneath the “menu” fieldgroup.

And that’s it.  No submit handler needs to be added or changed.  The existing submit handler already handles saving the hidden field if it is available.

/**
* Implementation of hook_form_alter
*/
function custom_menu_form_alter(&$form, &$form_state, $form_id) {
 if (isset($form['#node']) && $form['#node->type .'_node_form' == $form_id) {

 $item = $form['#node']->menu;
 $form['menu']['hidden'] = array(
 '#type' => 'checkbox',
 '#title' => t('Hidden'),
 '#default_value' => $item['hidden'],
 '#description' => t('Menu items that are hidden will not be listed in any menu.'),
 );
 }  
}

IE7 HREF Normalization and AJAX

Wednesday, August 18th, 2010

I have often relied on jQuery’s awesome cross-browser compatibility tricks. One of these is fixing an inconsistency with how link HREFs are reported in IE compared to other browsers. In most browsers, when asking for the HREF of a link, JavaScript sees what is actually in the document source. In IE, however, the HREF attribute is “normalized” into a fully-qualified URL. This can be a problem.

Generally, jQuery fixes this for you when you use the .attr() method to retrieve the “href” attribute. The returned value is whatever is in the source code, not the normalized URL, regardless of browser. Success!

Unfortunately, I discovered today that is not always the case. In this specific scenario the normalization still happens:

  1. Open IE7.
  2. Use AJAX to load some content into the page that contains links.
  3. Examine the link HREF using .attr(‘href’).
  4. See that the result is a normalized URL. Oops.

I haven’t yet performed reductions to see if the problem is the AJAX load or the DOM insertion, but it only affects IE7, not IE8. At this point, my workaround is to do the regexes manually to extract the part of the HREF I want, rather than relying on jQuery. Clumsy, but it works!

HTACCESS Fundamentals

Monday, January 25th, 2010

Apache HTACCESS files are an integral part of developing websites on the Apache web server.  In a nutshell .htaccess files are extensions of the Apache server configuration file.  They allow you to set up specific configuration for a site or even a particular directory.  It is always best to use Apaches’ server configuration file when you are able, the performance of the site is much better.  But often because multiple sites are running on one instance of Apache these specific configuration files are needed in order to apply functionality to a site that doesn’t negatively impact other sites.

Most of us host sites in a “Shared” hosting environment where modifying the apache configuration or php.ini simply isn’t an option, this is where HTACCESS files saves the day.  I’ll hit on some of the commonly used features / configurations here.

Allow Override (permitting the use of .htaccess files)

When on shared hosting I usually assume I’ll be able to use the basic functionality of an htaccess file.  But what you can do varies, and you may or may not be able to tell for sure what your able to override since this requires looking at the Apache config file.

Apache config files contain “Directory” sections defined like <directory “/test/site”></directory>.  By default, overriding the configuration is allowed however this can be specified using the “AllowOverride” property.  The typical values for this are either “All” or “None”.

In general I would assume you can set set server properties in the HTACCESS file.  But if things aren’t working as you would expect then this may be the reason.

http://httpd.apache.org/docs/2.0/mod/core.html#allowoverride

Password Protection

Probably the single most used feature of the HTACCESS file.  To use this feature you need to first set up a HTPASSWD file, which is easy, but does require the command line.  This file will store your user name and corresponding passwords.  There are lots of ways to set up .htpasswd files, I’ll show you some of the basics using a utility called “htpasswd”. To create a new htpasswd file type the following.

htpasswd -c /file/location/.htpasswd mbopp

You will then be prompted for a password.  Once entered, assuming you have the correct write permissions to the directory your file should be created and ready to go.  The “-c” option specifies that you want to create a new file.  If you want to modify an existing users password you can do the same without the -c option… like…

htpasswd /file/location/.htpasswd mbopp password

Or omit the password and be prompted as you were with the previous command.

http://httpd.apache.org/docs/2.0/programs/htpasswd.html

Once you have your .htpasswd file set up you need to reference it in your htaccess file in order for it to be recognized and used on your website.  You can either put password directives in a “directory” tag or simply by itself in the .htaccess file, which will apply it to the current directory.  Here is an example.

AuthType Basic
AuthName "Password Required"
AuthUserFile /file/location/.htpasswd

Allow override will need to be set in to at least “AllowOverride AuthConfig” if it isn’t already set to “All” in order for directive to be recognized.

You can also set up groups of users with different access privileges.  More can be found out at http://httpd.apache.org/docs/2.0/mod/mod_auth.html.

Mod ReWrite

Another feature I find myself using quite a bit is the mod rewrite module.  This gives you the ability to have “Clean URLs”.  Meaning that your URLs will not have file extensions like .htm, .php, .py, etc. It’s good practice to wrap your mod rewrite properties in a conditional xml tag.  “<IfModule mod_rewrite.c></IfModule>” .   The following is a simple example which sends a user to /e/www/ when visiting “/”.


RewriteEngine on
RewriteRule   ^/$  /e/www/  [R]

Most CMS solutions already have this htaccess configuration done for you.  The following is an example from a Drupal CMS .htaccess file.  This looks at the parameters in the url querystring and rewrites them to look like a directory structure.


RewriteEngine on

RewriteBase /

# Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

http://httpd.apache.org/docs/2.0/misc/rewriteguide.html

PHP Settings

Lastly, the other thing I find myself doing often is setting various PHP settings.  Every instance of PHP has an ini file somewhere in the path.  But if settings need to be changed on a site by site basis it’s quick and simple to just do this within the htaccess file.

Here’s a common scenario, you have a website that is returning a blank page.  This is likely a php error and your site is probably set up to hide these errors by default.  So in order to see the actual error you need to add the following to the .htaccess file.

php_flag display_errors off

There are a ton of PHP settings, should you run across one that you need to change, explore the ability to override and set it in the HTACCESS file.

http://php.net/manual/en/configuration.changes.php

Other Resources

ASMX will not be served by the static file handler resolution

Thursday, November 12th, 2009

Getting a 403 error “The requested content appears to be script and will not be served by the static file handler” when trying to access a ASMX .NET service location.

It took me a while to figure this one out, but here is the solution… (more…)

Sql Server Compact Edition and Datasets Rant

Monday, November 2nd, 2009

Sql Server Compact Edition seems to be the red headed step child of Microsoft’s line of Databases.  It doesn’t get much attention, not even from the tools that are supposed to support it.  Visual Studio gets confused easily when dealing with these databases.  And there are number of bugs if your unfortunate enough to have the need to use Typed Data sets with ADO.NET.  That being said, this database version really has it’s place, and can be a real asset in the development of client applications.  It sure beats storing your data in a XML file, or relying on the bloat and sheer size of Sql Server Express (or any other version).

(more…)

Sql CE Query Tool

Monday, November 2nd, 2009

What I meant to write when doing this

I stumble on this tool today that is top notch.  A tool called CE Query that can be found on CodeProject’s website here.  As I mentioned in that other post, there isn’t much help when it comes to working with SSCE.  The standard development tools MS provides seem to steer clear of this version of Sql Server.  What you get with this tool is what you would expect to get with Sql Server Management Studio.  Some of the features…

  • Script Generation, (handy for generating a database with code)
  • Ad-hoc querying of all kinds
  • CE database creation

And some of my favorite feature(s)…

  • Creating a SSCE database based on a Sql Server database.
  • Migrating data from Sql Server to SSCE.
  • Or flat out taking a sql server database to turning it into a SSCE file (*.SDF)

CE Query is by no means a refined mature program.  But it does surprisingly well.  Who am I kidding… its awesome!

You have the option of downloading the source or executable.  You can try the executable first, but you’ll most likely need to download the source and build the file yourself if your running on a 64bit Operating System because of the SSCE libraries referenced.

Check it out! http://www.codeproject.com/KB/database/CEQuery.aspx

How do you use IIS 7 for local development?

Friday, October 30th, 2009

Okay, so I’m new to IIS 7.  I just installed Win 7 and of course now presented with a new version of IIS.  It seems there are a variety of ways to go about developing ASP.NET Web Applications and testing using the local IIS instance.  It seems most developers agree that creating websites as “Applications” rather than as plain websites.  So how do you set up you local environment for a ASP.NET project? (more…)