Skip to main content

Posts

Concurrency in Go - Visualization

In this blog, let us discuss a program to visualize concurrency in Golang. Reference and source: Program 1: import " fmt " import " time " func main () { var Ball int Ball = 5 table := make ( chan int ) go player (table, 1 ) go player (table, 2 ) fmt. Println ( " mainstart: " , Ball) table <- Ball time. Sleep ( 1 * time. Second ) endres := <- table fmt. Println ( " mainend: " , endres) } func player ( table chan int , playernumber int ){ for { ball := <- table fmt. Println (playernumber, " : " ,ball) ball++ time. Sleep ( 100 * time. Millisecond ) table <- ball } } /* ---------------------------------------------------------------------------------------------------------- Explanation: Please try to visualize on your own before reading the explanation. We will name the two goroutines that are called as player1_goroutine
Recent posts

Deploying a python web app to Google Cloud.

This is the place to start if you already have some experience in python, virtual env, flask. If you want to have some hands-on on how to deploy a simple python based flask app in Google Cloud. please refer to the following link. https://cloud.google.com/appengine/docs/standard/python/getting-started/python-standard-env The link provides all the instructions to get your python app up and running. Here are some points to be noted when you are doing this activity. The standard environment only works with python2.7 and not with python 3.5 and above. If you have already installed python3.5, please perform an alternate install of python2.7 as well.  If you're an active developer who had been developing using python3.5 and don't want to modify the python3.5 to python symlink on your machine, please perform the above testing activity in a python virtual env. You need to create the virtualenv folder using python2.7 explicitly using the following command  $ virtualenv -p /u

Good programming practices

Over the past few days, I have been pondering over the fact that despite having a good hold on OOPs concepts and apply them while writing code to solve a particular use case, I am still not writing good code. I have been coding for almost 6 years now. 2+ years of professional coding. When I was in college, I was a wild programmer solving programming contests, DS problems. What I mean is that I only coded to solve the problem, did a lot of dirty coding. I never bothered if the code can be reused, if someone else or I myself can understand it if I looked at it after a few days. I did have a good habit of writing comments.  When I joined work, I learned many different aspects of how the code was written. Many facts were taken into consideration like code maintenance, reusability, testing etc. I still remember a co-worker who told me if you need to write 10 lines of beautiful code, you should have seen 1000s of lines of amazing code. Due to the pressure of getting things done,

Using python script, send a message to CISCO spark user when a certain event happens

CISCO spark has exposed few APIs that enable us to send a message to a certain email ID. Another good part is that, instead of sending the message from a certain user, you can create a Spark Bot and then send a message to the required user from the bot's ID. If you have a spark account, you can access the tutorials here and have fun. https://developer.ciscospark.com/getting-started.html Creating a bot instructions are available here: https://developer.ciscospark.com/bots.html I have tested these APIs and sent messages to myself from the bot's ID using Postman and a simple python script. You can download postman from the following link: https://www.getpostman.com/  and run the apis or run them directly from the interactive Rest API terminal that is present in one of the submenus in the above-mentioned link. You should try various other options as well.  The Python script to send spark message: import json import requests if __name__=="_

Image Recognizer App (WIP)

This was done for image identification of any particular classification of images that are identified by a script trained on data sets and has the intelligence to identify a good number of objects and give generic info about it. The overview of the idea is to create an image that captures an image and delegates it to a server where the script(ML trained script) is present and get the processed result and publish it to the user. The delegation method is via a rest call from the app to the server port where the script is running. The current plan is to run a python flask app in a certain port in the localhost and make Rest calls from the app(In the form of threads that run in the background.) and process information obtained from the server and store it in the database. Step 1: Building a simple hello world flask app. Python flask app build tutorial - https://code.tutsplus.com/tutorials/creating-a-web-app-from-scratch-using-python-flask-and-mysql--cms-22972 Step

Cycling to Dommasandra - 25km circuit

The following blog post not only inspired me to go for more cycling trips and write regularly because of some valuable, loving comments from friends, it also motivated many of my friends to try it out. https://rkinsideout.blogspot.in/2017/10/the-one-where-raj-went-for-cyclingfirst.html I and my close friend Padma whom I have known from my school days decided to go for cycling. The following week was a Diwali week and most of our friends' had already started leaving to hometowns. We decided to do it anyway. I chose a circuit behind Kadubeesanahalli, Sarjapur as I knew it would be pleasant and also have seen people cycling in these places. The Circuit It was a pleasant ride as it was cloudy was most of the time. From Panathur to Sarjapur road, there were more vehicles on the road, but after Carmelaram, there were fewer people on the road. The road condition also was good till Dommasandra with few patches here and there. Since the road was good, the bigger vehicles were spe

Python run watchdog along with a flash app

The pre-requisite for understanding this blog post would be the following post. Please go through the following to set the context to understand what is discussed in this post. https://rkinsideout.blogspot.in/2017/10/implementing-file-monitoring-script.html Problem : The flask app was running and was responding to a bunch of curl commands. This was single process thread that was working. When the watchdog api was integrated and initiated with the flask program, the problem was that the watchdog thread was started and the flask app was never started. It was started only when the watchdog thread ended. Since we want both the threads to be running, the watchdog process has to run in the background and the flask app to should run normally so that both functionalities are available for use. Python thread and threading are the options available. The "thread" starts a thread and waits for it to complete before proceeding with the rest of the flow to get execute