Thursday, 29 November 2012

Conway's Game of Life



Game of Life is not as our typical computer games. It is a 'cellular automaton'. This consists of a collection of cells which, based on a few mathematical rules, can live, die or multiply.


The Rules: 

1. Any live cell with fewer than two live neighbours dies, as if caused by    
    underpopulation.

2. Any live cell with two or three live neighbours lives on to the next generation.

3. Any live cell with more than three live neighbours dies, as if by overcrowding.

4. Any dead cell with exactly three live neighbours becomes a live cell, as if by 
    reproduction.


Patterns

Different types of patterns occur in the Game of Life, including still lifes, oscillators, and spaceships, which are the patterns that translate themselves across the board.


           Still lifes

Block Game of life block with border.svg
Beehive Game of life beehive.svg
Loaf Game of life loaf.svg
Boat Game of life boat.svg
                Oscillators




Blinker [period2] Game of life blinker.gif



Toad [period2] Game of life toad.gif



Beacon  [period2] Game of life beacon.gif



Pulsar [period3] Game of life pulsar.gif
                Spaceships

Glider Game of life animated glider.gif
Lightweight spaceship [LWSS] Game of life animated LWSS.gif
Algorithm
 

Life patterns are represented as two-dimensional arrays in computer memory. Typically two arrays are used, one to hold the current generation, and one in which to calculate its successor. Often 0 and 1 represent dead and live cells respectively. A nested for-loop considers each element of the current array in turn, counting the live neighbours of each cell to decide whether the corresponding element of the successor array should be 0 or 1. The successor array is displayed. For the next iteration the arrays swap roles so that the successor array in the last iteration becomes the current array in the next iteration.



Play the game:





Click here to download 'Game of Life' code.




[Expecting Your Valuable Comments]
Thank You

Sunday, 25 November 2012

Generate SSH Key






To use SSH keys to establish a secure connection between your computer and GitHub. Here is the steps to generate SSH keys and adding the public key to your Github account.

Step 1: Check for SSH keys

 Check for existing ssh keys on your computer by running the command given below:
$ cd ~/.ssh 
# Checks to see if there is a directory named ".ssh" in you user        directory                                                
If it shows "No such file or directory", skip to step 3. Else go to step 2.

Step 2: Backup and remove the existing key

Back the old SSH directory up and remove it:
$ ls
# Lists all the subdirectories in the current directory
config  id_rsa  id_rsa.pub  known_hosts

$ mkdir key_backup
# Makes a subdirectory called "key_backup" in the current directory

$ cp id_rsa* key_backup
# Copies the id_rsa keypair into key_backup

$ rm id_rsa*
# Deletes the id_rsa keypair
Step 3: Generate a new key

To generate a new SSH key, enter the code given below. To make default settings, when asked to enter a file in which to save the key, just press enter.
$ ssh-keygen -t rsa -C "your_email@youremail.com"
# Creates a new ssh key using the provided email
Generating public/private rsa key pair.
Enter file in which to save the key (/home/you/.ssh/id_rsa):
You need to enter passphrase.
Enter passphrase (empty for no passphrase): [Type a passphrase]
Enter same passphrase again: [Type passphrase again]
When you enter the passphrase, it shows something like this:
Your identification has been saved in /home/you/.ssh/id_rsa.
Your public key has been saved in /home/you/.ssh/id_rsa.pub.
The key fingerprint is:01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db                       your_email@youremail.com
Step 3: Add SSH key to Github

Run the following code to copy the key to your clipboard.
$ sudo apt-get install xclip
# Downloads and installs xclip
$ xclip -sel clip < ~/.ssh/id_rsa.pub
# Copies the contents of the id_rsa.pub file to your clipboard
Now,

1. Go to Github Account settings.
2. Click on SSH keys in the left sidebar.
3. Click on Add SSH key.
4. Paste your key into the Key field.
5. Click Add key
6. Confirm the action by entering your Github password.


[Expecting Your Valuable Comments]
Thank You

GIT REPOSITORY





A Git project using two main approaches. The first takes an existing project or directory and imports it into Git. The second clones an existing Git repository from another server.

Initialize a git repository in a directory


Go to the project’s directory and type
$ git init 
This creates a new subdirectory named .git that contains all of your necessary repository files. If you want to begin version-controlling existing files, then you need to start tracking files and do a initial commit. git add commands specify the files you want to track.git commit commands used to commit.
$ git add *.c
$ git add README
$ git commit -m 'initial project version'
Cloning a repository

If you want to get a copy of an existing Git repository, use git clone command.
git clone [url]if you want to clone the Ruby Git library called Grit
$ git clone git://github.com/schacon/grit.git 
if you want to clone the Ruby Git library called Grit in a new directory new
$ git clone git://github.com/schacon/grit.git new
Checking the status

To get the status of the git, type the command git status.Then you should see something like this.

$ git status
# On branch master
nothing to commit (working directory clean)
Add a new file README to your project. If the file didn’t exist   before, and you run git status, you see your untracked file like this:
$ vim README
$ git status
# On branch master
# Untracked files:
#   (use "git add ..." to include in what will be committed)
#
#   README
nothing added to commit but untracked files present (use "git add" to track)
Tracking a file

To begin tracking, use git add. Now on running the command git status, you will get  something like so:
$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD ..." to unstage)
#
#   new file:   README
#
Staging a modified file

Modify a file which is already tracked and then try the command. You will get something like this:
$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD ..." to unstage)
#
#   new file:   README
#
# Changed but not updated:
#   (use "git add ..." to update what will be committed)
#
#   modified:   hunter.rb
#

Now this shows the file 'hunter.rb' is modified but not yet staged. To stage it, run the command git add (Multipurpose command- Used for tracking, staging and to do more) and then git status.
$ git add benchmarks.rb
$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD ..." to unstage)
#
#   new file:   README
#   modified:   hunter.rb
#

If you modified the file 'hunter.rb'. To see the difference between the modified and unmodified file, type the command git diff before staging the modified file.
$ git diff
diff --git a/hunter.rb b/hunter.rb
index 3cb747f..da65585 100644
--- a/hunter.rb
+++ b/hunter.rb
@@ -36,6 +36,10 @@ def main
           @commit.parents[0].parents[0].parents[0]
         end

+        run_code(x, 'commits 1') do
+          git.commits.size
+        end
+
         run_code(x, 'commits 2') do
           log = git.commits('master', 15)
           log.size
Committing a file


The simplest way to commit is to type the commit message inline with the command git commit after -m flag.
$ git commit -m "Story 182: First commit"
[master]: created 463dc4f: "First commit"
 2 files changed, 3 insertions(+), 0 deletions(-)
 create mode 100644 README
Removing files

To remove a file from Git, you have to remove it from your tracked files and then commit. The git rm command does that and also removes the file from your working directory.
$ git rm pythonhunter.rb
rm 'pythonhunter.rb'
$ git status
# On branch master
#
# Changes to be committed:
#   (use "git reset HEAD ..." to unstage)
#
#       deleted:    pythonhunter.rb
#
Renaming files

To rename a file, run a command git mv and run command git status to get something like this:
$ git mv pythonhunter.txt hunter
$ git status
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
# Changes to be committed:
#   (use "git reset HEAD ..." to unstage)
#
#       renamed:    pythonhunter.txt -> hunter
#
Adding remote repository

To add a remote repository, run the below command.
$ git remote add origin git@github.com:rasheedh/Photo-Editor.git
Where 'git@github.com:rasheedh/Photo-Editor.git' is the SSH url(Generating SSH key).

Pushing to remote

If you want to push your master branch to your origin server, then you can run this to push your work back up to the server:
$ git push origin master

[Expecting Your Valuable Comments]
Thank You