Tuesday, July 31, 2012

Sears Israel 2012 Hackathon

As my first hackathon, I must say it was quite awesome!...
For two days at work, everyone was crunching at their projects, trying to get as much of it done as humanly possible in that short period of time. I stayed pretty late those days, and even worked a little more on the weekend after, as some others did too.

Some of the projects included creating apps on top of the application framework we have on our site (which is kinda like building a facebook app - You are hosted in an iframe on the site and can work against the site's api).
I created a 'polyvore' like app - It lets you create a collage of products on a canvas for others to see (mainly intended for women's use).
Some other cool apps were games like "The price is right" for products on our site, or an item tagging compatibility game where you need to tag items identically with a partner to score points.
There were some actual features developed for the site, like a 'GeoFeed' - The capability of presenting a users newsfeed on a map, with relevant feeds in his area. Some people took the time to install or implement tools that will help us get our job done better daily, like a cool dynamic dashboard that can contain almost any information we want, or installing an IRC server that will give us a better communication channel for development issues than email.

Whatever the project was - I think it was fun for everyone working on them, and very thoughtful of the company to hold such an event...

Here are just some cool pics from the hackathon -

Me working on my hackathon app...


Our R&D VP working on his app...


The team in Chicago working on their app...


It's not a real hackathon, unless you have hackathon water!


...and lots of energy drinks!


...and a big hackathon timer on the hallway monitors :)

Sunday, July 8, 2012

Always wear sunscreen while maintaining a blog


Many people think that maintaining a blog is a lot of work. I think saying that is like saying reading the paper is a lot of work - You need to go out, buy it, free some time and actually read it. ...But that's not the reality of it, you just grab it during some breaks you have during the day, and read a little...
No commitment, no strings attached and nothing happens if you don't finish the article you started...

The same should go for a blog -
You don't need to make a fuss about it and you don't need to free any time for it.
Just start one, and whenever you have something on your mind - something new you learned, something you feel like expressing, then just jot it down.

Don't think about what others will think.
Don't think about what will happen if you never finish the post.
Just start typing...

Now, when there are so many easy to use and free tools to get the job done, it should be happening 100 times more than it actually is!...

Just write it for yourself. If someone else happens to learn from it, or connect to it in any way, well, then that's just an added bonus.
You'd be surprised by the amount of knowledge you'll be learning by publishing one on your own.
Even if you only ever have one or two good posts, it's worth having them out there for others to read, but that should never be what it's about.

Don't look at how many people read your blog.
Don't think you have to be an expert to start one.
Don't believe everything you read in other blogs, and don't think that every blog is written by some expert.
Read a lot of blogs yourself, and comment when you feel like you have something to say on the matter.
You'd be surprised by the amount of comments you'll be getting (or not getting) on your posts...

People don't start reading your blog just because you posted something. They'll read it because they were looking for something that you posted about. That might happen today, maybe tomorrow and maybe only in 3 years from now...
They won't stop reading it just because you don't post anything either...

It's all about saying what you have to say, whenever you feel like it. Nothing more.
So just do it, have fun doing it, and always wear sunscreen.

:)
Gilly.

Sunday, June 24, 2012

Running UI tests on local asp.net website with development server


These past couple of days I started writing a utility program that will invoke some UI tests against a certain website of my choice. Obviously, I needed to write tests for the functionality of this utility, so I will be sure that it works.
I wanted the tests to be as real as possible, and so I decided to run them against a real site, like google (could've been any other site, this doesn't really matter for the sake of the story).

The tests worked great, but then I realized that they could easily be broken, with no connection to my work - No one promises me that google's page structure (or anything I want to test) will always stay the same, and I don't even know which tests i'll want to add to it in the future, and if I'll have all the resources on the site of my choice.

I decided that I'll create a custom asp.net mvc site for the sake of my tests.
At first I configured the site on IIS locally and this was great, but then I started thinking another step forward, and realized I have another problem - I want someone else to be able to download the source code, and run the tests immediately without having to create a local website and going through all the proper configurations.

I realized that I could use the asp.net development server for this.
First, I needed to give the site a static port to run on in the development server :
(In the project properties page, go to the 'Web' tab, and mark 'Use Visual Studio Development Server' -> 'Specific Port')

Then, I created a class called 'DevelopmentServer' responsible for loading the asp.net development server, and shutting it down at the end :
public class DevelopmentServer : IDisposable
{
    private readonly Process _devServer;

    public static int Port = 1212;
    private string _devServerExe = @"C:\Program Files (x86)\Common Files\microsoft shared\DevServer\10.0\WebDev.WebServer40.EXE";
    private string _testSitePath = @"C:\Dev\MySitePath\";

    public DevelopmentServer()
    {
        _devServer = new Process {
            StartInfo = { 
                FileName = _devServerExe,
                Arguments = string.Format("/port:{0} /path:{1}", Port, _testSitePath)
            }
        };

        try
        {
            _devServer.Start();
        }
        catch
        {
            Console.WriteLine("Unable to start development server");
            throw;
        }
    }

    public void Dispose()
    {
        _devServer.Kill();
        _devServer.Dispose();
    }
}
The port number and the library paths are just hard coded for the sake of the example. It makes more sense to put them in some configuration file of your choice.
(Note: You might have to change the path to the file WebDev.WebServer40.exe which is the binary of the development server, according to the version you have. The earlier version of this file is called WebDev.WebServer20.exe)

Finally, I just created an instance of this class upon FixtureSetUp, and disposed of it on FixtureTearDown.

Thursday, June 21, 2012

Redirecting external Process output to Console.Writeline (or elsewhere)


As part of some code I was writing recently, At some point my app needed to trigger some other command line utility. I did this easily, using the Process class like this :
var myProcess = new Process {
    StartInfo = {
        FileName = "C:\\path\\to\\my\\cmd\\utility.exe",
        Arguments = " --some --random --args"
    }
};
myProcess.Start();

This was working great, with one exception - Sometimes the process was throwing an error, causing the console window to close immediately, and I didn't have time to view this error.
I knew that you can tell there was an error by the process's exit code (myProcess.ExitCode), but while debugging it was important to know what error was happening and actually see the output of this process.

Digging a little into the Process class, I easily found that you can redirect the process's output elsewhere. You just need to add :
// This needs to be set to false, in order to actually redirect the standard shell output
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.RedirectStandardOutput = true;

// This is the event that is triggered when output data is received.
// I changed this to Console.WriteLine() - you can use whatever you want basically...
myProcess.OutputDataReceived += (sender, args) => Console.WriteLine(args.Data);

myProcess.Start();

myProcess.BeginOutputReadLine(); // without this, the OutputDataReceived event won't ever be triggered

That's it! Now i was getting all I needed from the running process, and it was much easier to find the problem this way. :)

Enjoy :)

Saturday, June 16, 2012

Having fun web crawling with phantomJs


A couple of weeks ago, a colleague of mine showed me this cool tool called phantomJs.
This is a headless browser, that can receive javascript to do almost anything you would want from a regular browser, just without rendering anything to the screen.

This could be really useful for tasks like running ui tests on a project you created, or crawling a set of web pages looking for something.

...So, this is exactly what i did!
There's a great site I know of that has a ton of great ebooks ready to download, but the problem is that they show you only 2 results on each page, and the search never finds anything!

Realizing that this site has a very simple url structure (e.g.: website/page/#), I just created a quick javascript file, telling phantomjs to go through the first 50 pages and search for a list of keywords that interest me. If i find something interesting, it saves the name of the book along with the page link into a text file so i can download them all later. :)

Here's the script :
var page;
var fs = require('fs');
var pageCount = 0;

scanPage(pageCount);

function scanPage(pageIndex) {
 // dispose of page before moving on
 if (typeof page !== 'undefined')
  page.release();

 // dispose of phantomjs if we're done
 if (pageIndex > 50) {
  phantom.exit();
  return;
 }

 pageIndex++;
 
 // start crawling...
 page = require('webpage').create();
 var currentPage = 'your-favorite-ebook-site-goes-here/page/' + pageIndex;
 page.open(currentPage, function(status) {
  if (status === 'success') {
   window.setTimeout(function() {
    console.log('crawling page ' + pageIndex);
    
    var booksNames = page.evaluate(function() {
     // there are 2 book titles on each page, just put these in an array
     return [ $($('h2 a')[0]).attr('title'), $($('h2 a')[1]).attr('title') ];
    });
    checkBookName(booksNames[0], currentPage);
    checkBookName(booksNames[1], currentPage);
    
    scanPage(pageIndex);
   }, 3000);
  }
  else {
   console.log('error crawling page ' + pageIndex);
   page.release();
  }
 });
}

// checks for interesting keywords in the book title,
// and saves the link for us if necessary
function checkBookName(bookTitle, bookLink) {
 var interestingKeywords = ['C#','java','nhibernate','windsor','ioc','dependency injection',
  'inversion of control','mysql'];
 for (var i=0; i<interestingKeywords.length; i++) {
  if (bookTitle.toLowerCase().indexOf(interestingKeywords[i]) !== -1) {
   // save the book title and link
   var a = bookTitle + ' => ' + bookLink + ';';
   fs.write('books.txt', a, 'a');
   console.log(a);
   break;
  }
 }
}

And this is what the script looks like, when running :
Just some notes on the script :
  • I added comments to try to make it as clear as possible. Feel free to contact me if it isn't.
  • I hid the real website name from the script for obvious reasons. This technique could be useful for a variety of things, but you should check first about legality issues.
  • I also added an interval of 3 seconds between each website crawl. Another precaution from putting too much load on their site.

In order to use this script, or something like it, just go to the phantomjs homepage, download it, and run this at the command line :
C:\your-phantomjs-lib\phantomjs your-script.js

Enjoy! :)

Friday, June 8, 2012

My opinion on GIT vs. SVN


I finally decided to convert to git...
Yes, this sounds like a religious statement (just like saying "i'm converting to christianity, judaism or islam") because it is!

Let me give some background -
At my work, we have a main svn repository, and we used to all use subversion (with Tortoise SVN and ankhSvn for VS compatibility). This was all great, until one day, some people decided that git is so much better than svn and they started convincing the others to try it out. So some of us did (or more accurately, attempted to try it out) by installing git extensions. In case you're not familiar, git extensions is a windows gui for git that is extendable so there's a plugin called git-svn that allows you to work git-based while actually having a svn server in the background. I went along and did just the same a couple of weeks ago. I also hosted a personal project on github to get the feeling of working with a real git repository (and not just using git-svn).

I must say, that working with git, is great!
...But also working with svn was great!
If i try to look back on it, I don't really remember the same people that are fans of git complaining about using svn the way they "claim" to have been complaining about it now. I think their more in love with the "coolness" of using git, since it seems like the cooler trend now-a-days.
Github has become so popular lately, and not for nothing - Their website is really easy and comfortable to use, and they have great tools for socializing and communicating on distributed projects over the internet. With that said, if they were hosting svn as well, I don't think it would be that big a difference.

All in all, git is great, but has it's share of problems. Svn has it's totally different share of problems as well. If there's a really good reason for me convincing you to start using git, it's because I truly believe that great developers should be well aware of the advantages and disadvantages each tool set gives you and that it's always good learning to use a new tool every once in a while. That's the only way to make the decision on which tools are best for you or your project.

Git and SVN are completely different in how they work, and it's really interesting to dig deep in to..
Here's a great post I read a while ago, that explains it really good : Understanding Distributed Version Control Systems

Monday, May 28, 2012

Sears Israel - Upcoming Hackathon...


A year ago, which was before I starting work at Sears, they had a 2-day 'dojo'. Everyone in the company grouped into teams and worked on projects that interested them the most. These projects weren't necessarily connected to what we do as a company, but just projects that we want to do for fun, and some of them are actually being used by people in the company till this day!
Until this day I am still hearing about how much fun it was, and how people are waiting for another event like the dojo.

The time has finally come, and in about a month we are having another event just like this. This time it is a 4 day hackathon, which is supposed to be about building applications on top of our platform for our site (www.shopyourway.com) or about building internal tools that will help us in the process of creation in the future. We are already talking about how we're going to build the teams and what apps we're going to build and all the buzz around the event is really exciting... I love it when we have a chance to express ourselves in a little more freely manner then usual, and I think this is essential in developing the people you work with in so many ways! :)

I thought I'd just post here some articles about different hackathons in some other cool companies around the globe :
- Facebook's hackathon page
- Twitter hack week
- Feedburner's hackathon
- Dropbox hack week
- Google's 20 percent time (which is basically like an ongoing hackathon)

You see... all the cool kids on the block are having them, so now it's our turn too!... :)

A big thank you to all the people running my workplace!!

You can be sure I'll update my blog after the event, and tell you about the project I worked on...