Thursday, July 28, 2016

Technical Skills a Software Developer Needs

Devs,

Here's another great article I read today. I, for the most part, agree with this author.

https://simpleprogrammer.com/2016/07/18/technical-skills-software-developer/

And here's a bonus article: Why SmallTalk is great to know?
http://techbeacon.com/how-learning-smalltalk-can-make-you-better-developer

I can add that it's definitely good to know when having conversations with older techies. I remember one developer from my first job rave about how SmallTalk was THE language and the industries were wrong for jumping into the next "hyped" language.

And another one on the importance of the rising skill of "data analysis":
http://venturebeat.com/2016/07/17/forget-learning-to-code-every-employee-should-know-data-analysis/

Enjoy,
G2

Goodbye OO?

Devs,

I read this great article and had to share. I haven't tried much the proposed development approach (i.e. functional programming), but I am familiar with the challenges of OO.

https://medium.com/@cscalfani/goodbye-object-oriented-programming-a59cda4c0e53#.e1crc9bdt

There are the hybrid development approaches, too.

Of course, it always depends and a developer has to be wise to know which solution works best.

Happy Thinking,
G2

Friday, July 22, 2016

JQuery: Setting Default Date on DatePicker

Devs,

I recently was trying to set the default date of a DatePicker that I added to a input field.

form.find('#expires').datepicker( {defaultDate: 7} );

However, the DatePicker would keep displaying the default date value of "1/1/2020". This was driving me nuts as I was looking through the documentation and searching online (i.e. SO) for solutions to my problem to no avail.

http://api.jqueryui.com/datepicker/#option-defaultDate
http://stackoverflow.com/questions/14580749/jquery-datepicker-set-default-date

Root Cause:

After intense thinking and investigation, I finally found my root cause. I already set the predefined value in the field itself which was overriding my jquery default property.

<input type="text" name="expires" class="expires" id="expires" placeholder="Expires" value="1/1/2020" />


Solution #1:

Remove the attribute value in the input field or replace the value with expected default value before passing field to DatePicker.

I chose to replace the value upon displaying of the input field because without the value attribute the input field displays null by default and the DatePicker would open with a default date. I wanted a default date in the input field AND in the DatePicker.

<input type="text" name="expires" class="expires" id="expires" placeholder="Expires" value="1/1/2020" />

form.find('#expires').val( _getDefaultExpirationDate() );
form.find('#expires').datepicker();

/** 
* Get Default Expiration Date
* @return (string) current date + 1 month in format: MM/DD/YYYY
*/
function _getDefaultExpirationDate()
{
var today = new Date();
return tens(today.getUTCMonth()+ 1) +'/'+ tens(today.getUTCDate()) +'/'+ today.getUTCFullYear();
}

/** 
* Tens 
* - converts an integer that's a single digit into double digits
* - useful for dates and times
* @param (int) integer
* @return (string) single digit with leading '0' or double digit
*/
function _tens (integer)
{
while (integer > 99 )
{
integer = integer - 100;
}
return (integer < 10) ? "0"+integer : integer;
}

Easier Solution:

Change the input type from 'text' to 'date' and set default value.
http://www.w3schools.com/jsref/prop_date_value.asp

<input type="date" name="expires" class="expires" id="expires" placeholder="Expires" value="1/31/2016" />

Happy Coding!,
G2

Wednesday, July 13, 2016

PHP Array indexes are CaSe-SeNsiTIvE

Devs,

Quick note, PHP array indexes are CaSe-SeNsiTIvE.

I ran into an issue with sending a $_POST to the database to insert a record. I was validating the data in the post array and setting required values if a key was not set properly. However, this gave me a database insert error stating I'm using duplicate field (column) names.

Well, ain't that tricky!

Did a quick search to confirm my assumption about PHP array indexes being case-sensitive.
http://stackoverflow.com/questions/1511230/php-array-are-array-indexes-case-sensitive

Yep, added the check for all cases and database insert worked! Yay!!

I wonder what other languages treat array indexes as case-sensitive? Maybe all programming languages? This would only make sense, no? The value of an index is calculated differently based on char value, right?

To be continued...

Happy Coding,
G2