2015年7月28日 星期二

digital ocean , wordpress setting mysql php apache lamp

from:
https://www.digitalocean.com/community/tutorials/one-click-install-wordpress-on-ubuntu-14-04-with-digitalocean

1. in the browser
http://192.168.0.1/

2.
mysql -uroot -p

3.
apt-get update 
apt-get install phpmyadmin

4.
echo "Include /etc/phpmyadmin/apache.conf" >> /etc/apache2/sites-enabled/000-default.conf

5.
service apache2 restart

6.
http://192.168.0.1/phpmyadmin

gsutil config tutorial

https://cloud.google.com/storage/docs/gsutil_install

type below and follow the step

gsutil config -b

javascript file upload read target event


from :
http://www.html5rocks.com/en/tutorials/file/dndfiles/

there is file API for users to operate file conveniently 

References



<style>
  .thumb {
    height: 75px;
    border: 1px solid #000;
    margin: 10px 5px 0 0;
  }
</style>

<input type="file" id="files" name="files[]" multiple />
<output id="list"></output>

<script>
  function handleFileSelect(evt) {
    var files = evt.target.files; // FileList object

    // Loop through the FileList and render image files as thumbnails.
    for (var i = 0, f; f = files[i]; i++) {

      // Only process image files.
      if (!f.type.match('image.*')) {
        continue;
      }

      var reader = new FileReader();

      // Closure to capture the file information.
      reader.onload = (function(theFile) {
        return function(e) {
          // Render thumbnail.
          var span = document.createElement('span');
          span.innerHTML = ['<img class="thumb" src="', e.target.result,
                            '" title="', escape(theFile.name), '"/>'].join('');
          document.getElementById('list').insertBefore(span, null);
        };
      })(f);

      // Read in the image file as a data URL.
      reader.readAsDataURL(f);
    }
  }

  document.getElementById('files').addEventListener('change', handleFileSelect, false);
</script>



2015年7月20日 星期一

copyfile, nodejs, fs, extra, file upload

npm install formidable@latest
npm install fs-extra

===========================

var formidable = require('formidable'),
    http = require('http'),
    util = require('util'),
    fs   = require('fs-extra');

http.createServer(function(req, res) {
  /* Process the form uploads */
  if (req.url == '/upload' && req.method.toLowerCase() == 'post') {
    var form = new formidable.IncomingForm();
    form.parse(req, function(err, fields, files) {
      res.writeHead(200, {'content-type': 'text/plain'});
      res.write('received upload:\n\n');
      res.end(util.inspect({fields: fields, files: files}));
    });

    form.on('end', function(fields, files) {
        /* Temporary location of our uploaded file */
        var temp_path = this.openedFiles[0].path;
        /* The file name of the uploaded file */
        var file_name = this.openedFiles[0].name;
        /* Location where we want to copy the uploaded file */
        var new_location = '/Users/staging/Desktop/website_istaging/example/gcloud/temp/jquery_upload_ejs/sample_storage/fs_extra/';

        fs.copy(temp_path, new_location + file_name, function(err) {
            if (err) {
                console.error(err);
            } else {
                console.log("success!")
            }
        });
    });

    return;
  }

  /* Display the file upload form. */
  res.writeHead(200, {'content-type': 'text/html'});
  res.end(
    '<form action="/upload" enctype="multipart/form-data" method="post">'+
    '<input type="text" name="title"><br>'+
    '<input type="file" name="upload" multiple="multiple"><br>'+
    '<input type="submit" value="Upload">'+
    '</form>'
  );

}).listen(8080);

2015年7月18日 星期六

四种常见的 POST 提交数据方式

http://imququ.com/post/four-ways-to-post-data-in-http.html


application/x-www-form-urlencoded

multipart/form-data

application/json

text/xml


node.js post example, with callback

test as :
http://httpbin.org/

//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////


//Load the request module
var request = require('request');

//Lets configure and request
request({
    url: 'http://httpbin.org/', //URL to hit
    qs: {from: 'blog example', time: +new Date()}, //Query string data
    method: 'POST',
    //Lets post the following key/values as form
    form: {
        field1: 'data',
        field2: 'data'
    }
}, function(error, response, body){
    if(error) {
        console.log(error);
    } else {
        console.log(response.statusCode, body);
    }
});


//////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////

app.post('/postpage', function(req, res) {
  res.send('respond with a resource'+req.body.username); 
});




2015年7月16日 星期四

mac npm, nodejs, express , express generator install

from:
http://coolestguidesontheplanet.com/installing-node-js-osx-10-9-mavericks/





sudo npm install -g express-generator

linux find,


file name contain "php" string

find . -type f -name "*php*"




paypal parse cloud code

Parse.Cloud.define("send_paypal_invoice", function(request, response){

var headerParams = [{   //Setting PayPal request headers
                    'X-PAYPAL-SECURITY-USERID'      : '****************',
                    'X-PAYPAL-SECURITY-PASSWORD'    : '***********',
                    'X-PAYPAL-SECURITY-SIGNATURE'   : '****************',
                    // Global Sandbox Application ID
                    'X-PAYPAL-APPLICATION-ID '      : 'APP-80W284485P519543T',
                    // Input and output formats
                    'X-PAYPAL-REQUEST-DATA-FORMAT'  : 'JSON',
                    'X-PAYPAL-RESPONSE-DATA-FORMAT' : 'JSON'
                }];

var payload = {
    requestEnvelope: {
        errorLanguage:  'en_US'
    },
    invoice: {
        merchantEmail: '*****************',
        payerEmail:    '*****************',
        currencyCode:  'SGD',
        paymentTerms:  'DueOnReceipt',
        itemList: [{    name:'BananaPlant',
                        quantity:'1',
                        unitPrice:'38.95'
                    },
                    {   name:'testPlant',
                        quantity:'2',
                        unitPrice:'18.20'}]
            }
    };     

var bodyJsonParams = JSON.stringify(payload);        

var headerJsonParams = JSON.stringify(headerParams);

Parse.Cloud.httpRequest({
  url: 'https://svcs.sandbox.paypal.com/Invoice/CreateAndSendInvoice',
   headers: headerJsonParams,
   body: bodyJsonParams,

  success: function(httpResponse) {
    console.log(httpResponse.text);
  },
  error: function(httpResponse) {
    console.error('Request failed with response code ' + httpResponse.status);
  }
});


  });

2015年7月7日 星期二

express error handling

from :
https://github.com/strongloop/express/blob/master/examples/error-pages/index.js


post ,get html curl linux

Linux provides a nice little command which makes our lives a lot easier.
GET:
with JSON:
curl -i -H "Accept: application/json" -H "Content-Type: application/json" http://hostname/resource
with XML:
curl -H "Accept: application/xml" -H "Content-Type: application/xml" -X GET http://hostname/resource
POST:
For posting data:
curl --data "param1=value1&param2=value2" http://hostname/resource
For file upload:
curl --form "fileupload=@filename.txt" http://hostname/resource
RESTful HTTP Post:
curl -X POST -d @filename http://hostname/resource
For logging into a site (auth):
curl -d "username=admin&password=admin&submit=Login" --dump-header headers http://localhost/Login
curl -L -b headers http://localhost/

2015年7月6日 星期一

node express generator problem / rm -rf ~/.npm

npm ERR! Error: ENOENT, open '/var/peter/package.json'

npm ERR! If you need help, you may report this *entire* log,


cd myproject 
rm -rf ~/.npm

2015年7月4日 星期六

node js / relation routes views render jade


http://expressjs.com/guide/using-template-engines.html

to add new page into the web, as long as adding file on routes/ , views/ and app.js

routes/peter.js
var express = require('express');
var router = express.Router();

/* GET home page. */
router.get('/', function(req, res, next) {
  res.render('peter', { title: 'Peter' ,content:'hihi'});
});

module.exports = router;

view/peter.jade
extends layout

block content
  h1= title
  h2= content

  p Welcome to #{title}


app.js

var peter = require('./routes/peter');

app.use('/peter', peter);


Once the view engine is set, you don’t have to explicitly specify the engine or load the template engine module in your app, Express loads it internally as shown below, for the example above.
app.set('view engine', 'jade');
Create a Jade template file named “index.jade” in the views directory, with the following content.
html
  head
    title!= title
  body
    h1!= message
Then create a route to render the “index.jade” file. If the view engine property is not set, you will have to specify the extension of the view file, else you can omit it.
app.get('/', function (req, res) {
  res.render('index', { title: 'Hey', message: 'Hello there!'});
});







node express generator problem "/usr/bin/env: node: No such file or directory"




solution:

ln -s /usr/bin/nodejs /usr/bin/node

allow root login ssh, sftp , debia

Open sshd_config file:
# vi /etc/ssh/sshd_config
Find out line that read as follows:
PermitRootLogin no
Set it as follows:
PermitRootLogin yes



Save and close the file. Restart the sshd:
# /etc/init.d/ssh restart