Sunday, 10 December 2017

Web Graphics 2


SVG

  • Resolution independent
  • Support for event handlers
  • Best suited for applications with large rendering areas (Google Maps)
  • Slow rendering if complex (anything that uses the DOM a lot will be slow)
  • Not suited for game applications

























SVG
Sorry, your browser does not support inline SVG.



Differences Between SVG and Canvas

  • SVG is a language for describing 2D graphics in XML.

  • Canvas draws 2D graphics, on the fly (with a JavaScript).

  • SVG is XML based, which means that every element is available within the SVG DOM. You can attach JavaScript event handlers for an element.

  • In SVG, each drawn shape is remembered as an object. If attributes of an SVG object are changed, the browser can automatically re-render the shape.

  • Canvas is rendered pixel by pixel. In canvas, once the graphic is drawn, it is forgotten by the browser. If its position should be changed, the entire scene needs to be redrawn, including any objects that might have been covered by the graphic.


  • Web Graphics 1


    Using Canvas and SVG



    Canvas

    • Resolution dependent
    • No support for event handlers
    • Poor text rendering capabilities
    • You can save the resulting image as .png or .jpg
    • Well suited for graphic-intensive games

    Your browser does not support the HTML5 canvas tag.




    Your browser does not support the HTML5 canvas tag.



    Your browser does not support the HTML5 canvas tag.



    Your browser does not support the HTML5 canvas tag.



    Your browser does not support the HTML5 canvas tag.



    Your browser does not support the HTML5 canvas tag.



    Your browser does not support the HTML5 canvas tag.

    Image to use:






    Monday, 30 October 2017

    JavaScript Job Interview Questions & Answers



     JavaScript  Exercises for Programming Job 


    The start of 2017 has seen immense growth in demand for developers, as front end developers, full stack developers, mobile developers, and back end developers are all currently in the top 10 hardest to fill tech jobs, according to data from job search site Indeed.com. The following are among the most in-demand positions in software companies this year

    • JavaScript Developers
    • Web Developers (PHP with Laravel or Symfony, Ruby on Rails, Python Django )
    • Mobile app developers
    • Information security software developers
    • Internet of Things (IoT) developers
    • Cloud developers
    • Full stack developers
    • Machine learning developers
    • DevOps engineers
    • UX/UI developers


    JavaScript is perhaps the hottest skill programmers need to know in 2017 and 2018. Currently, the hottest programming jobs are anything that has to do with any of the JavaScript frameworks:  AngularJS, React.JS, Vue.JS and on the server side, Node.JS. Thus, companies are developing with all of these and it is turning out to be very difficult finding programmers to fill these roles. According to TechRepublic, With more companies exploring and developing products to support the possibilities unlocked by the latest hi-techs—virtual/augmented reality, machine learning, artificial intelligence, and autonomous vehicles—there will be a corresponding demand for developers that can write software to support them.

    In this post, I will explore with you some key technicalities you need to polish up your JavaScript skills to brace up for these job interviews. You would find the source codes here

     JavaScript  Job Interview Questions  1

    You have an array of objects in JavaScript. Each one contains a name (a string) and ranking (a number). Write two functions, one to return the objects ordered by ranking and another to return the average ranking.

    // A function to return average ranking











     JavaScript  Job Interview Questions 2



    Write a function: function solution($A); that, given an array A of N integers, returns the smallest positive integer (greater than 0) that does not occur in A.
    For example, given A = [1, 3, 6, 4, 1, 2], the function should return 5.
    Given A = [1, 2, 3], the function should return 4.
    Given A = [−1, −3], the function should return 1.
    Assume that:
    • N is an integer within the range [1..100,000];
    • each element of array A is an integer within the range [−1,000,000..1,000,000].
    Complexity:
    • expected worst-case time complexity is O(N);
    • expected worst-case space complexity is O(N), beyond input storage (not counting the storage required for input arguments).
    Elements of input arrays can be modified.








    Sunday, 29 October 2017

    Dual Installations of Python 2.7 and Python 3.6 with Anaconda & Spyder



    Dual Installations of Python 2.7 and Python 3.6 with Anaconda/Spyder


    Anaconda is a cross-platform python distribution that comes with three IDEs through the Anaconda Navigator: 

    • jupyterlab 0.27: An extensible environment for interactive and reproducible computing, based on the Jupyter Notebook and Architecture 
    • notebook 5.0: Web-based, interactive computing notebook environment. Edit and run human-readable docs while describing the data analysis 
    • spyder 3.2 Scientific python Development Environment. Powerful Python IDE with advanced editing, interactive testing, debugging and introspection features.



    It is one of the best way to go about Python programming. The only issue is switching between difference versions of Python. A very common reason you would want to do this is testing code to verify that it runs in both Python 2.7 and Python 3.6, say for instance. Alternatively, some Python packages have only been developed for a previous version of Python, so it can be extremely useful to be able to switch to an older version of Python, run some legacy code, then post-process the results in a more “modern” Python version.
    You can solve the challenge easily in two ways:

    1. Have both Python versions installed independently
    2. Installed one and then create a virtual environment to install the other(s)


    A.    Having both executables always instantly available

    If you prefer to have both executables always instantly available from the command line. The you may have to install both Anaconda2 and Anaconda3 separately. Follow these steps:
    1.      Install Anaconda2 and Anaconda3 to the C:\ drive as "C:\Anaconda2\" and "C:\Anaconda3\" respectively.
    2.      Edit your "Path" environment variable (Control Panel -> System and Security -> System -> Advanced system settings -> Environment Variables) and make sure that "C:\Anaconda2;C:\Anaconda2\Scripts;C:\Anaconda2\Library\bin" is in front of "C:\Anaconda3;C:\Anaconda3\Scripts;C:\Anaconda3\Library\bin".
    3.      Copy and rename the file "C:\Anaconda3\python.exe" to "C:\Anaconda3\python3.exe".
    4.      Copy and rename the file "C:\Anaconda3\Scripts\conda.exe" to "C:\Anaconda3\Scripts\conda3.exe"
    5.      Copy and rename any other scripts you might use in "C:\Anaconda3\Scripts\", such as "pip.exe" to "pip3.exe", etc.
    Now, when you type "python" or "conda" at the command line you will get the python2 version, and when you type "python3" or "conda3", etc. at the command line you will get the python3 version.

    B.    Switch the virtual environment  

     In this case, you first use the Anaconda prompt to create a “virtual environment” for each version of Python that we want. A virtual environment is a Python island–it is a version of Python that is completely isolated from other Python installations. The packages and dependencies for each environment are completely unconnected from other virtual environments, which makes it very useful for switching between codes with different dependencies.
    In the tutorial below, I will assume that we want a 2.7 Python version and a 3.6 Python version to coexist in the same machine. You can install any number of versions–it all up to you! Once the different versions are installed, you simply open whichever version of Spyder corresponds to the version of interest at that time. It is seriously dead simple.

    Tutorial

    This tutorial draws very heavily from this page of the “Life of a Jenni”, so many thanks to her for providing very useful tips!

    Step 1: Install Anaconda

    To check if you have Anaconda installed, open a Windows command prompt and type
    conda -V
    and hit enter. If no error is returned, Anaconda is installed.
    I recommend a clean install of Anaconda, especially if you tried to manually install Python before installing Anaconda. Windows is not forgiving when it comes to messing with paths/dependencies/etc., so if you have any issues with the remainder of this tutorial, I recommend uninstalling Anaconda, making sure there are no Python distributions in your C:\ drive, then clean-installing Anaconda.
    You can download the Anaconda installer here. It doesn’t really matter what version of Python you choose to install with Anaconda , since you can always create a virtual environment with an older version. However, I would recommend installing the most up-to-date distribution because it’s generally better to be on the curve than behind it.

    Step 2: Check conda is up-to-date

    If you haven’t yet, open a Windows command prompt. Enter the following command
    conda update conda
    then enter “y” if prompted to accept the packages that need to be updated.

    Step 3: Create your virtual environments

    Let’s assume we want two virtual environments: one for Python 2.7 and one for Python 3.6. It is possible that the root environment (i.e., the one that was initially installed with Anaconda) is one of those distributions. You can check your default Python by simply entering
    python -V
    into the command prompt and seeing what version number pops up. I like to keep my versions clearly separated, so in this tutorial I will create two new virtual environments, one for each desired version. This is beautifully simple thanks to Anaconda:
    conda create -n python27 python=2.7 anaconda
    followed by
    conda create -n python35 python=3.6 anaconda
    With these commands, we have created two virtual environments: one named “python27” and one named “python35”. You can name your virtual environments whatever you want; I chose these names based on my preference. We can verify what virtual environments we have on a given machine by entering
    conda info -e
    into the command prompt.

    Step 4: Open Spyder for desired environment

    This step is the one I couldn’t find on the internet, and it is by far the easiest. If we have virtual environments for each version of Python, how do we switch from one version to the other in Spyder? I first tried to change the Python interpreter (Tools -> Preferences -> Python interpreter in Spyder 3.1) so that it pointed to my 3.6 interpreter instead of my 2.7 interpreter. This prompted a warning from Spyder that I was “doing it wrong”. (Classic Rinker move.) I then poked around a bit before I realized…
    Anaconda had already installed new versions of Spyder to go with each virtual environment I had created. Yes, holy crap, it was that easy.
    So, if you need to run some 2.7 code–just go to the Anaconda folder in your Start Menu and choose the Spyder that corresponds to your python27 virtual environment. (It’s clearly indicated in parentheses next to the program name.) You can even pin different Spyders to your task bar if you need access to them quickly. Seriously, I was quite delighted when I found out how easy this was.


    Some Useful Conda Commands

    Here is a collection of useful Windows commands for working with conda and virtual environments in the command prompt. Please leave a comment below if there’s a useful conda command I missed, and I’ll add it to the list (with credit, of course!).
    Update conda:
    conda update conda
    Update Spyder for root environment:
    conda update spyder
    Update Spyder for virtual environment $ENV_NAME:
    conda update -n $ENV_NAME spyder
    List available virtual environments:
    conda info -e
    Install package $PKG_NAME in virtual environment $ENV_NAME using conda:
    conda install -n $ENV_NAME $PKG_NAME
    Install package $PKG_NAME in virtual environment $ENV_NAME using pip (Anaconda prompt in Windows):
    activate $ENV_NAME
    pip install $PKG_NAME
    deactivate
    Update package $PKG_NAME in virtual environment $ENV_NAME:
    conda update -n $ENV_NAME $PKG_NAME
    Update all packages in virtual environment $ENV_NAME:
    conda update -n $ENV_NAME --all
    Create a new virtual environment $ENV_NAME with Python version X.X:
    conda create -n $ENV_NAME python=X.X anaconda
    Delete virtual environment $ENV_NAME:
    conda remove -n $ENV_NAME -all
    Activate virtual environment $ENV_NAME in Windows command prompt:
    activate $ENV_NAME
    Exit virtual environment $ENV_NAME in Windows command prompt:
    deactivate