[ php ] DateInterval / DatePeriod

$interval = new DateInterval('P1D')

Two days is P2D

List date

$begin = new DateTime( '2012-08-01' );
$end = new DateTime( '2012-08-31' );
$end = $end->modify( '+1 day' );

$interval = new DateInterval('P1D');
$daterange = new DatePeriod($begin, $interval ,$end);

foreach($daterange as $date){
echo $date->format("Ymd");
}

ref : http://php.net/manual/en/dateinterval.construct.php

Gradle : automate Build Tool + Deployment Tool

  • Build by convention ( like Maven (XML) ) — declarative build language
  • written Groovy DSL
  • support dependencies Ivy, Maven
  • support multi-project build

 

v.s. Ant ( Another Neat Tool ) — XML

v.s. Maven

 

Installation

way1: download from the site

then add to PATH=gradle-2.6/bin

way2: using gvm ( Groovy environment manager — http://gvmtool.net ) — great on Linux and Mac

download gvm

curl -s get.gvmtool.net | bash

add gvm to path

source ~/.gvm/bin/gvm-init.sh

install gradle

gvm install gradle

 

USAGE

settings.gradle

println "Initial Project"

build.gradle

//Configuration Phase
task Test1 {
//Configuration Phase
dependsOn "Test2"
println "Test1 => Configuration Phase"
doLast {
//Execution Phase
println "Test1 => doLast"
}
doFirst {
println "Test1 => doFirst"
}
}
task Test2 < Cofiguration Phase"
}

 

build

./gradlew build Test1 Test2

 

Gradle SSH plugin

https://gradle-ssh-plugin.github.io

 

build.gradle


plugins {
id 'org.hidetake.ssh' version '2.9.0'
}

ssh.settings {
dryRun = project.hasProperty('dryRun')
user = System.properties['user.name']
identity = file("${System.properties['user.home']}/.ssh/id_rsa")
}

remotes {
localhost {
host = 'localhost'
}
}

task deploy {
doLast {
ssh.run {
session(remotes.localhost) {
put from: 'app', into: '/tmp'
execute 'mv /tmp/app ~/python_app'
execute 'python ~/python_app/test_app.py'
}
}
}
}

 

ref : learn-gradle udemy course,

https://gradle.org/training/

gatsby : Static Web

Install gatsby-cli

npm install --global gatsby-cli

Generate new site

gatsby new gatsby-site
cd gatsby-site
npm install

 

or use the following command to create a new site

gatsby new hello-world https://github.com/gatsbyjs/gatsby-starter-hello-world#v2

Syntax

gatsby new [SITE_DIRECTORY_NAME] [URL_OF_STARTER_GITHUB_REPO]

 

gatsby-starter-default** : https://github.com/gatsbyjs/gatsby-starter-default

DEMO : http://gatsbyjs.github.io/gatsby-starter-default/

gatsby-starter-default v2 :https://github.com/gatsbyjs/gatsby-starter-default#v2

 

gatsby-starter-blog : https://github.com/gatsbyjs/gatsby-starter-blog

DEMO : http://gatsbyjs.github.io/gatsby-starter-blog/

gatsby-starter-blog v2 : https://github.com/gatsbyjs/gatsby-starter-blog#v2

 

gatsby-starter-hello-world : https://github.com/gatsbyjs/gatsby-starter-hello-world

DEMO : https://aberrant-fifth.surge.sh/

gatsby-starter-hello-world v2 : https://github.com/gatsbyjs/gatsby-starter-hello-world#v2

 

Commumity Starter : https://next.gatsbyjs.org/docs/gatsby-starters/#community-starters

Gatsby uses hot reloading to speed up your development process. Essentially, when you’re running a Gatsby development server, the Gatsby site files are being “watched” in the background — any time you save a file, your changes will be immediately reflected in the browser. You don’t need to hard refresh the page, or restart the development server — your changes just appear.

 

 

 

import React from "react"

export default () =&gt; (</pre>
<div>Hello Gatsby!</div>
<pre>
)

 

HTML in javascript : React and JSX ( hybrid “HTML-in-JS” )

/src/pages/index.js

import React from "react" // import "react", writing JSX, not pure HTML/JavaScript. Gatsby sites comes with tooling already set up to convert your source code into something that browsers can interpret.

export default () =&gt;</pre>
<div>Hello world!</div>
<pre>

In pure Javascript,

import React from "react"

export default () => React.createElement("div", null, "Hello world!")

 

Build with Page “Components” : block (HTML tag) for your site; It is a self-contained piece of code (  usually written with JSX ). that can accept input, and return React elements describing a section of UI.

CSS, HTML, and JavaScript are tightly coupled, and often living even within the same file.

Example : creating a custom button

In the past you would create a CSS class (perhaps .primary-button) with your custom styles and then whenever you want to apply those styles e.g.

button class="primary-button">
Click me
</button

PrimaryButton component

PrimaryButton>Click me</PrimaryButton

 

Run a server

gatsby develop

test URL : http://localhost:8000

 

source : src/pages/index.js ( react )

Any React component defined in /src/pages/*.js will automatically become a page.

/src/pages/about.js

import React from "react"

export default () =&gt; (</pre>
<div>
<h1>About Gatsby</h1>
Such wow. Very React.</div>
<pre>
)

Testing : http://localhost:8000/about/

components

/src/components/header.js

import React from "react"

// const Header = ({ siteTitle }) =&gt; (

//   {siteTitle}

// )

export default (props) =&gt;</pre>
<h1>This is a header. {props.headerText}</h1>
<pre>

props

DEMO : https://reactjs.org/redirect-to-codepen/components-and-props/extracting-components

Layout components : sidebar or navigation menu

 

Linking between pages : <Link /> component

Open the index page component (/src/pages/index.js). Import the <Link /> component from Gatsby. Add a <Link /> component below the header, and give it a to property, with the value of "/contact/" for the pathname:

import React from "react"
import { Link } from "gatsby"
import Header from "../components/header"

export default () =&gt; (</pre>
<div>Contact<header></header>What a world. <img src="https://source.unsplash.com/random/400x200" alt="" /></div>
<pre>
)

ref : https://next.gatsbyjs.org/tutorial/part-one/#linking-between-pages ( TOBE read )

 

/src/pages/about.js

import React from "react"
import Header from "../components/header"

export default () =&gt; (</pre>
<div><header></header>Such wow. Very React.</div>
<pre>
)

 

optimized production build for your site generating static HTML and per-route JavaScript code bundles

gatsby build

starts a local HTML server for testing your built site

gatsby serve

Test URL: http://localhost:9000

 

ref : https://www.gatsbyjs.org/docs/

 

other gatsby CLI command

gatsby --version
gatsby --help

 

Gatsby : Blazing-fast site generator for React

ref : https://github.com/gatsbyjs/gatsby

[ selenium ] installation

Dependencies

sudo apt-get install --yes openjdk-7-jre-headless firefox xvfb phantomjs
wget http://selenium-release.storage.googleapis.com/2.53/selenium-server-standalone-2.53.0.jar

Run

phantomjs --webdriver=4444 &

or

xvfb-run --server-args="-screen 0, 1366x768x24" java -jar selenium-server-standalone-2.53.0.jar > /dev/null &

xvfb-run : run specified X client or command in a virtual X server environment