Ubuntu: How to fix if screen brightness is not working

Recently I bought a new Dell Inspiron 3521 and Installed Ubuntu 13.10. Then I seen a minor issue it was screen brightness was not working. But in Try Ubuntu mode screen brightness was working well.

It may be your machine having same issue. So, lets go to fix this problem. Here is the solution I found some where:

First open /etc/default/grub:

$ sudo nano /etc/default/grub

In /etc/default/grub around line 12 there could be a line with written this:

GRUB_CMDLINE_LINUX=""

If found then change it as below line or if not then paste the below line:

GRUB_CMDLINE_LINUX="acpi_backlight=vendor"

Now save changes by pressing Ctrl+O then Enter Key

That’s it, you have done

But you should update Grub to apply changes. So also do this:

$ sudo update-grub

And what? Restart you machine.

How to find date interval in JavaScript

var get_date = function(interval) {
    // Get current time
    var now = (new Date).getTime();

    // Check if interval has some value
    if(!isNaN(parseInt(interval))) {
        now += parseInt(interval);
    }

    // Initialize date object
    var today = new Date(now);
    var yyyy = today.getFullYear();
    var mm = today.getMonth() + 1;
    var dd = today.getDate();
    var hh = today.getHours();
    var ii = today.getMinutes();
    var ss = today.getSeconds();

    // Lead 0 if month is less than 10        
    if(mm < 10) {
        mm = '0' + mm;
    }
    // Lead 0 if day is less than 10
    if(dd < 10) {
        dd = '0' + dd;
    }

    // Lead 0 if hours is less than 10
    if(hh < 10) {
      hh = '0' + hh;
    }

    // Lead 0 if minutes is less than 10
    if(ii < 10) {
      ii = '0' + ii;
    }

    // Lead 0 if seconds is less than 10
    if(ss < 10) {
      ss = '0' + ss;
    }

    return yyyy + '-' + mm + '-' + dd + ' ' + hh + ':' + ii + ':' + ss;
}

Now use the function above to add interval to current date:

// Get current date
console.log(get_date());

// Add one day to current date
var interval = 86400000 * 1;
console.log(get_date(interval));
// Similarly add 20 days to current date
var interval = 86400000 * 20;
console.log(get_date(interval));
// Subtract 20 days to current date to past date
var interval = 86400000 * -20;
console.log(get_date(interval));

Find last 10 days records even some days is missing between

Here I’m selecting last 10 days records from transaction table even there is some days has no any transaction.

SELECT * FROM `transaction` `t`
WHERE 
    DATE(`t`.`timestamp`) < (
        SELECT DATE(`s`.`timestamp`) FROM `transaction` `s`
        GROUP BY DATE(`s`.`timestamp`)
        ORDER BY DATE(`s`.`timestamp`)
                DESC LIMIT 10,1
    )
ORDER BY `t`.`timestamp` DESC

SAMPLE: Results will be only for previous date:

Read More