Categories
JavaScript Open Source Solutions Web

Convert JavaScript Date format YYYYMMDD

Here is a simple function that takes the input of JS Date and returns a string of format YYYYMMDD:

var getDateFromDateTime = function(date) {
date = new Date(date); //Using this we can convert any date format to JS Date
var mm = date.getMonth() + 1; // getMonth() is zero-based
var dd = date.getDate();
if(mm<10){ mm="0"+mm; } if(dd<10){ dd="0"+dd; } return [date.getFullYear(), mm, dd].join(''); // padding };

Categories
Android Apps Device Open Source Solutions

How to Disable Back Button Press in Android

You need to override the “onBackPressed” method to avoid the default action. You can leave the function empty if you dont want any action to be taken on press of the Back Button.

The Code:

@Override
public void onBackPressed() {
}

Note: this requires API Level 5 or higher.

Categories
Open Source Solutions

Git – Undo Uncommitted Changes to a Specific File

Here are the steps remove uncommited changes to a file in Git:

  • Firstly check the list of uncommited changes in your system by using the command “git status
  • To remove the changes to the file use the command: git checkout <filepath>  Make sure you use the full path as seen in the git status output
  • Execute “git status” again to make sure that the file is now clean again.
Categories
AngularJS Solutions Web

AngularJS – Filter to add Leading 0s to any Number

Lets say you want to display a list of numbers from 1 to n but want them to be displayed as 01 02 03 04 05… and not 1 2 3 4 5… Angular by default doesn’t have a filter for this.

Here is how you implement it:

Implement the filter in a module. Here we take the variable len to define how many 0s must be prepended to the number.
If len is 2 then 1 becomes 01
If len is 3 then 1 becomes 001
If len is 4 then 1 becomes 0001… so on and so forth

angular.module('myModule', [])
.filter('fixedLengthPrefix', function () {
return function (n, len) {
var num = parseInt(n, 10);
len = parseInt(len, 10);
if (isNaN(num) || isNaN(len)) {
return n;
}
num = ''+num;
while (num.length < len) { num = '0'+num; } return num; }; });

Now add the filter to the markup:

{{number | fixedLengthPrefix:2}}

Categories
Linux Solutions Ubuntu Web

WordPress: Error Uploading Media Files

I recently got the following error while uploading media to my wordpress site:

Unable to create directory uploads/2016/06. Is its parent directory writable by the server?

Here are the steps to fix the issue:

  • Possible Issue 1: Incorrect Directory pointed to in the settings:
    • Open your WordPress Admin page (this is usually at /wp-admin)
    • Hover over the sidebar menu “Settings” and then click on “Media
    • Check the section “Uploading Files“(If this section is missing then try the next solution)
    • check the value for “Store Uploads in This Folder
    • Most commonly the value should be “wp-content/uploads“, if not is should be pointing to the correct folder on the server. My setup had it pointing to the wrong directory with the wrong permissions.
  • Possible Issue 2: Wrong permissions
    • Login to your server via ssh or ftp
    • Traverse to the installation folder of the WordPress site
    • Check and see if the user:group settings are correct (Usually for UNIX systems its www-data:www-data)
    • If that is fine look at the permissions for the ‘uploads‘ directory and its sub directories
    • running a command ‘ls -l uploads‘, will give you the permissions set
    • The ideal permission is of 755. For this run the command “chmod -r 755 uploads

Hopefully that will solve your problems.