WYSIWYG

http://kufli.blogspot.com
http://github.com/karthik20522

Thursday, September 5, 2013

Useful Git Alias and Hooks

Git by itself is very raw and sometime hard to read the console outputs. Following are some of git alias that I tend to use on a daily basis.

git lg

This is a replacement to git log. git log doesn't provide any useful information such as branch name nor it's pretty looking! Yes pretty looking like colors and such. Following git alias solves this mundane problem.
Following is a comparison screenshot of git lg vs git log

Using git log:


Using git lg alias:

git unpushed

Every now and then I try to look for all uncommitted changes. But this quite a pain to look for from git console. Problem solved with the following alias:

git undo

git out-of-the-box doesn't provide an undo option to revert the previous commit. Pain! Following alias intends to solve the problem:


Pre-push hooks

One of the most important hooks that I use is a pre-push hook that executes unit tests before pushing to "master" branch. This is important as it can save broken test cases being pushed to master branch. Following hook script:

Labels:

Tuesday, August 7, 2012

YearInImages.com - How I built this?

Image mosaic source at https://github.com/karthik20522/ImageMosaic



Following post is a very high level technical overview of how the images were constructed and stored and how Getty Images Connect API was used to make this site possible. Site link: yearinimages.com

Connect API story:
All editorial images in Getty images are associated to an event. An event could be anything, Oscar awards, Olympics etc with a bunch of images associated to it. Every event has a numerical id that makes the event unique in our system. The years in focus 2011 images are categorized into 4 main categories (News, Sports, Entertainment, Archive). Each of these categories has many Events and with some simple scripting the EventId’s of each Event was scraped from the site and the image associated with these events was queried using Connect API. Following is a code snippet of querying Getty Connect API:
More technical information of GettyImages Connect API can be found at https://api.gettyimages.com/apis

C# wrapper to call GettyImages connect API: https://github.com/karthik20522/GettyConnect

Note that Connect API only returns back maximum of 75 images per search, so you would have to loop if an event has more than 75 images. The image metadata that Connect API provides has enough information to describe an image but you could also query GetImageDetail endpoint to get complete metadata details of an image. Once the image information was queried and saved (yearinimage uses mongodb as datastore), the image thumbnails were then downloaded for building image mosaic using following code snippet:

Image mosaic story:
The idea behind building image mosaic is to take the original image and split it to a grid say 20x20 pixels (depending on the size of the image) and compute the average RGB within each of the blocks.



Now unfortunately the thumbnail images that were downloaded from GettyImages are not uniform in size (landscape vs portrait). Since we are splitting the image into square Grid, the thumbnails had to be resized to be uniform. Once the thumbnails were resized, their average RGB values were calculated. Average color code snippet:

The next step was to iterate through each image and find the closest match to each block on the image. Since the image grid is basically a matrix of n x m, this can be serialized and stored in file/db. YearinImage used the following class model to store the matrix:


Upon page load, the browser builds a table/grid and places the image in the appropriate location (x,y) to make it look like a single mosaic. With client side scripting (JavaScript), user interaction with each of the mosaic image was possible like displaying image information when a user hovers over the image. This image information (caption) is fetched from the server using ajax calls. The ajax calls by themselves are relatively fast (less than 100ms) but when a user hovers over many images really fast these ajax calls get’s queued up and the user experiences slowness as the browser is waiting for queued ajax calls to complete. This delay can be avoided by aborting the previous ajax call to the server when a user hovers away from the image. Example of aborting an ajax call is like follows:


As a side note, since the browser displays 100’s of images for the mosaic, this potentially could lead to memory build up on the browser. This can be handled by using revokeObjectURL method. Code snippet:

Labels: , , , ,

Tuesday, July 17, 2012

TFS to GIT Simple Migration guide

Migrating tfs to an external git repository involves these following steps; make sure to have git-tfs [https://github.com/git-tfs/git-tfs] installed. Use chocolatey [http://chocolatey.org] to install git-tfs.

To install chocolatey, run the following command in command prompt:
Once chocolatey is installed run the following command to install git-tfs:

To clone/copy the entire TFS code and history use the following command: Note that "clone" command would copy all code, history and changesets and "quick-clone" would only copy the latest changeset of all the files. The git-tfs command also takes in optional target directory parameter like the following example. The default is the path that the command is run from.
To ignore any file or directory or ignore multiple files/directories from being cloned, use the ignore-regex parameter: If you were to encounter an error like "Command exited with error code:128", you may want to run the git-tfs command with "-d" option, detail option, and ignore that particular file that is causing the export to break! Example: So lets for example you cloned all your TFS code to c:\Temp\TFSCode directory and also lets assume that your GIT (external git repository) directory is at c:\Temp\GITCode. To completely migrate from TFS to your Git Repository following 3 steps needs to be performed:

Labels:

Sunday, May 13, 2012

2011 Year In Images - Image Mosaic

Checkout a Mosaic of 2011 Best images (images from GettyImages) at http://www.yearinimages.com

The images information is fetched using GettyImages Connect API using the following C# library
https://github.com/karthik20522/GettyConnect

I have also opened sourced the the Image Mosaic code used for building the mosaic at
https://github.com/karthik20522/ImageMosaic

Labels: , , ,

Friday, March 16, 2012

Git commands and basics

Between Team Foundation Server, SubVersion and Git that I have worked with, Git is slowly turning out to be quite a version control! Anyways, during my work with Git as my source control, here are some useful commands that I have put into my own cheat sheet.

create a file

$notepad myfile.txt

add a file

$ git add myfile.txt

add all files

$ git add .

commit a file (including comments)

$ git commit -m "Initial add"


get latest version and merge

$ git pull --rebase

note: rebase reformulates the check-in timeline continuum based the repository that everyone is working with.

checkout a branch

$ git checkout master

push a branch to remote repository without merging

git push origin newfeature

remove a branch on a remote repository

git push origin :newfeature

delete a local branch

git branch -d newfeature

Creating a branch (and switching to the new branch) in one line

git checkout -b [name of new branch]

Making sure changes on master appear in your branch

git rebase master

Pulling a new branch from a remote repository

git fetch origin [remote-branch]:[new-local-branch]


Undoing in Git - Reset, Checkout and Revert

Git provides multiple methods for fixing up mistakes as you are developing. Selecting an appropriate method depends on whether or not you have committed the mistake, and if you have committed the mistake, whether you have shared the erroneous commit with anyone else.
Fixing un-committed mistakes

If you've messed up the working tree, but haven't yet committed your mistake, you can return the entire working tree to the last committed state with

$ git reset --hard HEAD

This will throw away any changes you may have added to the git index and as well as any outstanding changes you have in your working tree. In other words, it causes the results of "git diff" and "git diff --cached" to both be empty.

If you just want to restore just one file, say your hello.rb, use git checkout instead

$ git checkout -- hello.rb
$ git checkout HEAD hello.rb

The first command restores hello.rb to the version in the index, so that "git diff hello.rb" returns no differences. The second command will restore hello.rb to the version in the HEAD revision, so that both "git diff hello.rb" and "git diff --cached hello.rb" return no differences.
Fixing committed mistakes

If you make a commit that you later wish you hadn't, there are two fundamentally different ways to fix the problem:

You can create a new commit that undoes whatever was done by the old commit. This is the correct thing if your mistake has already been made public.

You can go back and modify the old commit. You should never do this if you have already made the history public; git does not normally expect the "history" of a project to change, and cannot correctly perform repeated merges from a branch that has had its history changed.

Fixing a mistake with a new commit

Creating a new commit that reverts an earlier change is very easy; just pass the git revert command a reference to the bad commit; for example, to revert the most recent commit:

$ git revert HEAD

This will create a new commit which undoes the change in HEAD. You will be given a chance to edit the commit message for the new commit.

You can also revert an earlier change, for example, the next-to-last:

$ git revert HEAD^

In this case git will attempt to undo the old change while leaving intact any changes made since then. If more recent changes overlap with the changes to be reverted, then you will be asked to fix conflicts manually, just as in the case of resolving a merge.
Fixing a mistake by modifying a commit

If you have just committed something but realize you need to fix up that commit, recent versions of git commit support an --amend flag which instructs git to replace the HEAD commit with a new one, based on the current contents of the index. This gives you an opportunity to add files that you forgot to add or correct typos in a commit message, prior to pushing the change out for the world to see.

If you find a mistake in an older commit, but still one that you have not yet published to the world, you use git rebase in interactive mode, with "git rebase -i" marking the change that requires correction with edit. This will allow you to amend the commit during the rebasing process.


Good Git sites:

http://rogerdudler.github.com/git-guide/
http://think-like-a-git.net/
http://jonas.nitro.dk/git/quick-reference.html

Labels: