Tuesday, April 24, 2018

SUGARCRM: Custom Theme

The following error is either thrown when installing a new Sugar instance or when clearing the cache:

Exception in Controller: exception 'SugarApiExceptionError' with message 'lessc fatal error:<br />load error: failed to find tmp_less_custom_compiler.less'

This means that your custom.less file has a syntax error. Fix any syntax errors and try again.

If your custom.less file is empty, just delete the file, clear the cache, and load the Page again.

mySQL - Time Out Error

The following error is thrown when importing a large database:

mysql server has gone away

If you are an admin or have sufficient privileges, update the my.cnf or mysql.cnf file by adding the following command:

[mysqld]
max_allowed_packet=500M

Monday, March 12, 2018

JAVASCRIPT: Date Current Year

In JavaScript, we can get the current year as follows:
var myDate = new Date('2017-02-12');
console.log(myDate.getFullYear());
Expected Output: 2017
Actual Output: 2017

But, what happens if we test a boundary value with the above function:
var myDate = new Date('2017-01-01');
console.log(myDate.getFullYear());
Expected Output: 2017
Actual Output: 2016

In this case, we need to call getUTCFullYear()
var myDate = new Date('2017-01-01');
console.log(myDate.getUTCFullYear());
Expected Output: 2017
Actual Output: 2017

Thursday, May 25, 2017

PHP: Set Datetime with a Specific Time Zone

// Some databases or systems use GMT or UTC, so we need to 
// get the correct date time format at this point
$UTC = new DateTimeZone("UTC");
$dateTime = new DateTime($date, $UTC);

// Set your preferred time zone $dateTime->setTimezone(new DateTimeZone('America/Los Angeles'));
// Extra: Format your date time
$dateTimeFormatted = $dateTime->format('Y-m-d H:i:s');
echo  $dateTimeFormatted;

Friday, May 5, 2017

LINUX: Copying and Overwriting Files from a Folder to Parent Folder

cp -fR /source/files /dest
 
https://superuser.com/questions/358843/
how-to-replace-all-the-contents-from-one-folder-with-another-one 

LINUX: Changing Group and Ownership

Note: You may need root/sudo permissions

Group:
> chgrp <group name> <directory or file name>

Owner:
> chown  <user name> <directory>

Owner and Group:
> chown <user name>:<group name> <directory>

Owner and Group of all files and subfolders
> chown -R <user name>:<group name> <directory>

Thursday, May 4, 2017

BACKBONE: Detecting Events for Several Elements

Problem:
Suppose you have several "select" elements in a table with the same data that triggers another "select" element, but you want to detect each "select" individually.

<table>
  <tr>
    <td><select>.....</select></td> <!--Select we want to detect-->
    <td><select>.....</select></td> <!--Dependent Select--> 
 </tr>
 <tr>
    <td><select>.....</select></td> <!--Another Select-->
    <td><select>.....</select></td> <!--Another dependent Select-->
 </tr>
</table>

Solution:
In Backbone, we can add the "data-id" tag to the select element and dynamically populate the id in Backbone. Also, we need to add a class tag so all the "select" elements are fired without the need to construct a map or array of events. In the event you want to favor performance over simplicity, please consider the events collection approach.

({
     selectTable1:
    {
         selectCounter : 0
    },

    initialize: function()
    {
         // Add selects dynamically here (or create a helper function),
         // or get other selects, etc.
    },
 
    events:
   {
       'change .myClass': 'detectEvent'
   },

   detectEvent: function(e)
    {
        e.preventDefault();
        var id = $(e.currentTarget).data("id");
    }
)}