Python

Python is powerful… and fast; plays well with others; runs everywhere; is friendly & easy to learn; is Open.

Why the name Python for Python?

When he began implementing Python, Guido van Rossum was also reading the published scripts from “Monty Python’s Flying Circus”, a BBC comedy series from the 1970s. Van Rossum thought he needed a name that was short, unique, and slightly mysterious, so he decided to call the language Python.

5 Reasons why Python is Powerful Enough

  1. Python is Efficient
  2. Python is Fast
  3. Python is Broad
  4. Python is not Python
  5. Python is Easy

I say, pick the language that empowers your domain experts directly.
Pick Python.

Resources

1. Home https://www.python.org/

2. Download
https://www.python.org/downloads/
http://www.activestate.com/activepython

3. PyPI – The Python Package Index
https://pypi.python.org/pypi

4. The Python Tutorials
https://docs.python.org/3/tutorial/index.html
http://www.tutorialspoint.com/python/index.htm

5. Learn Python in one Video
Cover modules, comments, print, arithmetic operators, order of operation, lists, tuples, dictionaries, conditional operators, logical operators, if, else, elif, loops, for, while, break, continue, functions, return, readline(), string operators, file i/o, classes, objects and much more.
http://www.newthinktank.com/2014/11/python-programming/

6. Google Python Class
YouTube PlayList – https://www.youtube.com/playlist?list=PLC8825D0450647509

7. Books
Python Books at it-ebooks.info – http://www.it-ebooks.info/search/?q=python&type=title
Learn Python the hardway, Videos

8. Quick Reference
http://www.astro.up.pt/~sousasag/Python_For_Astronomers/Python_qr.pdf

9. Online Courses
9.1 Programming for Everybody (Getting Started with Python)
https://www.coursera.org/learn/python
https://www.coursera.org/courses/?query=python&languages=en

9.2 Code 401: Advanced Software Development in Python
https://www.codefellows.org/courses/code-401/advanced-software-development-in-python

10. Tools
10.1 PyDev – Python IDE for Eclipse
http://www.pydev.org/
Setting up Eclipse for Python – https://www.youtube.com/watch?v=vHRRiBHI3to

10.2 PyCharm – Python IDE for Professional Developers
https://www.jetbrains.com/pycharm/

10.3 Execute Python online
http://www.tutorialspoint.com/execute_python_online.php

10.4 PDB –  The Python Debugger
python –mpdb <script>
    Commands
        p – print, c – continue, restart, s – step into, n – next, up – finish current function, bt/where – Stack trace
        https://docs.python.org/2/library/pdb.html

11. How to Install Python Package

1. Open Cmd with “Run as administrator.”

  Microsoft Windows [Version 6.1.7601]
  Copyright (c) 2009 Microsoft Corporation.  All rights reserved.
 
  C:\windows\system32>cd \”Program Files”
 
  C:\Program Files>cd “Python 3.5”
 
  C:\Program Files\Python 3.5>cd Scripts
 
  C:\Program Files\Python 3.5\Scripts>pip install ijson
  Collecting ijson
    Downloading ijson-2.2-py2.py3-none-any.whl
  Installing collected packages: ijson
  Successfully installed ijson-2.2

Also see

Interesting Libraries/Frameworks for Linux (C/C++)

 

1. CLISH (Command Line Interface SHell)

A modular framework for implementing a CISCO-like CLI on a *NIX system. Arbitary command menus and actions can be defined using XML files. This software handles the user interaction, and forks the appropriate system commands to perform any actions.
http://clish.sourceforge.net/

2. Libconfig – C/C++ Configuration File Library

Libconfig is a simple library for processing structured configuration files, like this one: test.cfg. This file format is more compact and more readable than XML. And unlike XML, it is type-aware, so it is not necessary to do string parsing in application code.
Libconfig is very compact — a fraction of the size of the expat XML parser library. This makes it well-suited for memory-constrained systems like handheld devices.
http://www.hyperrealm.com/libconfig/

3. libevent – an event notification library

The libevent API provides a mechanism to execute a callback function when a specific event occurs on a file descriptor or after a timeout has been reached. Furthermore, libevent also support callbacks due to signals or regular timeouts.
libevent is meant to replace the event loop found in event driven network servers. An application just needs to call event_dispatch() and then add or remove events dynamically without having to change the event loop.
http://libevent.org/

4. libcurl – the multiprotocol file transfer library

libcurl is a free and easy-to-use client-side URL transfer library, supporting DICT, FILE, FTP, FTPS, Gopher, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMTP, SMTPS, Telnet and TFTP. libcurl supports SSL certificates, HTTP POST, HTTP PUT, FTP uploading, HTTP form based upload, proxies, cookies, user+password authentication (Basic, Digest, NTLM, Negotiate, Kerberos), file transfer resume, http proxy tunneling and more!
libcurl is highly portable, it builds and works identically on numerous platforms, including Solaris, NetBSD, FreeBSD, OpenBSD, Darwin, HPUX, IRIX, AIX, Tru64, Linux, UnixWare, HURD, Windows, Amiga, OS/2, BeOs, Mac OS X, Ultrix, QNX, OpenVMS, RISC OS, Novell NetWare, DOS and more…
libcurl is free, thread-safe, IPv6 compatible, feature rich, well supported, fast, thoroughly documented and is already used by many known, big and successful companies and numerous applications.
http://curl.haxx.se/libcurl/

5. jsmn – Minimalistic JSON parser in C

jsmn (pronounced like ‘jasmine’) is a minimalistic JSON parser in C. It can be easily integrated into resource-limited or embedded projects.
jsmn is designed to be robust (it should work fine even with erroneous data), fast (it should parse data on the fly), portable (no superfluous dependencies or non-standard C extensions). An of course, simplicity is a key feature – simple code style, simple algorithm, simple integration into other projects.
http://zserge.bitbucket.org/jsmn.html

6. libmraa – Low Level Skeleton Library for Communication on GNU/Linux platforms

Libmraa is a C/C++ library with bindings to javascript & python to interface with the IO on Galileo, Edison & other platforms, with a structured and sane API where port names/numbering matches the board that you are on. Use of libmraa does not tie you to specific hardware with board detection done at runtime you can create portable code that will work across the supported platforms.

The intent is to make it easier for developers and sensor manufacturers to map their sensors & actuators on top of supported hardware and to allow control of low level communication protocol by high level languages & constructs.
https://github.com/intel-iot-devkit/mraa

Method Call Interception (MCI) in C++

Method Call Interception (MCI) is the technique of intercepting methods, and performing certain extra, specified, operations before / instead of / after the called method. MCI while not the same as Aspect Oriented Programming is the most common technique, used to implement AOP.

As such MCI is often used for

  • Tracing
  • Code Profiling
  • Transaction management
  • Thread safety (locking)

MCI with VC++

When you compile your code with the /Gh option, the compiler automatically adds a call to a function with the prototypeextern "C" void __declspec(naked) _penter(void);

More…

MCI with GCC

GCC has the -finstrument-functions flag which allows you to define two functions that will be called at the beginning and end of each function call:

  • void __cyg_profile_func_enter(void *this_fn, void *call_site);
  • void __cyg_profile_func_exit(void *this_fn, void *call_site);

More…

Also See

Browsing Source Code with OpenGrok

“A wicked fast source browser”

{OpenGrok is a fast and usable source code search and cross reference engine. It helps you search, cross-reference and navigate your source tree. It can understand various program file formats and version control histories like Mercurial, Git, SCCS, RCS, CVS, Subversion, Teamware, ClearCase, Perforce, Monotone and Bazaar. In other words it lets you grok (profoundly understand) source code and is developed in the open, hence the name OpenGrok. It is written in Java. OpenGrok is an open source project and is distributed under CDDL. OpenGrok uses software libraries from Apache Software Foundation.

Steps to get OpenGrok on Ubuntu and Browsing your source code

1. Install Java and TomCat 7

  • $sudo apt-get install default-jdk tomcat7

In case old version of tomcat is installed, check and uninstall before installing Tomcat 7

  • $dpkg --get-selections | grep tomcat
  • $sudo apt-get purge tomcat*

2. Check the details about tomcat

  • $cd /usr/share/tomcat7/bin/
  • $./catalina.sh

Output

    Using CATALINA_BASE: /usr/share/tomcat7
    Using CATALINA_HOME: /usr/share/tomcat7
    Using CATALINA_TMPDIR: /usr/share/tomcat7/temp
    Using JRE_HOME: /usr
    Using CLASSPATH: /usr/share/tomcat7/bin/bootstrap.jar:/usr/share/tomcat7/bin/tomcat-juli.jar

3. Adding export vars
Edit your ~/.bashrc and include using the directory pointed by CATALINA_BASE include the following vars:
export CATALINA_HOME=/usr/share/tomcat7/
export OPENGROK_TOMCAT_BASE=$CATALINA_HOME

4. Run the tomcat and check if it is working:

  • $sudo /etc/init.d/tomcat7

Done!!! installed!!!! Check if it is running now!!! Using your favorite browser type in the web address: http://localhost:8080/
If ok you should see a web page with message “It works!”

    5. Install C tags

    • sudo apt-get install exuberant-ctags

    6. Installing OpenGrok

    • Download opengrok-0.11.1.tar.gz from java.net/projects
    • unpack into /tools
      $sudo mkdir /tools
      $sudo cd /tools
      $sudo tar –xvzf ~/opengrok-0.11.1.tar.gz
      $sudo chmod 777 –Rv /tools
    • Creating OpenGrok working directories
      $sudo mkdir -p /var/opengrok/src
      $sudo mkdir -p /var/opengrok/data
      $sudo mkdir -p /var/opengrok/etc
      $sudo chmod 777 –Rv /var
    • Deploying Opengrok
      /tools/opengrok-0.11.1/bin$sudo ./OpenGrok deploy
      Alternatively, copy OpenGrok all into Tomcat’s webapp folder
      $sudo cp /tools/opengrok-0.11.1/lib/source.war /var/lib/tomcat7/webapps
    • Checking OpenGrok – Visit http://localhost:8080/source/

    7. Specifying Source folder

    • $sudo cd /var/opengrok/src
    • $sudo ln -s /home/<username>/src_base/ src_base

    8. Indexing your source code

    • $sudo /tools/opengrok-0.11.1/bin/OpenGrok index
      Alternatively, You can invoke with path containing your source code.
    • $sudo /tools/opengrok-0.11.1/bin/OpenGrok index /home/<username>/src_base/

    9. Visit http://localhost:8080/source/ and start browsing your code!!