Posts

Quick Basics of ReactJs, Redux & Redux-Saga

React ( Docs ) React makes it painless to create interactive UIs. Design simple views for each state in your application. React is Declarative: Imperative would say (like JQuery): if (user.likes()) { if(!hasBlue()) { removeGrey(); addBlue(); } } else{ if(hasBlue()) { removeBlue(); addGrey(); } } Declarative would say: if (this.state.liked) { return <bluelike/>; } else{ return <greylike/>; } We now can use ES6 and a summary of features is  http://es6-features.org/ Component Life Cycles: Mounting These methods are called when an instance of a component is being created and inserted into the DOM: constructor() componentWillMount() render() componentDidMount() Updating An update can be caused by changes to props or state. These methods are called when a component is being re-rendered: componentWillReceiveProps() shouldComponentUpdate() componentWillUpdate() render() componentDidUpdate() Unmounting This m...

React - Component testing + End-to-End testing

Image
Introduction There are many test frameworks for testing React app.  Facebook introduced their own Jest framework which helps you run test cases against the React components and also mock some of the flow.  With lot of JavaScript developers in the community also having their due soft corner towards Mocha as their test runner. Lets see the things that are good and can be the right tool for the environment.  This post is basically trying to give more overview about how we can test a react app and ensure to automate the same. Tools for testing components The most favored tools include the Jest and Mocha. There are also plenty of other tools like Jasmine. Now these are all your test runner frameworks which use plenty of other libraries to get their work done, like Chai, Karma, PhantomJS or JSDom. Checking this webpage tells more about the community ​ usage : Talking briefly about Jest and Mocha (which requires other library support to run t...

SSH using Chrome Secure Shell app with SSH identity (private key and public key)

Image
It's something I keep using a lot! The Chrome's Secure Shell app is wonderful and is handy for people who want to use the chrome's tab for connecting to the remote server. So here it is: Install  Secure Shell  from the chrome web app store. Once added, open the app and select "[New Connection]": Enter the details: Remember to change the permission of the pem file, using the following command:  chmod 400 mykey.pem Generate the public key from the private key:  ssh-keygen -y -f mykey.pem > mykey.pub RENAME the private key (.pem) file to remove the extension of the private key ( The most Important :P ). Otherwise, the files won't be accepted by the plugin:  mv mykey.pem mykey Click on the "Import" button beside the Identity in that screen and select both the files: In case you want to Reset the known_hosts  then do the follow...

How to create NPM package for a React component - (using Webpack + Babel).

Recently I was working on creating a NPM package for a react component. Tried my hands on writing a react radio button component, with webpack and ES6. You can checkout the source code in github repository:  https://github.com/tan31989/react-radio-button  and the npm repository link is:  https://www.npmjs.com/package/react-radio-button . Here is a quick update on the webpack I used for production and deploying the react component as a library so that others can use it: webpack.config.build.js const path = require('path'); const webpack = require('webpack'); module.exports = { entry: [ /** This section is basically the hook for letting the webpack scan your code * to find that right set of files to bundle up for the library you would * want to expose. In my case, the file inside src/components is where * I have the file to be provided as a library. * This section is also known as entry point */ './src/components/Radi...

Difference between Python classmethod and staticmethod with a better use case.

Personally, in python I believe, classmethod's and staticmethod's are about the use in terms of the case. When it comes to classmethod and instance method, the point is about you are maintaining a state (variables) to be processed. Couple of days back, I was working on the payment gateway implementation and have come across this best way to understand how to know what is good for the situation. Let's say we have three class, BasePaymentGateway FirstPaymentGateway SecondaryPaymentGateway Now, the BasePaymentGateway provides all the signature which the other payment gateways can follow. Considering the fact that each payment gateways will have their own settings and hence we need to fetch the settings from their respective item. # paymentgateway.py import settings import some_util class BasePaymentGateway(object): @staticmethod def get_payment_settings(): """Provides the settings for the given item""" ...

Setting up CRON via a python script without using external library

What is the best tool in computer that can do your job automatically and is something which otherwise, if not there would involve manual intervention? Life around computer is increasingly getting more complex with our lifestyle demanding more of automated work. Out of philosphy let's face it, we need tools that we can set up for doing tasks for us, run scripts for us whenever we want. When it comes to schedulers, it's like an alarm clock or a timer which goes of for whatever time we set it and then ensure we do our tasks. Now, in the world of Linux, we know this schedulers at system level as Cron. Cron is a system daemon which is used to execute desrired tasks (in the background) at specific designated time. It is used to schedule jobs (commands or shell scripts) to run periodically at fixed times, dates, or intervals. It typically automates system maintenance or administration Now, thinking of cron, it's a name we use, when we have to schedule a task. Now, I am ...

NGinx + Gunicorn + Flask-SocketIO based deployment.

It's been a long time I wrote a blog post!. Recently I realized I should at least write about my unwarranted account of solving problems which were hard, to just get some information online. So this post provides the details we need to know how to deploy the Flask-SocketIO app using Gunicorn and NGinx. Here are the links for NGinx , it is a web server with a focus on high concurrency, performance and low memory usage. Gunicorn 'Green Unicorn' is a Python WSGI HTTP Server for UNIX and Flask-SocketIO  gives Flask applications access to low latency bi-directional communications between the clients and the server. The client-side application can use the SocketIO Javascript library or any compatible client to establish a permanent connection to the server.  Version's I used: Nginx : 1.6.0 (Websocket support in Nginx was introduced in version 1.4 and above) Gunicorn : 17.5 Flask-SocketIO : 0.6.0 If you go through the document's of the tools, you will com...

Dijkstra's algorithm in OpenGL - Network simulation

Image
I and my friend late Mr. Padmaprasad Kusagundi (will always miss him), had created an OpenGL project for the syllabus in our college, G.I.T, college, Belgaum, Karnataka, India. We had worked day and night over this. The github repo is here:  https://github.com/tan31989/Dijkstra-opengl-network-simulation This project has used basic programming elements of OpenGL. Here we used   Dijkstra's algorithm  and modified it to any source to any destination (as opposed to single source and all the destination). The nodes of which looks like a box in here are hard coded as, we never had a chance to take it to the next level. (PS: hoping to increase its vicinity). The distance matrix, also was fixed in the code, to make it dynamic was just another step, but again, we kept it low :). When the program is run, it asks to select the source and a destination and later step to find the shortest path between the given source and the destination. The packets that ar...

Learning computer with low cost - Use open source OS.

Ever since i entered the stream of Computer Science, I use to always wonder how can an average person pay for all the software's when it comes to learning computer. As we know that for many years Microsoft ruled the computer software's, its not the same now. I mean for one to learn computer usage with Window (XP/Vista/7) it will cost him as either you need to buy the software for your use or you need to explore the knowledge in computers by visiting some computer academia. But this is not the best way one can experience learning. Then there is free software which are build by a group or might have even by a single person. When i talk about free software, its not just any application but entire Operating System(OS) like LINUX based Operating systems. For information on Linux based visit here --  WIKI Here we see that people contribute to develop a community based systems which is widely available for end users and also the users feedback to improve the bugs   if ...