Tuesday, 29 January 2013

How do I solve following HTML5 video error: HTTP "Content-Type" of "text/plain" is not supported

Problem:

When trying to play a video using the HTML5 tag in a web page being programmed, the video plays fine when running the file locally in Firefox. However, when running the web page using Apache, an error like the following comes up in the console:

HTTP "Content-Type" of "text/plain" is not supported. Load of media resource http://127.0.0.1/path/to/video.webm failed.

The videos are encoded properly, so they are not the issue.

Solution:

This error is happening as Apache isn't reporting the MIME type of the video files correctly. To solve this, add the following lines to the relevant .htaccess file that covers (at the very least) the folders of the videos that will be played:

AddType video/webm .webm
AddType video/ogg .ogv
AddType video/mp4 .mp4

Notes:

Alternatively, the proper MIME types can be placed into the appropriate configuration file for Apache. This solution is particularly relevant if your web server is set up to ignore .htaccess files.

Monday, 28 January 2013

Change Data Usage Cycle in Android 4.1.1

Problem:

How do I change the data usage cycle in Android 4.1.1? The option to change won't show.

Solution:

The first screenshot below illustrates the problem: it seems as though the option to change the billing cycle does not exist! Notice that mobile data is turned off at this point.

Turning on mobile data at first doesn't seem to fix the problem as seen in the screenshot below. The option to change billing cycles is still not there.

To work around this issue, try the following: exit the preferences to the home screen, and open the data usage preferences again. You should be able to see the option to change the billing cycle now.

Notes:

This seems to be a strange, intermittent problem with the interface. This solution was tested using Android 4.1.1 on a Galaxy Nexus. Your results may vary with other setups.

What's the font in the Google logo?

Question:

What's the name of the font used in the Google logo?

Answer:

The font is named "Catull". Find out more in the Wikipedia article for Catull here.

Use several wireless routers with only one DHCP server for a home network

Problem:

How do I connect more than one (D-Link) wireless router to make a single home network with only one router acting as a DHCP server?

(In other words, how do I make the other wireless routers in my home network act only as access points?)

Solution:

  • plug only one router into internet using the router's uplink/WAN port. This will be the primary wireless router and act as the network's gateway to the internet. This should preferably have a firewall and be the fastest router as all traffic from the network will be funnelled through it. This router should have several ethernet ports available to plug the other routers into it.
  • turn on the DHCP server in this router, and set the range to something that does not encompass the entire IP range (e.g. 192.168.0.100-192.168.0.255)
  • set the primary router's IP address to something outside of the DHCP server's range (like 192.168.0.1) -- this is to allow access to the web admin/setup application of the primary wireless router
  • plug the second (third, etc.) router into the primary router using one of the ethernet ports of both the primary and secondary (tertiary, etc.) wireless routers -- in other words, leave the WAN/uplink port of the secondary router empty
  • turn the DHCP server of all secondary wireless routers off
  • match the subnet of all secondary wireless routers to the subnet of the primary router (e.g. 255.255.255.0)
  • set the IP address of the secondary routers to something outside of the DHCP server's range (such as 192.168.0.2, etc.) -- this is to allow access to the admin/setup web applications of the secondary routers
  • (optional, but useful) set the SSIDs and authentication methods (like WPA2-only PSK) of all the wireless routers to the same as one another
  • (also optional) make sure the channels of the wireless routers are spread out as much as possible to minimize interference between them

Notes:

This has been tested with only D-Link routers, but should work for others, too. Again, while it's one of many solutions, it should be good enough for most home situations. The benefit of setting up the network this way (if necessary due to the nature of the location the wireless network is being set up, budget, etc.) is that all clients in the home's LAN should be able to communicate to one another if desired. (This can be useful for running local services, running a home file server, accessing networked printers, etc.)

As with any network, make sure that all machines connected to it are trusted and precautions have been taken to mitigate intrusions, viruses, anonymous logins, etc. This is beyond the scope of this reminder how-to, however a quick Google search should help with finding more information on this.

Reference:

The following reference probably explains this procedure better than this blog post. The blog post was written as a reminder to myself, in case the reference ever goes down. Hopefully this comes in handy for someone out there :)

Tuesday, 22 January 2013

Some useful postfix commands

Intro

This is a partial list of useful commands related to postfix/sendmail for my own reference. It's posted here in case anyone else finds this useful, too.

Commands

  • List stuff in the mail queue:
    mailq

  • Read a message in the mail queue with example id 012345678F:
    postcat -q 012345678F

  • Delete a message in the mail queue with example id 012345678F:
    postsuper -d 012345678F

  • Delete ALL messages in the mail queue (warning - no confirmation nor undo!):
    postsuper -d ALL

Wednesday, 2 January 2013

One workaround for Android not receiving MMS

Problem:

My Android (4.1) phone is often not receiving MMS messages in the Messaging app. It stays stuck on the "downloading" message. I have data turned on, so that's not the issue. I was also not roaming at the time. Sometimes Android would download the MMS messages, other times it would just remain on the MMS notification 'download'.

Workaround:

This workaround seemed to have success with my own device after several days of attempting other solutions (turning on/off background data, turning on/off wifi while 3G is turned on, etc.) Your mileage may vary, but hopefully it at least helps someone out there :)

  • in the Messaging app, go to the settings
  • scroll down to the "MULTIMEDIA (MMS) MESSAGES" section
  • uncheck "auto-retrieve"
  • when someone sends a MMS, click the "download" button that appears in place of the 'downloading ...' message
  • your message should now download, rather than forever remain on the "downloading..." message

Notes:

This was tested to work using Android 4.1.1 on a Samsung Galaxy Nexus while on the Fido network in Canada. Again, as many things can contribute to MMS messages not sending, your mileage may vary.

While this is not the ideal solution, most people will usually not be looking at a MMS message until they have the messaging app open in front of them, so hopefully this is an appropriate workaround for those who don't mind waiting a few seconds to manually download a MMS rather than have them automatically download.

By the way, if anyone at Google is reading this, hopefully this bug can be reproduced by your Android Messaging app team =) It's an intermittent bug and I have no idea how to reliably reproduce it, otherwise a bug report would have been filed by now! Have a great day!

Saturday, 22 December 2012

Install pattern files into GIMP 2.8 in OS X

Problem:

How do I install patterns into GIMP 2.8 in OS X?

Solution:

One way to do this is to copy the .pat files directly into the GIMP folder that contains all of the default GIMP pattern files. To find this folder, follow the steps below:

  • open your Applications folder
  • secondary-click GIMP, and select "Show Package Contents" from the context menu
  • navigate to: Contents/Resources/share/gimp/2.0/patterns

Now that you've found the patterns folder, copy all the GIMP-compatible pattern files into this folder. Restart GIMP. You should now be able to see the new patterns in the patterns dialogue/selector of GIMP.

Notes:

Note that the above method will make the patterns you install available for every user of your system. There are other methods available which should only install it to your own user, but they may not be so straightforward for the typical user since they involve creating/opening hidden folders.

If you'd like to find out the alternative locations where GIMP is looking for pattern files, just follow these instructions:

In the main menu, click on (in OS X) GIMP->preferences, (or sometimes in another OS, file->preferences). The preferences dialogue should appear. Then in the left-hand menu of the new dialogue, expand the icon/item labelled 'folders' and look for the item named 'patterns'. Once you click on this, you should be able to find all of the folders GIMP is looking for patterns in, as shown in the following screenshot.

Tuesday, 11 December 2012

Access images in Symfony 2.1 CSS stylesheets with Twig and Assetic

Problem:

How can I access images from my Symfony 2.1 project's CSS stylesheets?

Solution -- intro:

The example in this blog post is only part of the picture and is meant to get the typical project started for the beginner. Please note that it's far from a complete explanation, but hopefully it'll be useful for some out there.

Accessing images in Symfony 2.1 stylesheets can be done by following a few steps. Before we list them out, let's establish some parameters for this blog post's example.

First, for illustration purposes, let's assume that your bundle is named DemoIllustrationBundle, its path is Demo/IllustrationBundle, and that your CSS and image files are located respectively in the following locations in src/Demo/IllustrationBundle/:

  • Resources/public/css
  • Resources/public/images

Let's also assume that our CSS file is named style.css, and that it needs to access the image 'repeat.png' to repeat as the background image.

In style.css, we'll access repeat.png via url('../images/repeat.png'), for example:

background-image: url('../images/repeat.png');

Now that we've established the parameters for this example, we can summarize the steps needed to be taken to properly access images in CSS styles:

  • whitelist the bundle in assetic
  • install web assets
  • use stylesheets tag in twig template with cssrewrite filter
  • compile assets for production (out of the scope of this blog post, but necessary to learn prior to switching to a production environment)

... whitelist bundle in assetic

This step allows you to use the stylesheets tag in your twig templates. You'll need this in order to use the rewrite filter to dynamically update the path of your images in the generated stylesheets of your app.

Open the file app/config.yml, it should have a section that looks like:

assetic:
  ...
  bundles:        []
  ...

Add your bundle to this whitelist. In the case of this blog post's example we'll add DemoIllustrationBundle:

bundles:        ['DemoIllustrationBundle']

Save this file and exit. Note that this assetic whitelist will now apply to all environments.

... install web assets

This step installs the images from your project's Resources/public folder to the web folder.

There are several ways to install assets. We'll be installing assets using the symlink method so we don't have to keep reinstalling them during development. In the command console / terminal, go to your project folder and use the command:

php app/console assets:install web --symlink

You should be able to access the CSS and image files in the web folder now. In the case of this example, they'd be located respectively in:

  • web/bundles/demoillustration/css
  • web/bundles/demoillustration/images

Note how these locations compare to your project's public folder.

... use the stylesheets tag with cssrewrite filter

When including the style.css file in this example, the twig template section should look like the following:

{% stylesheets 'bundles/demoillustration/css/style.css'
   filter="cssrewrite" %}
  <link href="{{ asset_url }}" rel="stylesheet" type="text/css" />
{% endstylesheets %}

This should rewrite the '../images/' in the stylesheet to the location of the installed images.

Debugging (incomplete):

There are a few things that can go wrong with the above example. This section will cover two of those bugs with potential approaches to debugging them.

Assetic not configured:

One error can be forgetting to whitelist your bundle. This is indicated by getting an exception such as the following:

An exception has been thrown during the compilation of a template ("You must add DemoIllustrationBundle to the assetic.bundle config to use the {% stylesheets %} tag in DemoIllustrationBundle::base.html.twig.") in "/path/to/Demo/IllustrationBundle/Resources/views/base.html.twig".

Images still aren't showing:

If the above steps were followed but images still aren't showing, there are a few things that should be looked at. We'll use the setup in the example of this blog post to illustrate a few steps that can be looked at when trying to debug this:

  • are there any typos?
  • are images located in the project's "Resources/public/images" folder?
  • does the CSS file look for images in "../images/"?
  • were web assets installed?

Unfortunately, since there is an exhaustive list of things that can potentially go wrong, you'll have to use your ingenuity or Google to search out any other scenarios besides the above ones if they don't seem to apply.

Further reading:

The example in this blog post is only part of the picture and is meant to get the typical project started for the beginner. There's a lot to learn, and several steps left to go in order to make your project suitable for production. The following links are either references that helped in figuring out the above steps in this post, in addition to other resources that may provide more useful information for either clarification or for how to proceed from where this post leaves off.

Thursday, 6 December 2012

Styling links and anchors with CSS by example

Problem:

How do I style anchors and links with CSS? Additionally, how do I override these styles?

Examples:

The examples below in this post will demonstrate how to use the most common pseudo-classes of website links: link, visited, hover, active.

Here's what the pseudo-classes mean:

SelectorInterpretation
:linkall unvisited links
:visitedall visited links
:activethe active link
:hoverthe link selected on mouseover

Link defaults (covers all links in the document):

:link { color:blue; text-decoration:underline; }
:visited { color:green; text-decoration:underline; }
:link:hover { color:blue; text-decoration:none; }
:link:active { color:blue; text-decoration:underline; }

Anchor defaults (covers all links embedded in anchors):

a:link { color:blue; text-decoration:underline; }
a:visited { color:green; text-decoration:underline; }
a:hover { color:blue; text-decoration:none; }
a:active { color:blue; text-decoration:underline; }

Override (covers all links embedded in anchors with the class 'overrideClass'):

a.overrideClass:link { color:red; text-decoration:none; }
a.overrideClass:visited { color:orange; text-decoration:none; }
a.overrideClass:hover { color:red; text-decoration:underline; }
a.overrideClass:active { color:red; text-decoration:underline; }

References:

Friday, 30 November 2012

Check if a javascript variable contains a function

Problem:

How do I check if a value stored in a javascript variable is a function?

Solution:

While there are many ways to do this, the following code should work:

function isFunction(toCheck){
  return toCheck != null 
      && {}.toString.call(toCheck) == '[object Function]';
}

Notes:

Note that the first conditional, toCheck != null, may not be necessary. However, if null or nothing is passed to the function the result could be undefined otherwise (this was encountered, at least, in some older (or buggy?) implementations of javascript but might be a non-issue today -- feel free to test it out).

An alternative (and closely-related) method of checking is to directly call Object.prototype.toString.call() instead of instantiating an anonymous object.

References: