SSSSSnake – HTML Canvas

I still have memories of playing this game in college backbenches. Never thought of developing this game until last week.  It took me two days and just 400 lines of code to write the whole game using HTML Canvas and Javascript. My take on the first mobile game that I played.

Play the game here https://bemineni.github.io/app/lotus_naga/index.html

snake

 

ELDAM 1.4.0 released

ELDAM 1.4.0 released. With the new radical change in Elastic Search to drop mapping types, we had to do some changes to the ELDAM library. The add item API will now automatically create an index, if it doesn’t exist during commit phase. In 6.0 only one mapping can be defined for each index.

  • Support for Elastic Search 6.x.
  • If cluster contains any 6.x nodes, then add document API will automatically create the index, if it doesn’t exist
  • refresh() function to refresh indices

https://pypi.python.org/pypi/eldam/1.4.0

Latest documentation

http://eldam.readthedocs.io/en/latest/

Lotus Image Crop plugin

For live demo https://bemineni.github.io/app/lotus_imagecrop/index.html

Lotus Image crop jQuery plugin. A plugin that you can use in your web page to visually crop an image. Once the user finishes his selection, we can retrieve the width, height, x position, y position and zoom values to crop the image using any of image processing libraries like pillow, imageJ, and Magick++ etc..

Code on GitHub: https://github.com/bemineni/lotus-imagecrop

$(".lotus-image-container").lotusImageCrop({'onchange': function(top,left,zoom,width,height){
     $("#x-position").val(left.toString())
     $("#y-position").val(top.toString())
     $('#zoom').val(zoom)
}})

$("#increase").on('click',function(e){
    $(".lotus-image-container").lotusImageCrop('increaseZoom')
    e.preventDefault();
})

$("#decrease").on('click',function(e){
    $(".lotus-image-container").lotusImageCrop('decreaseZoom')
    e.preventDefault();
})

 

 

Egg Fried Rice

D7250958-5431-431C-B2D5-44CEC8FF4F90

My first cooking blog of one of my favorite food Egg Fried Rice. I have seen many variations of making this dish. There is the authentic Chinese version, Spicy Indian version, Thai version with peanuts and Singapore version. This is my first attempt making the simple and easy Chinese version. Let’s start with the ingredients

Ingredients

  • Cooked Rice (1 Cup)
  • Garlic minced
  • Springs onions chopped
  • One Carrot chopped
  • One capsicum
  • One medium sized onion chopped
  • Green peas
  • Black pepper
  • Soy sauce
  • Fish sauce
  • Eggs
  • Oil
  • Salt

Optional

  • Sesame oil

 

Preparation

Let’s start by making some scrambled eggs. Add some oil, break two eggs onto the frying pan, add some pepper and scramble the eggs. Transfer the scrambled eggs onto a plate.

Add some oil and fry the minced garlic.

0A06B246-8257-426D-8E5B-3EC8385D9E19

Add onions fry until they are golden brown

0E695AFE-8D3F-4126-AA62-C528D7223B9A

Add carrots and capsicum and fry for some time

D603F2BD-8A60-4FCF-A967-ED192B31E60A

Add some salt to the vegetables, so that they don’t taste bland

6BBCA255-4554-4219-A761-9DF7140EB609

Add green peas and fry until cooked

5302B58D-61AD-4C5C-89EF-F821B55F3A3C

Add cooked rice

772392AC-6052-4B19-A011-0FDB282D1463

Add some black pepper

AFC79571-2D8B-4940-B9D2-F564F9575CF1

Add some soy sauce

056E35A4-5A2B-4B56-889D-6AE2F2B7FB12

Stir rice and all the ingredients until they are mixed well

34B93078-209A-461E-91AD-16ECDDC7C0EC

Now add some fish sauce half a teaspoon.

4A33032B-9346-4A4E-A1D4-4C794038C73B

Add some salt as needed. Caution – Both soy sauce(if salted) and fish sauce contain salt. Optional – Add two teaspoon of sesame oil.

1D060E8D-6B07-4F0F-8968-FF7CCDC5D03B

Add scrambled eggs and stir well

E29828D9-85C8-4C87-8E33-B330D5FA592D

We are almost done. Add some spring onions and stir well

FBFA167F-A671-48B5-98A2-46A314AC8888

We are done, serve the fried rice with some soy sauce or hot sauce

DF03A100-FCED-42B7-BBF4-DB206D8519FA

Please leave your comments if you have enjoyed making this dish.

GIT cheat sheet

Setting up user

git config --global user.name "Srikanth Bemineni"
git config --global user.email "srikanth.bemineni@gmail.com"
git config --global credential.helper cache
git config --global credential.helper 'cache --timeout=3600'

Setting up GitHub key

https://help.github.com/articles/generating-ssh-keys


ssh-keygen -t rsa -C "srikanth.bemineni@gmail.comi"

please install xclip it


xclip -sel clip < ~/.ssh/id_rsa.pub

Git commands

Create Project – To make the existing project root folder managed by the Git repository or to start a new project


git init .

Clone Project(checkout) – To check out a project.

We use the git URL in the form git:\\…


git clone git://github.com/bemineni/eldam.git

Add – To add new files to the project

git add [filename];

The below command will add any new file that hasn’t been added to the current project


git add .

Status – To get status of the current repository


git status

-s Short output


git status -s

diff – To get diff of the changes


git diff

Show both staged and unstaged changes comparing with the head revision


git diff HEAD

To show the short status output of the diff


git diff --stat

commit – To commit the changes


git commit -m "Message"

This will open the default editor to enter the message.


git commit

log

Will get all the changes logs with respect to the branch


git log

A compact version of the log output.


git log --oneline

Will show a graph of the branches and changes


git log --oneline --graph

reset – To reset the changes. Commit will not commit these changes


git reset HEAD [filename]

Remove – To remove the file from git


git rm

Move – If you want to move the file and add it to the git


git mv

tag – To tag the current head


git tag -a

To get all the tags from the remote


git fetch origin --tags

Git Branching

To find out the current branch details use the below command


git branch

To find out last commits on all the branches.


git branch -v

Create a new Branch.


git branch

Switch or checkout to a branch

The branch should have been created using the previous command


git checkout [name of new or existing branch]

The -b creates a new branch and switches to the new branch.


git checkout -b

Delete a branch


git branch -d

This push the changes to the remote repository and delete the branch


git push [remote-name] :[branchname]

Merge branches

This command will merge the changes and move to the branch that was used to create this branch.


git merge

Git Remote

List remote – This will be used to manage remote attribute

lists all of the remote repositories


git remote -v

Example:

$ git remote -v
github git@github.com:bemineni/baamv.git (fetch)
github git@github.com:bemineni/baamv.git (push)

Add a new remote URL


git remote add [name] [url]

Example

$git remote add origin git@github.com:something/something.git

Remove remote repositories

This command will remove the remote repositories


git remote rm [name]

Example

$git remote rm github

Renaming an alias


git remote rename [old_name] [new_name]

Example

$git remote rename github origin

Updating the new URL for the remote repository


git remote set-url

Example

git remote set-url github git@github.com:something/something.git

Fetch -To get updates from a remote branch.

To synchronize your repository with a remote repository, fetching all the data it has into your branch reference locally for merging


git fetch

git pull -> This will fetch from the remote and merge with the current branch locally

Push – To update a remote repository with the changes you’ve made locally.

It will take what your [branch] looks like and push it to be [branch] on the remote, if possible. If someone else has pushed since you last fetched and merged, the Git server will deny your push until you are up to date.


git push

How to update your project which has already been modified from the current master branch. (similar to SVN update)

When you have changed on your working copy, from the command line do:


git stash

This will stash your current changes and clear your status


git pull

This will pull changes from an upstream branch. Make sure it says fast-forward in the report. If it doesn’t, you are probably doing an unintended merge


git stash pop

This will apply stashed changes back to working copy and remove the changes from stash unless you have conflicts. In the case of conflict, they will stay in the stash so you can start over if needed.

If you need to see what is in your stash


git stash list

eldam 1.2.0 released

We can now update and delete multiple document records using Elasticsearch query DSL and scripts. In this release below two new methods are included.

https://pypi.python.org/pypi/eldam/1.2.0 

Documentation for this release at http://eldam.readthedocs.io/en/v1.2.0/

eldam 1.0.1 released

ElasticSearch Data Manager (eldam). eldam works with Zope transaction. You can add, delete or update documents all through your session. All data will be included in Elasticsearch database at the end when the transaction is committed. The module can be used in your web application to add/modify or delete elastic search data that will be committed along with other transaction data manager like zope.sqlalchemy.  If any one of the transaction fails, then every Elasticsearch committed data will be reverted back. It’s like all go in or none. eldam implements two-phase commit as defined by the Zope transaction module.  The module is well suited for a pyramid application.

https://pypi.python.org/pypi/eldam/1.0.1 

How to install eldam


pip install eldam

Try it out


import transaction
from eldam.elasticdatamanager import ElasticDataManager
edm = ElasticDataManager()
edm.connect({
'elasticsearch_hosts':["16.83.62.232:9200","16.83.63.114:9200"]
} ,"test")
edm.add({'_type':'group',
'_id':'2',
'_source':{
"gid": 234,
"owner": "bemineni",
"name": "Sammy",
"grp_hash": "456678",
"description": "Sammy group"
}
})
transaction.commit()

For more eldam documentation

http://eldam.readthedocs.io/en/latest/

Generating a sha256 self signed certificate

We can generate a self-signed certificate using one simple command. This is fast and simple

izero@Ganesha ~/devel/demo $ openssl req -x509 -sha256 -nodes -days 365
-newkey rsa:2048 -keyout device.key -out device.crt
Generating a 2048 bit RSA private key
..............................................................+++
........+++
writing new private key to 'device.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:US
State or Province Name (full name) [Some-State]:TX
Locality Name (eg, city) []:Houston
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Lotus Inc
Organizational Unit Name (eg, section) []:Lotus apps
Common Name (e.g. server FQDN or YOUR name) []:iamzeroblog.wordpress.com
Email Address []:srikanth.bemineni@gmail.com

 

What all did happen by executing this single command?

  1. We just created a new 2048 bit RSA key “device key “
  2. The command internally generated a CSR (certificate sign request).
  3. The command internally used the device key to sign the CSR and generate a device.crt signed the certificate

Now use your certificate(device.crt) and key(device.key) in your web server.

Please leave your comments below.

Who is guiding your state of mind? Can you fight it ?

I want to start with some scenarios dealing with different people in your life.

  • Lets say you heard in news about a well know business person who killed his wife for money . He is on trial today. You got a crucial clue about this murder. If this clue is submitted to the authorities, he will be definitely convicted.
  • You met a person in a store, he smiled at you and  you smiled back. You got acquainted, you two guys are not longer strangers any more. You came out of the store with that person. You just found out the that he didn’t pay for an item and you remind him about that, but he says its fine.
  • There is kid in your street, you knew his family for past 10 years. You saw this kid grow up in front of your eyes. You just came to know the that the kid is involved in some gang and is dealing drugs.
  • Your son/daughter hit a 10 year old kid with your car. He/she didn’t come out of the car to help the kid, but instead came back home. Nobody saw what happened on that street. You just came to know about this from your son/daughter
  • You are travelling in a bus, and met with an accident. The bus fell into a river, you know how to swim and escape. You also feel that you can save some people.

Now think what you are going to do in all these situations?

There is varying level of emotions, feeling and personal loss that can result based on the righteous decision you make. In some situations the decision can affect your life very personally, In some it may be minimal, some times it may not affect you at all, you may also give suggestions on what is right thing to do at that time.

I feel we have varying degree of will to fight these demons in our mind to take the righteous decision. The situation may not always deal with some simple things mentioned above or with some ones life itself. The decision may with be with respect to materialistic gain or loss.

In the above questions, that last two situation is where our demons really kicks in. I feel if a person can really overcome this, then  he is a pure soul who has conquered his demons. We can also at our subconscious  level can tell where we are, and  who is guiding our mind at this moment, is it the seven sins of evil or the path to righteousness . If we are with a person for long time, we can definitely tell what his decision would be , when these kind of situation occurs in his life.

Most of people including me move around this scale.

scale

As this blog is written people in India are getting their new currency. I have been talking to some of my friends, seeing so many videos of people blaming the decision. Some people say common people should not be affected, some say government need to attack the big shots. From my perspective, every person in India from the multi millionaire to a street beggar is  hiding some black money. Every one has some or significant amount of money that is not “reported” to the government. Looking up to the above questions, the situation falls under the last category. “My money is gone” for the mistakes that I have done to not disclose my money to the government.  The crossed sentence is the whole statement which has the answer for the righteous decision. Lets see to how much extent the people of India are going to fight the demons to make the country a better place.

 

Deleting the parent who owns you

man-cutting-a-branch

In my ten years of the programming experience, this is the most common programming bug that I always see in the code.


class A;

class B
{
public:
  B(A* parent)
  {
    m_parent = parent;
  }

  void funcB()
  {
     delete m_parent;
  }

public:

   A* m_parent;
};

class A
{

 A()
 {
    bptr = new B(this);
 }

 ~A()
  {

  }

 void funcA()
 {
    bptr->funcB();
 }

 void sayHi()
 {

     cout<<"Hi this is A";  }  public:     B* bptr; }; main() {    A* aptr = new A();    aptr->funcA();
   aptr->sayHi();
}

Some times these may be not be a straight forward bug like the one mentioned above. The difficulty is in finding when the Object was deleted. The best way is to put a break point at A’s destruct-or.

In Qt always try to use deleteLater to delete an object. Some times the object would have generated the event, and we should not be deleting the calling object from the slot or event processing handler. The best example I can give is during the socket disconnect event. The disconnect signal would be emitted on the socket closeEvent.  If this event is handled by a slot in your program then , don’t delete the socket in the disconnected handler slot.  Always use deleteLater(socket) to delete the socket object in the closeEvent handler. This will make sure that the socket object is deleted before the event loop starts processing the next event.