Febin John James's Blog, page 20

March 14, 2017

How to build a simple meme bot in 30 minutes using Meteor

We are going to build a simple meme bot. It responds with memes according to the sentiment of the topic. Here’s a demo. Get the source code here. If you are interested in making cloud apps. Do checkout my book Cloud Is a Piece of Cake . Get the free chapters here.

Install Meteor

If you are using OSX/Linux

curl https://install.meteor.com/ | sh

If your are using Windows

Download the installer here

Now in your terminal

meteor create simplebot
cd simplebot
meteor npm install
meteor

Now visit http://localhost:3000/

We need six gifs, three for positive and the other for negative sentiment. One of the three gifs is randomly picked and shown.

The six memes must be in gif format with filenames 1.gif,2.gif,….,6.gif and one more with the filename “angry.gif”. We will use the first three for negative and the other three for positive sentiment. (You can use the gifs I used , get them here)

Create a folder named public. Inside that create a folder called gifs. Place the gifs inside it.

For styling let’s add twitter bootstrap. Go to terminal and type the following (Stop meteor using CTRL + C, then execute the following command)

meteor add twbs:bootstrap

Add this package for sentiment analysis

meteor add art1sec8:sentiment

Let us start meteor by typing

meteor

The following code will give us the sentiment of the text written.

sentiment(“I am so Happy”, function( e, result ) {console.log(result.score);});

This will calculate the sentiment for the words “I am so Happy “. Since it’s a positive sentence we get a score above zero. Otherwise we get a score below zero.

Now here’s the code to select random gifs based on positive and negative sentiment . (Read through the code , don’t use it in your files yet.)

var responses = [“God , help us.”,”Let’s scoot”,”Just through it away”,”Danda nakka …”, “Like that huh? ;) “,”Because am happy …”];sentiment($(“#text”).val(), function( e, result ) { if(result.score < 0){ pos = getRandom(1,3); prepareResponse(“/gifs/”+pos+”.gif”,responses[pos-1]); }else{ pos = getRandom(4,6); prepareResponse(“/gifs/”+pos+”.gif”,responses[pos-1]);
}});

In case users don’t input anything or types less words we will show him the angry gif. Here’s the code for that. (Read through the code , don’t use it in your files yet.)

function checkIfBlank(){ if($(“#text”).val() == “”){ $(“#answer”).attr(“src”, “gifs/angry.gif”); $(“#response”).html(“

Can’t you type something ?

”); showResponses(); return false;
} return true;}function checkIfLessWords(){ if($(“#text”).val().split(“ “).length $(“#answer”).attr(“src”, “gifs/angry.gif”); $(“#response”).html(“

Seriously? Type at least six words!

”); showResponses(); return false;
} return true;}

Now, let’s integrate the above code inside a html file . Replace your main.html with the following lines of code

A Simple BotHacker Noon on Medium, where people are continuing the conversation by highlighting and responding to this story.
 •  0 comments  •  flag
Share on Twitter
Published on March 14, 2017 05:07

March 12, 2017

How to change your habits

Charles Duhigg in his book The Power of Habit: Why We Do What We Do in Life and Business explains the habit loop.

The habit loop consists of Cue , Routine and Reward.

Cue can be external or internal. A sudden craving for a piece of cake is an internal cue. External cue is when facebook send you a notification that someone mentioned you.

Routine is the action you take from the cue. Like going to a bakery , ordering a cake and having it.

Reward is the pleasure of having the cake. The cause why brain decides to make you want it in the future.

Breaking the habit loop is simple. All you have to do is change the routine to give you a similar reward. When you have the craving for a piece of cake. Have an apple instead. Sometimes you will have to experiment with different rewards to break the loop. This way you change your bad habit into a good one.

Try making small changes to begin with. If you have the habit of checking your phone when you wake up. Change it by reading a chapter.

Do you know that the same loop is used by Facebook, Pinterest etc to hook you with their products? It’s well explained in the book Hooked: How to Build Habit-Forming Products.

How to change your habits was originally published in Hacker Noon on Medium, where people are continuing the conversation by highlighting and responding to this story.

 •  0 comments  •  flag
Share on Twitter
Published on March 12, 2017 10:44

March 11, 2017

How to avoid the curse of knowledge

The more proficient we are with a topic, the harder it is to communicate with a beginner or a layman. This is due to the curse of knowledge.

If a physicist is trying to explain the movement of electrons. He would say .

Electrons move around the nucleus in probability clouds.

But, our teacher would have taught us the following.

Electrons move around the nucleus like the planet move around the sun.

The first statement was difficult to understand. The physicist assumed that the other person knew about probability clouds. Now, for him to communicate he need to put himself into the mind of a beginner. In other words he need to unlearn things which is not possible.

You can avoid the curse of knowledge by using analogies. When our teachers taught us about electrons they used the analogy of the solar system. It’s something we can relate to. The better we do this the stickier our idea gets as explained in the book Made to Stick.

Why did Jesus tell stories? Because he knew people would understand it better. They were so powerful that generations till date has passed it on.

How to avoid the curse of knowledge was originally published in ART + marketing on Medium, where people are continuing the conversation by highlighting and responding to this story.

 •  0 comments  •  flag
Share on Twitter
Published on March 11, 2017 10:23

March 10, 2017

How changing one habit saved a company

It was 1987 , Aloca wasn’t doing well. That’s when Paul O’Neill was appointed as the CEO.

This is how he began his CEO speech “I want to talk to you about worker safety.”

His concern was the yearly injuries of his workers. They were severe that sometimes they had to skip a day’s work. He explained his vision of having zero injuries and making his company safest workplace. He spoke nothing of profits.

Now, the investors were afraid if he would ruin the company.

By focusing on changing the safety habits. Not only Paul O’Neill succeeded in worker health but increasing revenue by five fold.

You can read the whole story in The Power of Habit: Why We Do What We Do in Life and Business. Changing the keystone habit triggers other productive habits.

For example. I started with the habit of reading books. Later I created the habit of sharing my learnings through blog posts. This is now triggering the habit to write books.

This is how I ended up writing a book. All you need to do is find the keystone habit and improve it. I would recommend you this beautiful book The Power of Habit: Why We Do What We Do in Life and Business by Charles Duhigg.

How changing one habit saved a company was originally published in Hacker Noon on Medium, where people are continuing the conversation by highlighting and responding to this story.

 •  0 comments  •  flag
Share on Twitter
Published on March 10, 2017 06:19

March 9, 2017

Boost your productivity by having order in things you do

This is my learnings from applying techniques of these beautiful books.

1.) Deep Work: Rules for Focused Success in a Distracted World

2.) A Mind for Numbers: How to Excel at Math and Science (Even If You Flunked Algebra)

I have written more about these book here.

Before reading these books, I used to overestimate my mind’s ability. I would never keep a to-do list or think through my day’s work. This resulted in me having a hard time getting things done.

It’s because the mind has no clarity about the next step. This causes confusion. A confused mind drains your energy. You often end up being stressed .

In the book deep work the author asks to schedule time blocks for your day. Here’s my blocks for the day.

One thing to keep in mind while scheduling your day is to be specific about it. Avoid writing generic terms . For Example : Instead of scheduling a block called “reading” make it “read Xth chapter from book X”.

Try this simple technique and your days are never the same.

Do checkout my previous post on productivity. How I tweaked pomodoro technique for better results in productivity.

Boost your productivity by having order in things you do was originally published in Hacker Noon on Medium, where people are continuing the conversation by highlighting and responding to this story.

 •  0 comments  •  flag
Share on Twitter
Published on March 09, 2017 06:58

March 8, 2017

A silly mistake most programmers make

I found this security bug in one of the prominent food startups of India. All their customer data including residential info , order info and contact details were vulnerable.

Exposed Customer Data

Look at the following code.

@app.route(“/customer/info”)
def customer_info():
customer_id = requests.args.get(‘customer_id’)
customer = customers.query.filter(Customer.id==customer_id).one()
customer_schema.jsonify(customer)

A customer of id 5453 will have the following request URL

http://server_ip/customer/info?customer_id=5453

Now look at the URL, the id is a number. A hacker will try changing the number from 5453 to 5454

http://server_ip/customer/info?customer_id=5454

This will allow him to fetch details of the customer with id 5454, which he is not supposed to see. Now he can write a script which loops through customer ids and fetch information; he has hacked into a company’s confidential data.

This can be prevented by adding authentication to check if the user has privileges to access the data. A unique string identifier is much better than an integer identifier.

If you are interested in making cloud apps. Do checkout my book Cloud Is a Piece of Cake :) . Get the free chapters here.

A silly mistake most programmers make was originally published in Hacker Noon on Medium, where people are continuing the conversation by highlighting and responding to this story.

 •  0 comments  •  flag
Share on Twitter
Published on March 08, 2017 10:34

March 6, 2017

How I tweaked pomodoro technique for better results in productivity

Having heard good responses for my previous post, 3 books to help you stop procrastinating. I decided to write about how I tweaked the pomodoro technique.

In short the pomodoro technique is to decide on a task, set a timer for 25–30 mins and work until it rings.

This is a great technique. But, I noticed this works for certain tasks. It’s perfect when I have to read a book or write this post. But, if I were to develop a module for a mobile app, the technique wasn’t effective. In other words the technique didn’t help me for complicated tasks.

The solution “Simplify” is something you have heard a lot. But I have more to add. It’s not enough to simplify. But, I would say simplify it logically.

When you craft a task , make sure it won’t need task switching.

Consider development, We often use a couple of libraries to achieve things. We go search for them and read about them while we code. Here, we are switching from coding to searching and then to reading. It’s a cycle. These switches drains our energy and the more we are prone to procrastination.

The key to achieve productivity is to minify task switching. Instead of coding directly. It would be better to analyse the task, search for the necessary libraries, read about them and then code. Each step done one after the other.

So my tweak to the pomodoro technique is simple. Just prepend one more step. Craft the task to have minimal or no task switching.

“The process of simplifying is complicated”. I am not sure where I heard this. But, something we need to put thought into.

I am such fan of simplicity that I can go on staring at the design of Macbook for hours :P.

How I tweaked pomodoro technique for better results in productivity was originally published in Hacker Noon on Medium, where people are continuing the conversation by highlighting and responding to this story.

 •  0 comments  •  flag
Share on Twitter
Published on March 06, 2017 07:11

March 4, 2017

Benefits of being an innovator in product adoption

I hope most of you are familiar with this curve. For those who don’t know, It’s the product adoption curve. It shows how different consumers adopt a product over time.

You might be an innovator for some products and are already enjoying the perks. But, may be you are unaware of it. For example: The innovators who used medium didn’t have to pay for custom domain. It’s still free for them. Only those who want a custom domain now has to pay.

Great companies consider innovator’s success as theirs. It’s like they have a stake in your company.

Consider electronic gadgets. Do you know that smart innovators get their money back? It’s like they pay nothing for the product. Sometimes they make five to ten times more than their investment for the product.

It would be sane things like product reviews on youtube. Sometimes insane things like destroying Macbook or shooting an Iphone with AK-74. You might think these people are crazy. But fail to notice the view count they get. This converts to money.

My point is not that you destroy gadgets. But as an early innovator you are a star. The later part of the curve wants to hear from you. As I mentioned earlier, you get a lot of perks free or cheap which late majority have to pay for.

So, why not try something new today ?

Benefits of being an innovator in product adoption was originally published in Hacker Noon on Medium, where people are continuing the conversation by highlighting and responding to this story.

 •  0 comments  •  flag
Share on Twitter
Published on March 04, 2017 07:02