Raba - Defend your code RSS 2.0
# Saturday, July 24, 2010

After we understand what video stream is all about and we wrote our first piece of SWFObject in Javascript. let’s try to have this working on our servers, of course that such things tend to fail. But let’s understand why…

First thing we need to understand is whether such failures occur due to my code, file format or server configuration.
let’s have a simple check trying to access the file directly using our browser.


configure your IIS to serve the following files: swf and mp4 using Static Content

<add name="FlashFiles" path="*.swf" verb="*" modules="StaticFileModule" scriptProcessor="" resourceType="File" requireAccess="Script" />
<add name="VideoFiles" path="*.mp4" verb="*" modules="StaticFileModule" scriptProcessor="" resourceType="File" requireAccess="Script" />

Setting handler(s) won’t be good enough, requesting the server again will return “404.3 – mime type missing”.
Don’t worry Adding new  mime type to IIS 7 - is easy:

            <mimeMap fileExtension=".mp4" mimeType="video/mp4" />


While installing the static content on our static servers (apache) – we’ve found out that requesting the files from firefox return with “no content length” and “incorrect mime type”
adding the correct mime type to the /etc/mime.type

video/mp4     mp4

Check the Request\Response we’ve found out that our servers are still returning compressed response , googling it find out that Firefox cann’t handle gzipped video stream,
compression was selectively disabled by adding the following line to /etc/httpd/conf.d/static.d/static.conf:

SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png|mp4)$ no-gzip dont-vary

Apache solution provided by Tomer G.

Saturday, July 24, 2010 11:01:30 PM (GMT Daylight Time, UTC+01:00)  #    Comments [0] - Trackback
IIS7 | Software Development | Web

You can read here my introduction about video streaming.

In order to embed rich media content into web pages and have our code compatible with different browsers we will use the SWFObject 2.2.
The SWFObject will render the right tags for the right browsers.

Here is a short, unobtrusive JS for showing your movie:

   1:  $(function() {
   2:    var videoBase = 'http://static-server/';    
   4:    $('.VideoTeaserArea').click(function() {   
   5:      $(this).openLightBox("<div id='media'></div>");  
   6:      playMovie('intro-movie.swf');   
   7:    });    
   9:    function playMovie(videoFile) {  
  10:      var videoUrl = videoBase + videoFile;  
  11:      var att = { data: videoUrl, width: "640", height: "378", allowfullscreen:true};  
  12:      var params = { flashvars: "autostart=true"};  
  13:      var id = "media";  
  14:      var myObject = swfobject.createSWF(att, params, id);  
  15:    }  
  16:  });


- line 2: Our movie directory, better place such content on static server or even CDNs.
- line 4: VideoTeaserArea is a class name that we spread all over our site - clicking on it will trigger the movie.
- line 5: openLightBox – on our site the movie will be opened in a light box.
- line 11: the videoUrl, will be seen in the configured size. allowfullscreen is false by default. read more here
- line 12: flashVars will be used here in order to have our movie start as our light-box will be opened.
- line 13: The placeholder we want to replace while loading the movie
- line 14: Add reference to the swfObject.js in order to have its instance(read bellow). The createSWF method is a low level API which enable combining with other Javascript libraries.

in order to have this code running we must add script tag:
<script type="text/javascript" src="swfobject.js"></script>

Now, after having embedding SWF to our site  - Let’s understand how to make this work on IIS and Apache.

Saturday, July 24, 2010 10:28:23 PM (GMT Daylight Time, UTC+01:00)  #    Comments [0] - Trackback
Web |  Ajax |  Javascript

So our mission is to have our website play a short intro movie.


Wiki Definition

Progressive download is a term used to describe the transfer of digital media files from a server to a client, typically using the HTTP protocol when initiated from a computer. The consumer may begin playback of the media before the download is complete. The key difference between streaming media and progressive download is in how the digital media data is received and stored by the end user device that is accessing the digital media.”


Actually the “progressive download” feature implemented in most media players allows them to begin playing the file as soon as enough data received.


File formats: SWF VS. FLV

  • Both are Adobe formats.
  • FLV is a video container, intended to contain only audio\video
  • SWF can contain animations, games, applications and videos
  • SWF uses a lossless compression and is limited to a certain number of frames. Due to it is not compressed some files can be too big for use in the internet.
  • Large websites like Google, Amazon are using the FLV file formats

After this short explanation, we are ready to start:

  1. Create a video file in a common streaming media format (in our case: Camtasia -> SWF, mp4)
  2. Upload the files to your Web Server
  3. Check whether this link is working from common browsers
  4. Link from you Web Pages (HTML tags or JS)

In the next posts we will talk about steps 3 and 4.

For now you can keep reading about step 1 - here

Saturday, July 24, 2010 10:25:34 PM (GMT Daylight Time, UTC+01:00)  #    Comments [0] - Trackback
Software Development | Web

Area 51 – GIS is a new place supported by the Stack Overflow to post your Qusetions and Answers about Geographic information systems. Part of the questions are talking about interesting issues like: Databases comparisons, Algorithms, New tools, GeoTagging, GeoJson, Kml, Map Caching layers etc.

Public beta will begin in 5 days.

Saturday, July 24, 2010 5:30:00 PM (GMT Daylight Time, UTC+01:00)  #    Comments [0] - Trackback

# Saturday, February 13, 2010

Finally, after a long time I find time to upgrade my blog to the newly 2.3 version.

I had many problems installing this version Go-daddy, Monorail and SecurityException.
The last one was also the funny one, after Google-ing a little bit, I found this post by Gabel one of my co-workers.

What’s new?

So first I created my self a new homepage which you can see here.
Second, you can track my reading-list, my twitter statuses and my projects (will be published later).

homepage  readinglist

Have fun.

Saturday, February 13, 2010 12:49:30 PM (GMT Standard Time, UTC+00:00)  #    Comments [2] - Trackback
My Site

# Saturday, August 01, 2009

Test methods must be written as production code.
While writing your tests you must act the same methods you write for your production code which means:

  1. human-readable (code standard, pattern etc.)
  2. code re-use (copy paste is never acceptable)
  3. etc...

This is a code you will probably find in your test projects

   1: [Test]
   2: public void GetCommentsByQuery_LookFormHmmmText_FindAtLeaseOne()
   3: {
   4:     SvnLogParser parser = new SvnLogParser();
   5:     string textToSearch = "Hmmm...";
   6:     var results = parser.GetCommentsByQuery(comment => comment.Contains(textToSearch));
   7:     CollectionAssertExtensions.IsNotEmpty(results);
   8: }
  10: [Test]
  11: public void GetCommentsByQuery_LookFormBugText_FindAtLeastOne()
  12: {
  13:     SvnLogParser parser = new SvnLogParser();
  14:     string textToSearch = "bug";
  15:     var results = parser.GetCommentsByQuery(comment => comment.Contains(textToSearch));
  16:     CollectionAssertExtensions.IsNotEmpty(results);
  17: }

You can see that the two methods are pretty much the same, the only change is the textToSearch variable.
There are some excuses for such duplication:

  • "We want two different names... to easily understand the failiure reason"
  • "we want it to be easy to read, without context switches..." (method calls and un-needed inheritance complexity)

We, of course, can refactor this code, like this:

   1: [Test]
   2: public void GetCommentsByQuery_LookFormBugText_FindAtLeastOne()
   3: {
   4:     string textToSearch = "bug";
   5:     GetCommentsByQuery_AssertAllItemsStartsWith(textToSearch);
   6: }
   9: [Test]
  10: public void GetCommnentsByQuery_LookForHmmmText_VerifyInsideComment()
  11: {
  12:     string textToSearch = "Hmmm...";
  13:     GetCommentsByQuery_AssertAllItemsStartsWith(textToSearch);
  14: }
  16: public void GetCommentsByQuery_AssertAllItemsStartsWith(string textToSearch)
  17: {
  18:     SvnLogParser parser = new SvnLogParser();
  19:     var results = parser.GetCommentsByQuery(comment => comment.StartsWith(textToSearch));
  21:     CollectionAssertExtensions.AllItemsSatisfy(results, res => res.Comment.StartsWith(textToSearch));
  22: }

This is better when you think of clone detection: less identical rows and the logic was extracted to one method.
But people might say that they can't see the AAA (Arrange, Act, Assert) and they want it in one place,
Moreover, in such code sample, it is harder to find all the input parameters, cause they will be spread all over the TestFixture methods.


NUnit 2.5 added TestCaseAttribute, this can help us write tests that are:

  • more readable
  • shorter test-fixture
  • all-in-one-place tests
   1: [TestCase("Hm...")]
   2: [TestCase("bug")]
2: [TestCase("bug")]
   3: public void GetCommentsByQuery_LookForText_FindAtLeastOne(string textToSearch)
   4: {
   5:     SvnLogParser parser = new SvnLogParser();
   6:     var results = parser.GetCommentsByQuery(comment => comment.Contains(textToSearch));
   7:     CollectionAssertExtensions.IsNotEmpty(results);
   8: }

Here you can avoid the duplication and you won't need to refactor your Tests to more than one method, while you still see them running using the given parameter,
for example when the second parameter will fail you will see this output:

------ Test started: Assembly: App.Tests.dll ------

TestCase 'App.Tests.NewFolder1.SvnLogParserTests.GetCommentsByQuery_LookForText_FindAtLeastOne("Hm...")'
  Expected: True
  But was:  False
    C:\ShaniData\ProjectsByTitle\Delver\App.Tests\NewFolder1\SvnLogParserTests.cs(75,0): at App.Tests.NewFolder1.CollectionAssertExtensions.IsNotEmpty[T]
    C:\ShaniData\ProjectsByTitle\Delver\App.Tests\NewFolder1\SvnLogParserTests.cs(33,0): at App.Tests.NewFolder1.SvnLogParserTests.GetCommentsByQuery_LookForText_Find...

4 passed, 1 failed, 0 skipped, took 0.78 seconds (NUnit 2.5).

The output will point the given method and the parameter used - which will ease finding the error.
You can extend reading about the usage here

Saturday, August 01, 2009 5:20:12 AM (GMT Daylight Time, UTC+01:00)  #    Comments [2] - Trackback
.Net 3.5 | C#3.0 | TDD | NUnit

# Tuesday, July 28, 2009

Yoav sent me this web site.

I like the idea of sharing knowledge,
I also like to read and learn from open sources.
This is even better: daily -public- code review...

Tuesday, July 28, 2009 7:05:03 AM (GMT Daylight Time, UTC+01:00)  #    Comments [0] - Trackback
Life | My Site | Software Development

# Wednesday, July 08, 2009

For more background about when we use this API you can read my last post about Rendering Objects to Html

Simple Rendering of query:

   1: var query = new StringTemplate("SELECT $column$ FROM $table$;");
   2: query.SetAttribute("column", "name");
   3: query.SetAttribute("table", "User");
   4: var data = query.ToString();
We will refactor this sample to handle the queries from an outside source:
   1: var group = new StringTemplateGroup("SimpleTemplates",@"C:\Templates\TemplateEngineTestCase");
   2: var query = group.GetInstanceOf("1_simple");
   3: query.SetAttribute("column", "name");
   4: query.SetAttribute("table", "User");
   5: var data = query.ToString();
Rows 1,2 - loading the template data from a source file. 
Here is the Template (1_simple.st):
SELECT $column$ FROM $table$;

Template Anonymous Type:

In the last template usage (1_simple.st) We bind the parameters using strings only. but we also have a better options: let's assume we wrote down such template:

Full Name: $Person.FirstName$ - $Person.LastName$

But let's assume that we don't have the Person class\instance, we can simply write it using the anonymous types:

   1: var user = new {FirstName = "Shani", LastName = "Raba"};
   2: var group = new StringTemplateGroup("OOTempaltes", @"C:\Templates\TemplateEngineTestCase");
   3: var query = group.GetInstanceOf("2_simpleObjects");
   5: query.SetAttribute("Person", user);
You can also use this kind of bindings for setting template-attributes from each one of the Person sub-classes.
Template list:

Till now it is all pretty simple to implement by yourself, but the real issue here is the List binding feature.
You can write such template:

$items: {num1|

and bind the list using this code:

   1: var templateFolder = new StringTemplateGroup("SimpleLoopTemplates", @"C:\Tempaltes\TemplateEngineTestCase");
   2: var template = templateFolder.GetInstanceOf("3_simpleLoop");
   4: template.SetAttribute("items", new List<string> {"Shani", "Doron", "Nati", "Yossi"});



  • The code is pretty simple, the templates engine implements good functionality and is well documented.
  • The StringTemplate syntax is easy to learn and well documented.
  • I still don't like it when I need to learn a new language\syntax - it will sharpen the newbie's curve.
  • StringTemplate is missing good Object2Template Designer.
Wednesday, July 08, 2009 8:13:57 AM (GMT Daylight Time, UTC+01:00)  #    Comments [1] - Trackback
.Net 3.5 | Scripting Technology

# Sunday, June 14, 2009

Dr. Alistair Cockburn will be in Israel.
I recommend you this user-group: Scrum Event. come and learn from the best.

See you there.

Sunday, June 14, 2009 4:42:51 AM (GMT Daylight Time, UTC+01:00)  #    Comments [0] - Trackback
Agile | Scrum

# Sunday, June 07, 2009


We are writing a new task for the ArcGis Explorer, this task needs to place images on the globe using its X,Y coordinates.
While for each instance on the globe we need to render its details as html.


Rendering the objects to html, we are still didn't find the right place (on the server or on the client), but let assume that they both need to do the same job.


  1. Render in code:
    This is the naive way of thinking. while you are first thinking about this  problem you might think to add the object an ToHtml() method.
    Always think about the: Single Responsibility Principle (SRP).
    You can still think about Writing an HtmlWriter or HtmlRenderer class that gets object and render the object using reflection or something else, but than you will find yourself indenting you JavaScript\html\CSS in C#, for example you can watch this code:

       1: var items = new List<string> {"Shani", "Doron", "Nati", "Yossi"};
       2: var sb = new StringBuilder();
       3: items.ForEach(currentItem => 
       4:         sb.AppendFormat("<li>{0}</li>", currentItem)
       5:         );
       6: string data = sb.ToString();
    Let's think about the time we will need to change the UI from <li> to one with style or maybe even change the list to be styled as table...
  2. XSL - is pretty more dynamic than code, isn't it?
    So we are now looking for something more dynamic, something that we can read from a file so we can give it to our designer to play with the UI.
    This lead us to the second option: at my past all our reports were rendered using XSL files, personally I don't like this option.
    But the main reason is that we will need to serialize our objects to XML, while in most cases all you need is to render only few fields.
  3. Let's found another Template Engine:
    The first one I can think of is the MVC Engine or Brail. after some searching reading and Testing I found StringTemplate.
    Here is a simple code for using the API:

       1: var templateFolder = new StringTemplateGroup("SimpleLoopTemplate", @"\TemplateEngineTestCase\WinApp");
       2: var template = templateFolder.GetInstanceOf("3_simpleLoop");
       3: //here we are binding our list to the template
       4: template.SetAttribute("items", new List<string> {"Shani", "Doron", "Nati", "Yossi"});
       5: var data = template.ToString();

    and here is the template (file name: 3_simpleLoop.st):
       1: $items: {num1| 
       2:   <li>$num1$</li>
       3:   }$
       4: $end$


The StringTemplate give us an API to solve our problem - and using such code and template we can render our Models to different Views.
But is this API is easy or even stable?

In later posts we will see more samples using the StringTemplate.
Hopefully samples for using Brail too.
Sunday, June 07, 2009 3:48:07 AM (GMT Daylight Time, UTC+01:00)  #    Comments [0] - Trackback
.Net 3.5 | Software Development | Design Patterns

# Saturday, April 11, 2009

I've been looking around for samples and some good advices for writing resumes and found this site: VisualCV

Mostly, I like this Engineer profile: http://www.visualcv.com/alex1
The really good part is the "code sample" section on the top-right corner...

Have fun...

Saturday, April 11, 2009 5:56:02 AM (GMT Daylight Time, UTC+01:00)  #    Comments [0] - Trackback
Life | Software Development

<July 2010>

The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2014
Shani Raba
Sign In
Total Posts: 146
This Year: 0
This Month: 0
This Week: 0
Comments: 97
Cool Stuff
Add to Technorati Favorites
Pick a theme:
All Content © 2014, Shani Raba
DasBlog theme 'Business' created by Christoph De Baene (delarou)