Friday, November 2, 2018

API fun


Rest lacked standards
https://dzone.com/articles/rest-api-documentation-part-1

in general an API has various “resources” that you access through “endpoints.” The endpoints give you access to the resource. (But terminology isn’t standard, so expect variety.
https://idratherbewriting.com/learnapidoc/docapis_resource_descriptions.html

The endpoints indicate how you access the resource, and the method used with the endpoint indicates the allowed interactions (such as GET, POST, or DELETE) with the resource...Path parameters (represent them through curly braces) are part of the endpoint itself, and are not optional.
https://idratherbewriting.com/learnapidoc/docapis_resource_endpoints.html


Parameters are options you can pass with the endpoint (such as specifying the response format or the amount returned) to influence the response. There are four types of parameters: header parameters, path parameters, query string parameters, and request body parameters
https://idratherbewriting.com/learnapidoc/docapis_doc_parameters.html

curl is a command-line utility that lets you execute HTTP requests with different parameters and methods. Instead of going to web resources in a browser’s address bar, you can use the command line to get these same resources, retrieved as text.
https://idratherbewriting.com/learnapidoc/docapis_install_curl.html


REST APIs follow an architectural style, not a specific standard. However, there are several REST specifications that have been developed to try to provide some standards about how REST APIs are described.
https://idratherbewriting.com/learnapidoc/pubapis_rest_specification_formats.html


With OpenAPI (Swagger), instead of XML, you have set of JSON objects, with a specific schema that defines their naming, order, and contents. This JSON file (often expressed in YAML instead of JSON) describes each part of your API. By describing your API in a standard format, publishing tools can programmatically ingest the information about your API and display each component in a stylized, interactive display.
https://idratherbewriting.com/learnapidoc/pubapis_swagger_intro.html










Swagger editor
http://editor.swagger.io/

YAML refers to “YAML Ain’t Markup Language,”

https://swagger.io/tools/swagger-codegen/ is one of the code generators , but SmartBear who does SoapUI is supported.

display framework that reads an OpenAPI specification document and generates an interactive documentation website. This tutorial shows you how to use the Swagger UI interface and how to integrate an OpenAPI specification document into the standalone distribution of Swagger UI
https://idratherbewriting.com/learnapidoc/pubapis_swagger.html








The link for a good example
https://howtodoinjava.com/swagger2/swagger-spring-mvc-rest-example/

Or making a rest call using RestTemplate programatically:
https://spring.io/guides/gs/consuming-rest/

For example, I did this project example https://spring.io/guides/gs/rest-service/ and converted it to swaggerness and got json format with http://localhost:8080/v2/api-docs . Was able to get yaml with https://www.json2yaml.com/


Building a back-end API layer introduces a whole new area of challenges that goes beyond implementing just endpoints. You now have clients which will now be using your API. Your clients will need to know how to interact with your API. In SOAP-based web services, you had a WSDL to work with. This gave API developers an XML-based contract, which defined the API. However, with RESTFul web services, there is no WSDL. Thus your API documentation becomes more critical. API documentation should be structured so that it’s informative, succinct, and easy to read. But best practices on, how you document your API, its structure, what to include and what not to is altogether a different subject that I won’t be covering here"
https://dzone.com/articles/spring-boot-restful-api-documentation-with-swagger
https://www.infoq.com/presentations/doc-restful-api


API First Swagger Top Down approach
https://www.easyitblog.info/2017/01/08/api-first-approach-with-swagger/
"There are a lot of good API design tools. Here are some useful comcparisons"


need to add spec for API. How can we do this in Apigee, do we have option to create swagger documentation for REST service in Apigee or we have to use other tool to prepare documentation and create spec in Apigee by importing doc created using third party tool, if documentation is out of box solution in Apigee. If Api documentation possible in Apigee. Please share how to implement this.
https://community.apigee.com/questions/53011/rest-service-documentation.html

https://community.apigee.com/articles/25770/openapi-spec-swagger-spec-generator-a-tool-to-gene.html using SmartDocs The tool you can use is http://specgen.apistudio.io/


https://swagger.io/tools/

https://www.xoriant.com/blog/product-engineering/swagger-specification-code-generation.html

Sunday, February 11, 2018

Vision Video


Getting started with video:
http://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_gui/py_video_display/py_video_display.html#display-video


The following example will load up a video from disk . It uses the VideoCapture object.
  • Its argument can be either the device index or the name of a video file. Device usually is the index is just the number to specify which camera to use.  This line below sets the video source to use an existing file.


#------------------------------------------------------------
import numpy as np
import cv2 as cv
cap = cv.VideoCapture('output.mp4')
while(cap.isOpened()):
       ret, frame = cap.read()
       gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
       cv.imshow('frame',gray)
       if cv.waitKey(1) & 0xFF == ord('q'):
             break
cap.release()
cv.destroyAllWindows()

#------------------------------------------------------------

[link]  - tweak for VideoCapture

VideoWriter([filename, fourcc, fps, frameSize, isColor)
  • filename – Name of the output video file.
  • fourcc – 4-character code of codec used to compress the frames. 
  • fps – Framerate of the created video stream.
  • frameSize – Size of the video frames.
  • isColor – If it is not zero, the encoder will expect and encode color frames, otherwise it will work with grayscale frames (the flag is currently supported on Windows only).


The read() function

  • reads one frame from the video source, which in this example is the webcam. 

This returns two things:
  • The actual video frame read (one frame on each loop) 
  • A return code (True/False). If frame is read correctly.  It tells us if we have run out of frames, which will happen if we are reading from a file. This doesn’t matter when reading from the webcam, since we can record forever, so we will ignore it.
Reading from web camera:

#------------------------------------------------------------
while(True):  
     # Capture frame-by-frame  
     ret, frame = cap.read()  
    # frame come here  
    gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)  
 
    # Display the resulting frame  
    cv.imshow('frame',gray)  
    if cv.waitKey(1) & 0xFF == ord('q'):      
          break

# When everything done, release the capture
cap.release()
cv.destroyAllWindows()

#------------------------------------------------------------


Saving images from video camera input to a file:

#------------------------------------------------------------

import cv2
import numpy as np
#This line sets the video source to the default webcam, which OpenCV
cap = cv2.VideoCapture(0)
w = cap.get(cv2.CAP_PROP_FRAME_WIDTH);
h = cap.get(cv2.CAP_PROP_FRAME_HEIGHT);
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
out = cv2.VideoWriter('output.mp4',fourcc, 15.0, (int(w),int(h)))

while True:
        ret,frame = cap.read()
        #---------for gray video--------
        gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
        out.write(frame)

        #Display the resulting frame
        cv2.imshow('myvideo',frame)
        cv2.imshow('myvideo',gray)
        cv2.waitKey(0)      
        k = cv2.waitKey(0) & 0xFF
        if k == ord('q'):    # wait for 'q' key to exit break
                break
cap.release()
out.release()
cv2.destroyAllWindows()


#------------------------------------------------------------

Saturday, February 10, 2018

Vision Overview

In my earlier Python post I mentioned how easy is to install Open CV

OpenCV is the most popular library for computer vision. Originally written in C/C++, it now provides bindings for Python. OpenCV uses machine learning algorithms to search for faces within a picture. For something as complicated as a face, there isn’t one simple test that will tell you if it found a face or not. Instead, there are thousands of small patterns/features that must be matched. The algorithms break the task of identifying the face into thousands of smaller, bite-sized tasks, each of which is easy to solve
Here is what you can do with OpenCV

Well before we start mentioning the provided examples on web site, it is good to have the API search tool - i.e. reading and writing images API


Here as part of the gui features we will read an image from disk. Likewise, we can write a copy of the image to the disk.

Here are some of the methods we will use:

imread
  • file name
  • flag on way image should be read
imshow
  • named window name
  • image
imwrite
  • file name on disk
  • image



#------------------------------------------------------------
import cv2
import numpy as np

#practice numpy
#https://www.w3resource.com/python-exercises/numpy/index.php#EDITOR

# IMREAD_GRAYSCALE = 0
# IMREAD_COLOR = 1
# IMREAD_UNCHANGED = -1

 img = cv2.imread('img.JPG',cv2.IMREAD_GRAYSCALE)

# ----------showing with opencv.........

cv2.imshow('my image',img)
k = cv2.waitKey(0) & 0xFF

if k == 27: # wait for ESC key to exit
      cv2.destroyAllWindows()
elif k == ord('s'): # wait for 's' key to save and exit
       cv2.imwrite('img2.JPG',img) # writing the image
       cv2.destroyAllWindows()

#------------------------------------------------------------





  •  mouse as paint brush
  •             https://docs.opencv.org/master/db/d5b/tutorial_py_mouse_handling.html


    Wednesday, February 7, 2018

    python everywhere

    Python seems like the hot thing. I have been learning and experimenting.

    I use The following package manager for macOS:  https://brew.sh/

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

    use example: - brew install python

    anaconda https://www.youtube.com/watch?v=8JiWEZEnJ40

    Install anaconda:

    • https://repo.continuum.io/archive/Anaconda3-4.2.0-Windows-x86_64.exe 
    • https://repo.continuum.io/archive/Anaconda3-4.2.0-MacOSX-x86_64.pkg


    condo update anaconda

    to install opencv:

    conda install --channel https://conda.anaconda.org/menpo opencv3

    confirm the install from python command line
            import cv2
            cv2.__version__

    spyder is an IDE for perl - for macOs from the cmd line enter to start it:
                spyder&

    console : print "hello"
    editor: run by select f9
    inspector : debugging

    see spyder perl tutorial https://www.youtube.com/watch?v=J5GevIHNctM


    http://www.numpy.org/
    • https://www.w3resource.com/python-exercises/numpy/index.php

      https://www.scipy.org


    active state
    python tutorial https://pythonprogramming.net/introduction-to-python-programming/

    https://www.youtube.com/watch?list=PLQVvvaa0QuDe8XSftW-RAxdo6OmaeL85M&time_continue=163&v=IX6mc9l6tY4

    https://www.youtube.com/watch?v=5aP9Bl9hcqI

    https://docs.cs50.net/2016/fall/notes/8/week8.html
    https://www.cs.cornell.edu/courses/cs1110/2017fa/lectures/index.php 
    python class http://stanfordpython.com/#lecture
    http://arc-ts.umich.edu/mini-course-introduction-to-python-sept-11-14/ python https://stanford.edu/~schmit/cme193/ python

    https://github.com/wgong/py4kids

    Monday, December 15, 2014

    Firebase

    firebase joins google - g+ page  why

    three way binding:

    We can synchronize our data back to Firebase by using the following methods provided by the $firebase object.


    • $add(value)
    • $remove([key])
    • $save([key])
    • $save()
    • $child(key)
    • $set(value)


    create a free account

    Once you are logged in, you can view your url  on https://www.firebase.com/account/#/

    https://www.firebase.com/tutorial/

    https://www.firebase.com/docs/web/quickstart.html

    https://www.firebase.com/docs/

    plunkr demo #1

    https://www.firebase.com/docs/web/guide/understanding-data.html

    Friday, December 5, 2014

    client side reorder list

    I am looking into jquery ui drag and drop grid row

    http://jqueryui.com/sortable/

    Enable a group of DOM elements to be sortable. Click on and drag an element to a new spot within the list, and the other items will adjust to fit. By default, sortable items share draggable properties

    http://api.jqueryui.com/sortable/

    options:
    items: Specifies which items inside the element should be sortable
    handle:Restricts sort start click to the specified element.

    events:
    stop( event, ui )Type: sortstop This event is triggered when sorting has stopped


    example : http://plnkr.co/edit/jpxc42tF55jktfI3upTE?p=preview 














    Tuesday, November 18, 2014

    Links i have learned about lately


    https://github.com/gregturn/spring-a-gram - Spring Boot, Spring Data, Spring Rest and JQuery UI (see GalleryRepository class , PagingAndSortingRepository)

    Nodevember
    - http://nodevember.org/#speakers
    - http://nodevember.org/#speakers