Tuesday, September 19, 2017

Facebook Bot for Multiple Facebook Pages

When you call the Facebook Send API, you can pass a page access token through the access_tokenparameter. You can specify which page to direct your message by modifying this access token. To know which page initiated the message, you can access the id field of the entry of the message post.
app.post('/webhook', (req, res) => {
    const data = req.body

    // Make sure this is a page subscription
   if (data.object === 'page') {
       // Iterate over each entry
       data.entry.forEach((pageEntry) => {
           // get the pageId
           const pageId = pageEntry.id
           ...
You would then need to maintain an object mapping page ids to the access token associated with each page id:
const accessTokens = {
    myPageId1: 'myPageAccessToken1',
    myPageId2: 'myPageAccessToken2',
}
Then when sending the response, just specify the corresponding page access_token
const callSendAPI = (pageId, messageData) =>
    rp({
        uri: 'https://graph.facebook.com/v2.8/me/messages',
        qs: { access_token: accessTokens[pageId] },
        method: 'POST',
        body: messageData,
        json: true,
     })

Monday, September 18, 2017

Anaconda Installation

Initial setup for anaconda virtual environment.

Server version is anaconda 64bit / 2 + ; however, this version is anaconda 3+ / 64bit.

you need to download the anaconda 3 then you need to activate anaconda 3.

    input  ( source bin/activate )
    output (root) sadikerisen@station-X200MA:~/anaconda3$
after that please check anaconda virtual envrinment is actvated or not and you have the correct version or not?

  input  ( python --version )
  output (root) sadikerisen@station-X200MA:~/anaconda3$ python --version
         Python 3.5.2 :: Anaconda custom (64-bit)
You should be able to see above output.

Please also check your conda (package manager is working), so you need to type ' conda '.

later you need to update your package manager ' conda update --all --yes' .

Afterwards, display all the packages that you install during the main installment. Please Type ' conda list ' .

Now, you should be able to see dependency package list, althouth Django isnt installed as prerequisite.

Therefore we need to install that inorder to start application or create virtual env.

    first step, lets download that conda install -c anaconda django
Now we are able to create a new environment but we need to have atleast one dependency package.

Since we are creating Django app, and make ourselves more comfortable in the env; lets add pip

    Second step, conda create --name test Django pip

    Third step, source activate test
Now you are in the Grace project. You can always deactivate and activate your virtualenvs.

to list your vitualenvs; (root) virtualenv you need to type conda-env list

    output  (root)test                    /home/station/anaconda3/envs/test
                  root                  *  /home/station/anaconda3
You can go ahead and initlize the git in to your envs folder.

1- ls.
2- cd envs.
3- ls.
4- cd test.
5-to make sure write the path on your screen ' pwd '.
6- you can type git init and then pull test folder.



installing GCC / C++

One of the most simplest way to run C++ on linux terminal is installing GCC compiler, although there more steps that needs to be done. Usually gcc compile outcome into a text file which your editor sometimes cannot event read from it unless you adjust the binary for it.
in this case i am going to show you how to install GCC and how run through from terminal in both ubuntu and mac os.

Please note that becareful when you choose gcc version, some version doesn't have c++ features.
According  GNU.ORG gcc4.7 supports lots  c++ 11 features.
As of the gcc-4.8 release, gcc-4.7 does not support 8 out of 64 features (See C++0x/C++11 Support in GCC)
  • Language Features
    - Rvalue references for *this
    - Generalized attributes
    - Alignment support
    - Inheriting constructors
    Concurreny
    - Bidirectional Fences
    - Memory model
    - Abandoning a process and at_quick_exit
    - Thread-local storage 
    

Adding the toolchain/test PPA: (if you dont have it)

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-4.8
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 50

Building GCC-4.8 from source:
If you need gcc-4.8 on 12.04 now, your only option is to build it from source.
Please read the GCC installation FAQ prior to installation.
You can download gcc-4.8 from one of gnu.org's mirror sites or directly from their SVN server.
Here is an example of steps to compile from source (see here for additional details.) Note that these may vary depending on your system and preferences.
  1. Download the source code
    • Make a build directory ( mkdir gcc-build && cd gcc-build)
    • Download the source file: wget http://www.netgull.com/gcc/releases/gcc-4.8.0/gcc-4.8.0.tar.bz2 (adjust this command to use an appropriate mirror site.
    • Unzip the file (tar -xvjf <file name>)
  2. Install some additional libraries (sudo apt-get install libgmp-dev libmpfr-dev libmpc-dev libc6-dev)
  3. Compile the source: ./gcc-4.8.0/configure --prefix=/app/gcc/4.8.0
  4. Run make (This will take some time to complete. Go make some coffee, or bake some cookies. ;-))
  5. Install the code: sudo make install
Once this process has completed, run the command gcc --version to verify that the installation has completed successfully. 

Data Structures : Tree Traversals

(Week 2) Tree traversals are one of the most important algorithm in computer science because sometimes we don't have lin...