Friday, January 19, 2018

Heroku Dashboard Create App


1. Create new app in Heroku Dashboard


https://dashboard.heroku.com/apps

Find the NEW Button.


Select Create new app.

Give a name eg test247 .


2. Using Heroku CLI


https://dashboard.heroku.com/apps/test247/deploy/heroku-git

Notice that in the Deployment Method section, Heroku Git button is selected.


3. Follow the guide


https://dashboard.heroku.com/apps/test247/deploy/heroku-git



Heroku Getting Started PHP On Uwamp




1. Register with heroku

https://signup.heroku.com/account



2. Select PHP in Heroku Dashboard


https://dashboard.heroku.com/apps

3. Prepare Local System Environment

This tutorial uses the following Local System Environment:

3.1. Windows 7 Professional SP1
3.2. Uwamp version 3.1.0 (https://www.uwamp.com/file/UwAmp.exe)
3.3. Visual C++ Redistributable for Visual Studio 2012 Update 4  vcredist_x86.exe (https://www.microsoft.com/en-us/download/confirmation.aspx?id=30679) [this is required by Apache]

... otherwise Apache will not run in this WAMP package

3.4. Visual C++ Redistributable for Visual Studio 2015 - vc_redist.x86.exe (https://www.microsoft.com/en-us/download/details.aspx?id=48145) [this is required by PHP runtime]
...otherwise windows will report missing dll files

4. Install Required Tool


4.1. Composer - https://getcomposer.org/download/

Install Composer and select the PHP version that you have selected via Uwamp in step 3.2 above (Heroku requires PHP version 7+)

4.2. Heroku CLI - https://devcenter.heroku.com/toolbelt-downloads/windows32


5. Check That All Installations Were Successful

Run Commands

5.1. PHP:  php -v
5.2. Composer: composer -v
5.3. Git: git --version  (installed by Heroku CLI in step 4.2)
5.4. Heroku: heroku (it will require you to enter your heroku account name and password)


6. Setting Up Test Project

Follow the steps in https://devcenter.heroku.com/articles/getting-started-with-php#prepare-the-app


git clone https://github.com/heroku/php-getting-started.git

cd php-getting-started

heroku create

git push heroku master

heroku ps:scale web=1

heroku open

Refer the following screenshots:



7. Check in Heroku Web Dashboard





8. Edit and Commit Changes

Edit your codes and then type the following commands:

git commit -a -m "a message describing what you did"

git push origin master



Monday, January 1, 2018

Slim PHP Simple Setup


1) Download Package


slim.zip


2) Apache ModRewrite

the .htaccess contains the following code:

RewriteEngine On

# Some hosts may require you to use the `RewriteBase` directive.
# If you need to use the `RewriteBase` directive, it should be the
# absolute physical path to the directory that contains this htaccess file.
#
# RewriteBase /

Header add Access-Control-Allow-Origin "*"
Header add Access-Control-Allow-Headers "origin, x-requested-with, content-type"
Header add Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS"

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]


3) Get and Post Method test codes


the index contains the following code:

<?php

require 'Slim/Slim.php';
\Slim\Slim::registerAutoloader();

$app = new \Slim\Slim();

$app->get('/testget/:params+','testGet');
$app->post('/testpost','testPost');

$app->run();

function testGet($params){
   echo json_encode($params);
}

function testPost(){
   $app = \Slim\Slim::getInstance();
   $postvars = $app->request->post();
   echo json_encode($postvars);
}

?>






Silex PHP Simple Setup


1) Download Package


silex.zip

2) Apache ModRewrite

the .htaccess contains the following code:

RewriteEngine On

# Some hosts may require you to use the `RewriteBase` directive.
# If you need to use the `RewriteBase` directive, it should be the
# absolute physical path to the directory that contains this htaccess file.
#
# RewriteBase /

Header add Access-Control-Allow-Origin "*"
Header add Access-Control-Allow-Headers "origin, x-requested-with, content-type"
Header add Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS"

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]


3) Test Functions


Objectives:
Get "/"
Get "/testget/1"
Post "/testpost" with form data key message (x-www-form-urlencoded)
Get "/testgetcontents" to call Get "/testget/"
Post "/testpostcontents" to call Get "/testpost/"  with form data key message (x-www-form-urlencoded)


Codes:
<?php

require_once __DIR__ . '/vendor/autoload.php';

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

$app = new Silex\Application();

$app->get('/', function(){
return new Symfony\Component\HttpFoundation\Response("Hello Silex");
});


$app->get("/testget/{id}", function($id){
   return "testget - {$id}";
   
});

$app->post('/testpost', function (Request $request) {
    $message = $request->get('message');
    $reply = 'You have sent the following message:'.$message;
    return new Response($reply, 201);
});


$app->get('/testgetcontents',function(){
   $contents = file_get_contents('http://demo.razoph.com/silex/api/');
   return $contents;
});


function file_post_contents($url, $data, $username = null, $password = null){
   $postdata = http_build_query($data);

   $opts = array('http' =>
       array(
           'method'  => 'POST',
           'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
           'content' => $postdata
       )
   );

   if($username && $password)
   {
       $opts['http']['header'] .= ("Authorization: Basic " . base64_encode("$username:$password")); 
       // .= to append to the header array element
   }

   $context = stream_context_create($opts);
   return file_get_contents($url, false, $context);
}

$app->get('/testpostcontents',function(){
   $data = array("username" => "duser", "firstname" => "Demo", "message" => "testing", "email" => "example@example.com");  
   $contents = file_post_contents('http://demo.razoph.com/silex/api/testpost',$data);
   return $contents;
});


$app->run();


REFERENCES:

https://silex.symfony.com/

https://silex.symfony.com/doc/2.0/cookbook/index.html

https://www.gajotres.net/creating-a-basic-restful-api-with-silex/

http://www.robertprice.co.uk/robblog/posting-json-to-a-web-service-with-php/

https://stackoverflow.com/questions/11319520/php-posting-json-via-file-get-contents

https://symfony.com/doc/current/components/http_foundation.html

https://www.gajotres.net/creating-a-basic-restful-api-with-silex/

https://www.sitepoint.com/introduction-silex-symfony-micro-framework/

https://stackoverflow.com/questions/37346700/get-post-body-data-in-silex-restful-api

https://sleep-er.co.uk/blog/2013/Creating-a-simple-REST-application-with-Silex/

http://editor.swagger.io/

https://swagger.io/swagger-editor/

http://www.yaml.org/start.html

http://yaml-online-parser.appspot.com/

https://learnxinyminutes.com/docs/yaml/

https://stackoverflow.com/questions/1726802/what-is-the-difference-between-yaml-and-json-when-to-prefer-one-over-the-other

https://dzone.com/articles/working-angularjs-and-silex

https://gonzalo123.com/2015/02/02/handling-angularjs-post-requests-with-a-silex-backend/

https://gonzalo123.com/2013/06/03/working-with-angularjs-and-silex-as-resource-provider/

https://gonzalo123.com/2013/12/16/enabling-cors-in-a-restfull-silex-server-working-with-a-phonegapcordova-application/

https://stackoverflow.com/questions/643355/https-url-with-token-parameter-how-secure-is-it

https://stackoverflow.com/questions/36157059/angularjs-http-post-request-with-json-parameter-and-query-string

https://stackoverflow.com/questions/24545072/angularjs-http-post-send-data-as-json

http://tutlane.com/tutorial/angularjs/angularjs-http-post-method-http-post-with-parameters-example

https://github.com/vesparny/silex-simple-rest

https://github.com/shahroznawaz/Rest-API-in-Silex

https://github.com/mbezhanov/silex-rest-api-example

http://marinbezhanov.com/demo/vuejs-rest-client-example/#/diary

https://www.cloudways.com/blog/create-rest-api-silex/






Thursday, October 26, 2017

Install Node For Mac


.

How to Install Node and NPM

Installing Node.js and NPM is pretty straightforward using Homebrew. Homebrew handles downloading, unpacking and installing Node and NPM on your system. The whole process (after you have XCode and Homebrew installed) should only take you a few minutes.

Open the Terminal app and type...

 brew install node

Sit back and wait. Homebrew downloads some files and installs them. And that’s it.

To make sure you have Node and NPM installed, run two simple commands to see what version of each is installed:

To see if Node is installed, type node -v in Terminal. This should print the version number so you’ll see something like this v0.10.31.
To see if NPM is installed, type npm -v in Terminal. This should print the version number so you’ll see something like this 1.4.27


How to Update Node and NPM


New versions of Node and NPM come out frequently. You can use Homebrew to update the software it installs.

Make sure Homebrew has the latest version of the Node package. In Terminal type brew update
Upgrade Node: brew upgrade node
How to Uninstall Node and NPM

You can use Homebrew to uninstall packages that it installed: brew uninstall node

With Node.js and NPM installed you’ll soon be able to take advantage of the huge world of NPM modules that can help with a wide variety of tasks both on the web server and on your desktop (or laptop) machine. The NPM site lists all of the official Node packages making it easy to make the choice.

Reference:

https://blog.teamtreehouse.com/install-node-js-npm-mac.

Install Homebrew For Mac



Homebrew is a package manager for the Mac. The Homebrew website says "Homebrew installs the stuff you need that Apple didn’t". It makes installing most open source software simple.

To install, open Terminal and type:


ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"


Reference:
1. https://brew.sh/
2. https://blog.teamtreehouse.com/install-node-js-npm-mac


Wednesday, October 25, 2017

Windows Network Diagnostic Commands


-----

Windows Network Diagnostic Commands

The following are common Microsoft Windows network commands
ipconfig
Ipconfig is a Console Command which can be issued to the Command Line Interpreter (or command prompt) to display the network settings currently assigned to any or all network adapters in the machine. This command can be utilised to verify a network connection as well as to verify your network settings.
netstat
Displays active TCP connections, ports on which the computer is listening, Ethernet statistics, the IP routing table, IPv4 statistics (for the IP, ICMP, TCP, and UDP protocols), and IPv6 statistics (for the IPv6, ICMPv6, TCP over IPv6, and UDP over IPv6 protocols). Used without parameters, netstat displays active TCP connections.
tracert
The tracert command is used to visually see a network packet being sent and received and the amount of hops required for that packet to get to its destination.
Users with Microsoft Windows 2000 and Windows XP who need additional information network latency and network loss should also consider using the pathping command.
ping
Helps in determining TCP/IP Networks IP address as well as determine issues with the network and assists in resolving them.
pathping
Provides information about network latency and network loss at intermediate hops between a source and destination. Pathping sends multiple Echo Request messages to each router between a source and destination over a period of time and then computes results based on the packets returned from each router.
telnet
Telnet is software that allows users to remotely access another computer such as a server, network device, or other computer. With telnet users can connect to a device or computer, manage a network device, setup a device, transfer files, etc.
ftp
FTP is short for File Transfer Protocol, this page contains additional information about the FTP command and help using that command in Unix and MS-DOS (Windows).
route
The function and syntax of the Windows ROUTE command is similar to the UNIX or Linux route command. Use the command to manually configure the routes in the routing table.
arp
Displays, adds, and removes arp information from network devices.
nslookup
Displays information that you can use to diagnose Domain Name System (DNS) infrastructure. Before using this tool, you should be familiar with how DNS works. The Nslookup command-line tool is available only if you have installed the TCP/IP protocol.
nbtstat
MS-DOS utility that displays protocol statistics and current TCP/IP connections using NBT.
One common way of using netsh is to reset the TCP/IP in Windows 2k/XP
Type this in Run or DOS Window – "netsh int ip reset"
In Windows XP you can run a graphical diagnostics by typing "netsh diag gui" into the run dialogue box. (This may take a little time to startup)
getmac
DOS command used to show both local and remote MAC addresses. When run with no parameters (ie. getmac) it displays MAC addresses for the local system. When run with the /s parameter (eg. getmac /s \\foo) it displays MAC addresses for the remote computer. When the /v parameter is used, it also displays the associated connection name and network adapter name.
Included with Windows XP, Windows 2003 Server, and Windows 2000 Resource Kit. Can be downloaded for the Windows 2000 here:http://www.microsoft.com/windows2000/techinfo/reskit/tools/existing/getmac-o.asp
Find All Active/Used IP Addresses on Your Network
There is a really neat way that you can quite easily find all active/used IP Addresses on your network without the need for any third party applications or worse, pinging each IP Address individually.
Open the Command Prompt and type in the following:
FOR /L %i IN (1,1,254) DO ping -n 1 192.168.10.%i | FIND /i "Reply"&gt;&gt;c:\ipaddresses.txt
Change 192.168.10 to match you own network.
---
source: http://whirlpool.net.au/wiki/windows_nw_diag_cmds