AngularJS Scroll to Top for New Pages on Single-Page-App

20 Oct

As promised in my last post, I’m going to try to keep updating with things I learn on my trek down the long road to Angular-ville. As far as I could tell, there isn’t much info about the issue I was facing online, so either I’m doing something wrong (and if I am, for heaven’s sake, don’t just sit there; please tell me!) or there aren’t as many people concerned with what I felt was a noticeable UX flaw in single page apps (SPA). To try to make clear my explanation of the issue, I’ll just walk through some steps that an end-user might experience with an SPA and how the page responds by default:

  1. User loads the home page. Angular fetches the template and inserts it into the ng-view.
  2. User scrolls down the page a bit, say 600px.
  3. User clicks a link to another page. Angular fetches the requested page’s template and inserts it into the ng-view, but the browser stays scrolled 600px, so the user doesn’t actually see the content they loaded.
  4. User clicks the browser’s back button and sees again the content they were at before clicking the link.

Read the rest of this entry »


AngularJS Auto-Focus Input After Router Template is Loaded in SPA

14 Oct

It’s been just a little while (oh, only about 3.5 years) since I last published any new posts here. Too busy.

At the moment I’ve been delving head-first into some modern frameworks like¬†AngularJS and Bootstrap, so I plan to document things I learn along the way that I think will help other developers also new to these technologies who might come up against some of the same issues or who might just find interesting the things I’m discovering.

Without further ado, this is my first of such posts, which is a little more advanced than just starting to learn everything from scratch, but I do plan to back-track and cover more in future posts the basics of using AngularJS.

Read the rest of this entry »


Fixing the IE7 <Button> Submit Value

12 Mar

If you’ve ever used <BUTTON> tags in your HTML forms, you’ve probably noticed that there are a couple of problems with them in IE7 and older.

For starters, clicking a BUTTON does not cause its form to be submitted. This means that a user will never be able to submit the form by clicking it. Furthermore, if you are using JavaScript including jQuery to trigger a callback upon form submit, that callback will never be fired.

Read the rest of this entry »


Generate UUID in PHP

23 Feb

I posted this last year to and thought I’d just share it here as well. It’s a short write-up and demonstration of a PHP class you can use to generate various versions of a Universally-Unique Identifier, or UUID.

The php5-uuid functions could definitely use some documentation to clarify how they should be used, but here’s what I’ve gleaned by examining the OSSP source code (found here:

The uuid_make() function takes two arguments when generating v1 or v4, but four arguments are required when generating v3 or v5. The first two arguments have been thoroughly demonstrated and are straightforward, so I’ll skip to the as-yet non-described arguments.

Read the rest of this entry »


Posted in PHP


Text Beautify WordPress Plugin

09 Feb

I’ve just submitted my first ever plugin to the WordPress repository. It’s called Text Beautify and can be found at the following URL:

The purpose of the plugin is to beautify post titles, post contents, and comments of your WordPress blog. In post contents and comments, the text is made sentence case. In post titles, it is made title case, so all words are capitalized except for a user-defined list of exceptions, such as: of, an, the, etc. It is really targeted at persons with a refined sense of text aesthetics and people who just want their content to look nicer.

Read the rest of this entry »


PHP Human File Size Function

19 Nov

Just found myself needing to display bytes in a human readable format. There are countless examples that use a lot of complex techniques to achieve this, but I wanted a simpler solution. This is the method that came to mind. Rather than basing my algorithm on the numeric value, it is based on the length of the bytes.

Read the rest of this entry »

1 Comment

Posted in PHP


PHP Uppercase Sentences

14 Nov

I’ve never really had a need to write code to uppercase only sentences in a string, but I now am dealing with large blocks of text content that is often written all uppercase by the author. So I popped on over to the PHP manual. I was pretty certain no such function existed in the language, but thought I’d check if one was added in a newer version.

Alas, no such function existed, so I wrote one myself Read the rest of this entry »


Posted in PHP


jQuery Placeholder Fallback

01 Aug

One of the handy new features for <input> elements in HTML5 is the “placeholder” attribute. If you’re unfamiliar with this attribute, it allows you to pre-populate a text input with instructions which disappear when the element receives focus or there is any entry in the element.

For example, if you had a field prompting a user to enter their username, the placeholder text might be “Enter your username here.” With the introduction and support of the “placeholder” attribute, all that would be required is the use of an input tag like <input type=”text” placeholder=”Enter your username here.”/> and the browser will automatically display your text whenever there is no entry in the field and it does not have the keyboard focus.

The only problem is that older web browsers (and even those that are not-so-old, such as IE8) lack support for placeholders, so a standalone solution is required. After contemplating a couple of different fallback implementations, I decided that for my requirements, an extremely simple implementation would be best.

Read the rest of this entry »


PHP 5.3 Class Friendship Support

23 Apr

One of the useful features of OOP languages like C++ is class friendship via the friend keyword. What this allows you to do is define a class that permits other explicitly named classes to touch its private parts.

For an overly simple example, let’s say you have a User class that carries its user info privately, but you also have a Logger class for writing error and info message to a log. If you tried the following, you’d hit errors telling you that the User properties “id” and “nick” are private:

class User {
  private $id;
  private $nick;
  // ...

class Logger {
  // ...
  public static function write($str) {
    $user = User::get_current_user();
    fwrite(self::$handle, "User: {$user->nick} ({$user->id}): {$str}\n");

In C++ you could add a simple line to class User like:

friend class Logger;

This would permit the Logger class to access any of its private or protected properties and methods. Despite there being numerous people who demand that you should redesign your code instead of using class friendship, there are many cases where friendship is not only useful but necessary. This is all good and fine except for the fact that the PHP language does not have support for friend classes, nor do its developers have any intention of adding it (the last I heard from the PHP team is they long ago decided against such functionality).

This led me to develop a workaround, which wouldn’t have been possible in the past, but with the flexibility of PHP5.3 and late-static binding, it is now possible. So, without further ado, here’s my implementation of class Friendship.
Read the rest of this entry »

No Comments

Posted in PHP


PHP 5.3 Dynamic Namespace Resolution

10 Apr

As PHP continues evolving, it just keeps getting better and better. One of the features added in version 5.3 is support for namespaces. If you’ve started trying to actually use PHP namespaces, you’ve probably run into some of the more obvious quirks that require you to either retrofit your code or implement a workaround. I started with the former before realizing that thanks to the namespace feature itself, a simple set of workarounds could do the job.

Specifically, I’m referring to the fact that namespace resolution happens at compile time, which means that if you attempt to reference a namespaced class or method as a string, it won’t be recognized unless that string explicitly includes the namespace name. The most apparent case is when calling class_exists(). For example, let’s say you define class Settings in namespace OssumCMS:

namespace OssumCMS;

class Settings {
  const MEMCACHED_ADDR = 'none';
  public static function do_something() {

In your code, you might want to do some things like:

// ...
if (class_exists('Settings'))
  if (@constant('Settings::MEMCACHED_ADDR') != 'none')
    call_user_func(array('Settings', 'do_something'));

But that would never work because class Settings is defined within namespace OssumCMS. PHP resolves namespaces at compile time, so when class_exists(), constant(), and call_user_func() are called at run time, they won’t ever find class Settings because it’s checking only the global namespace. Read the rest of this entry »


Posted in PHP


Automated PDF Manipulation

27 Mar

I recently found myself on a project involving PDF file organization. I’ve always known there to be countless open source PDF manipulation tools, but I’ve never really used many myself, and especially not via a Linux shell.

Specifically what I needed to do is:

  1. split multiple pages into each individual page
  2. create a thumbnail image to preview each page
  3. extract all readable text from each page for searching

Read the rest of this entry »

No Comments

Posted in Linux


Fancy Opts jQuery Plugin – Custom Radio and Checkbox Inputs

16 Mar

I was in need of a quality jQuery plugin that would allow me to customize radio buttons and checkboxes. After a bit of googling, I was only able to find offerings that weren’t fully featured. Specifically, they lacked graceful degradation, required custom HTML, and/or just functioned far too much unlike a native input.

As is usually the case, I couldn’t find what I needed so I decided to create it myself, and so the Fancy Opts plugin was born. It allows you to simply create flexible and completely unique radio button and checkbox inputs. Read the rest of this entry »


TH Float jQuery Plugin – Fixed THEAD and TFOOT

03 Mar

I recently found myself in need of an elegant, simple solution allowing users to know which column in a table contained which value once the table header has scrolled out of view.

A quick google lead me to believe that no such plugin for jQuery currently exists. I did find a few table-centric plugins that (maybe) include the kind of functionality that I wanted, but nothing looked to provide just what I had in mind. So, I started working on the plugin myself.

I call the plugin TH Float, but it could also aptly be named Sticky Table TH or Fixed THEAD / TFOOT. What it does is make the <thead> or <tfoot> of a table remain floating in view at the top or bottom, respectively, of the scrollable container until the table is completely out of view. Read the rest of this entry »


IE8 Crash – Inline-Block Scroll with DOM Append

02 Mar

Was struggling for many hours today to figure out what has turned out to be a really stupid bug in IE8. In the hopes I can prevent even a single person from wasting their day like I have trying to figure out what is wrong with my code, I’ll explain below how the bug presents itself with examples. Read the rest of this entry »

1 Comment

Posted in Bugs


PHP Shared Session Encoding Solution

06 Feb

I came up against a really baffling problem the other day. I was tasked with adding a Wiki for VideoSift. Rather than just dumping MediaWiki onto the primary VideoSift web server, we wanted to keep it self-contained for security and load reasons, so we installed into one of our other back-end servers which was being used as a MySQL Slave and not hosting any web content. To start with I just did a quick, basic install of Apache2 and PHP5 (I would prefer and attempted to use Nginx with PHP5-FPM, but MediaWiki complains about implementation bugs in the packaged versions available to me and I don’t want to recompile from source).

Read the rest of this entry »


Posted in PHP