Thursday, November 10, 2016

Php determine if date string is a valid date in that format

Code snippet

function validateDate($date_string)
{
    $date_value = DateTime::createFromFormat('Y-m-d', $date_string);
    return $date_value && $date_value->format('Y-m-d') === $date_string;
}

Some examples

var_dump( validateDate('2016-13-10'));   // false
var_dump( validateDate('20160-13-10'));  // false
var_dump( validateDate('2016-11-32'));   // false
var_dump( validateDate('2017-02-29'));   // false

var_dump( validateDate('2016-11-02'));   // true
var_dump( validateDate('1970-12-21'));   // true
var_dump( validateDate('2017-07-29'));   // true

Online fiddle link


Wednesday, November 9, 2016

Git commit single or multiple files

git commit project/config/app.php project/env -m "Test"

Marked yellow are two files, you add more files one by one.

Marked orange is message for this commit.

Git clone with user name and password

1. Use: 
git clone https://user:password@server.org/username/repo.git

2. Or (It will prompt you for your password):
git clone https://user@server.org/username/repo.git

Git: How to checkout a file from another git branch


1. First go to your project location using git bash

2. Use below command to go to project location:

3. Command:: cd /c/User/pritom/Git_Project/my_project

3. Now go to the branch from where you want to update file to 
current branch

3.1 You have to update the branch from which you want to 
checkout file

4. Command:: git checkout another_branch

5. Command:: git pull

6. Command:: git diff --name-only another_branch~1 
(It will list files changed last 1 commit)

7. Now go to working branch using:

8. Command:: git checkout current_branch

9. First pull to update current branch using:

10. Command:: git pull 

11. Now checkout files from another_branch using:

12. Command:: git checkout another_branch app/data/some_data.name

13. Now you file updated with another_branch

14. Command:: git status (It will show files changes)

Tuesday, November 8, 2016

Grails get retrieve GrailsParameterMap params from service class or util class

Have to import:
import org.springframework.web.context.request.RequestContextHolder

and use following:
def params = RequestContextHolder.getRequestAttributes().params

Reload refresh current url or redirect to another url using php script

Refresh/reload current page:
header("Refresh:0");

Or you can redirected to another page using:
header("Refresh:0; url=another-page.php");