Everyone knows Google app engine But what about .net apps? Meet AppHarbor (Thanks Gadi) So I wanted to give it a chance and after playing for less than an hour: - Enable you to build \ host \ deploy web apps
- Provide both Version control and hosting service
- Absolutely free (for now)
- Damn simple
Short tutorial on how to do it: - Create your appharbor account + create new application
- Hopefully you have Git installed (msysgit downloads)
- Init empty Git repository
git init test1 - Copy your files to this directory (download from here: https://github.com/appharbor/appharbor-splash )
- Add files and subdirectories
git add . - Create your remote repository
git remote add appharbor https://username@appharbor.com/test-178.git - Commit your code
git commit -m 'firstcommit' - Almost forgot, we are working on Git - so don't forget to push...
git push appharbor master Till here everything should work but I had a small issue, got this error: error setting certificate verify locations: I've found out that it is all about versions (git --version) - So check yours and upgrade if needed Here you can find great cheat sheet for Git commands: http://ionrails.com/2009/08/07/git-commands-adding-and-committing-cheatsheet/ Btw, AppHarbor support Databases and Running unit-testing after successful builds – I will post about those features later on.
Lately my “find usages” (shift+F12) stopped working. I tried to restore ReSharper again and again but it fails (ReSharper –> find usages –> General –> restore ReSharper) I’ve found out that some other shortcuts still working (for example: find usages advanced, CTRL+SHIFT+ALT+F12) Then I checked the visual studio binding (Tools->Options->Keyboard) and find out that ReSharper.Find binding is missing. I thought about fixing this manually – but god knows what also is not working. And then I found out the magical button called RESET -> clicking on this and running the restore ReSharper again solve this issue! Cheers…
Finally I’ve found some time to customize my blog with tiny change: FB:Like Plugin – Whenever you LIKE it – let me know. This will be shared with your friends and help me spread my ideas. Tip #1 - FB:Like Plugin If you are using dasblog and you want to add this to your theme use the PermaLinkUrl macro - href=”<%PermalinkUrl%>” Tip #2 – measure using FB insights You can track the trends here http://www.facebook.com/insights BUT in order to see it you should add meta-tag your head <meta property="fb:admins" content="user_id" /> Have fun.
Delver is a “Social Shopping Platform”, You are more than welcome to check our website at www.delver.com We are still in “closed beta” but, leave me a comment or an email and I will send you an invitation. We also opened our Blog where we will post about new features, technology and other cool stuff.
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. IIS7: 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:
<configuration>
<system.webServer>
<staticContent>
<mimeMap fileExtension=".mp4" mimeType="video/mp4" />
</staticContent>
</system.webServer>
</configuration>
Apache:
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.
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/'; 3: 4: $('.VideoTeaserArea').click(function() { 5: $(this).openLightBox("<div id='media'></div>"); 6: playMovie('intro-movie.swf'); 7: }); 8: 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.
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: - Create a video file in a common streaming media format (in our case: Camtasia -> SWF, mp4)
- Upload the files to your Web Server
- Check whether this link is working from common browsers
- 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
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.
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). Have fun.
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: - human-readable (code standard, pattern etc.)
- code re-use (copy paste is never acceptable)
- 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: } 9: 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: } 7: 8: 9: [Test] 10: public void GetCommnentsByQuery_LookForHmmmText_VerifyInsideComment() 11: { 12: string textToSearch = "Hmmm..."; 13: GetCommentsByQuery_AssertAllItemsStartsWith(textToSearch); 14: } 15: 16: public void GetCommentsByQuery_AssertAllItemsStartsWith(string textToSearch) 17: { 18: SvnLogParser parser = new SvnLogParser(); 19: var results = parser.GetCommentsByQuery(comment => comment.StartsWith(textToSearch)); 20: 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...")'
failed:
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
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...
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):
//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:
//2_simpleObjects.st
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"); 4: 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:
//3_simpleLoop.st
$items: {num1|
<li>$num1$</li>
}$
$end$
and bind the list using this code:
1: var templateFolder = new StringTemplateGroup("SimpleLoopTemplates", @"C:\Tempaltes\TemplateEngineTestCase"); 2: var template = templateFolder.GetInstanceOf("3_simpleLoop"); 3: 4: template.SetAttribute("items", new List<string> {"Shani", "Doron", "Nati", "Yossi"});
Conclusion:
- 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.
|