Friday, January 3, 2014

Designing Validation Rules for Names

Seems like there's no hope of ever getting it right: http://www.kalzumeus.com/2010/06/17/falsehoods-programmers-believe-about-names/

But still, I'm sure for the sanity of the app and where applicable, other users, certain rules can/should be applied on a case-by-case basis:

  • Length limits because you simply can't design a website with any length of name possible
  • Character limits in situations where names have to be readable by majority of users (e.g. restrict to ASCII or extended ASCII)

Monday, December 30, 2013

Saturday, December 21, 2013

Modal Window Not Displaying With AngularJS and Bootstrap

This will probably be fixed pretty soon but for now (i.e. Angular UI for Bootstrap version 0.7 and Bootstrap 3), the modal window will not display (only the backdrop will).

To make the modal window display, change "display: none" to "display: block" in the ".modal" class in the CSS. However, it will be very badly formatted. To fix the formatting issues, the markup for the modal needs to be put inside the following 2 div blocks:

<div class="modal-dialog">
<div class="modal-content">
                 <!-- modal content here→
       </div>
</div>

References:

AngularJS Logging

AngularJS has a logging service $log that can be used to log information for e.g. debugging purpose. The main advantage of using this instead of the usual "console.log" is that you can control whether debug level messages are filtered out. Additionally, you can also add decorators to add additional behaviours.

To use it, just inject "$log" as you would $scope, $location etc.

Example here: http://docs.angularjs.org/api/ng.$log

Configure the $logProvider when defining the module to enable/disable debug.

Example: http://plnkr.co/edit/HZCAoS?p=preview

Example of decorator to add additional behaviour: https://coderwall.com/p/_zporq

Downloading File using curl

When you issue a "curl <url>" command, the output will be shown on stdout. This is great when trying to read a text response but most of the time, what you're doing is downloading a file.

The easiest way to do it is "curl -O <url>". This downloads the file with the same filename as the remote file.

Wednesday, December 18, 2013

CIDR Block Cheat Sheet

This page has a cheat sheet for coming up with CIDR blocks using the "a.b.c.d/x" notation: http://whatismyipaddress.com/cidr

Thursday, December 12, 2013

Online Tool for Converting Between Sexagesimal and Decimal Notations

Latitude and Longitude are represented sometimes in decimal notation and other times in sexagesimal notations.

Here's an online tool for converting between the two: http://ghiorzi.org/sexagesi.htm

Friday, November 29, 2013

Javascript Adding Arrays

To add a Javascript array to another, use the "concat" method. Note that it doesn't change the original array but instead returns a new one, so you have to assign the return value.

References:

Friday, November 22, 2013

AngularJS Datepicker

The Angular UI team has an implementation based on JQuery UI datepicker. Download and documentation here: https://github.com/angular-ui/ui-date

Note: it is possible to customize the behavior using options (see "Options" section in the link above).

As an alternative, there is a variant based on Bootstrap: http://angular-ui.github.io/bootstrap/

Thursday, November 21, 2013

Monday, November 18, 2013

Thursday, November 14, 2013

Git Diff Tool

It seems after the Mountain Lion update, "git difftool" now no longer has a graphical diff interface.

I had to set it up again using the instructions from here: http://git-scm.com/book/en/Customizing-Git-Git-Configuration

I also had to install kdiff3 separately.

Wednesday, November 13, 2013

Jackson Date Handling

The default is behavior is epoch, but lots of way to customize, as explained here: http://wiki.fasterxml.com/JacksonFAQDateHandling

Servlet "init" Method Called Multiple Times

This can happen if an exception is thrown the last time it was called.

Wednesday, November 6, 2013

AWS Policy Document "Sid" Field

This is a field that is usually generated by the policy generator but what happens when you copy and paste a policy? Is it safe to leave it unchanged? Or should it be changed to another value?

According to this blog post:

"The Sid (statement ID) is an optional identifier you provide for the policy statement. Essentially it is just a sub-ID of the policy document's ID. The Amazon S3 implementation of the access policy language require this element and have uniqueness requirements for it."

In this case, any identifier unique to the document should be sufficient, even "1", "2", "3" etc.