Showing posts with label Tips. Show all posts
Showing posts with label Tips. Show all posts

Friday, January 20, 2012

WCF-4 Client/Host quick start/tutorial

For those of you who already know WCF basics and need to start quickly here are guidelines to start a working client-server/service project:

My Quickest Start
  1. Designing Service Contracts
    1. Start simple, grow in time.
  2. Implement the contract
  3. Host the service - Console (starting simple).
    1. http://msdn.microsoft.com/en-us/library/ms731758.aspx
      1. New 'Console Application'
      2. See 'Example Host Code' below...
        1. Add Reference.... Select System.ServiceModel
        2. Reference 'ServiceModel'
        3. Start the service code
          1. Using
          2. Open
          3. Close
  4. Disable WcfSvcHost (if needed)
    1. "Right-click the WCF Service Project in Solution Explorer, choose Properties, and click WCF Options tab. The Start WCF Service Host when debugging another project in the same solution check box is enabled by default."
  5. CLIENT SIDE - Obtain the Service Contract, Bindings, and Addresses
    1. Enable the service
      1. Set the Host as the default startup program and run in without debugger (usually <CTRL>+F5).
    2. 'Add Service Reference...' 
      1. Past the service address in the 'Address' field and 'Go'.
      2. Point the service and 'OK' =results=> a new client proxy code will be generated in your client.
    3. SET YOUR CLIENT APPLICATION AS THE STARTUP PROGRAM :)
    4. Add service usage code to your client (see 'Example Client Code' below...).
  6. Run and relax :-).

    Example Host Code
    Code Snippet
    1. using System;
    2. using System.Collections.Generic;
    3. using System.Linq;
    4. using System.Text;
    5.  
    6. using System.ServiceModel;
    7. using System.ServiceModel.Description;
    8. using MyWcfLib;
    9.  
    10.  
    11. namespace MyServer
    12. {
    13.     class Program
    14.     {
    15.         static void Main(string[] args)
    16.         {
    17.             Uri baseAddress = new Uri("http://localhost:9090/hello");
    18.  
    19.             using (ServiceHost host = new ServiceHost(typeof(MyService), baseAddress))
    20.             {
    21.                 // Enable metadata publishing.
    22.                 ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
    23.                 smb.HttpGetEnabled = true;
    24.                 smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
    25.                 host.Description.Behaviors.Add(smb);
    26.  
    27.                 // Open the ServiceHost to start listening for messages. Since
    28.                 // no endpoints are explicitly configured, the runtime will create
    29.                 // one endpoint per base address for each service contract implemented
    30.                 // by the service.
    31.                 host.Open();
    32.  
    33.                 Console.WriteLine("The service is ready at {0}", baseAddress);
    34.                 Console.WriteLine("Press <Enter> to stop the service.");
    35.                 Console.ReadLine();
    36.  
    37.                 // Close the ServiceHost.
    38.                 host.Close();
    39.             }
    40.  
    41.         }
    42.     }
    43. }

    Example Client Code
    Code Snippet
    1. using System;
    2. using System.Collections.Generic;
    3. using System.Linq;
    4. using System.Text;
    5.  
    6. namespace ConsoleApplication1
    7. {
    8.     class Program
    9.     {
    10.         static void Main(string[] args)
    11.         {
    12.             var client = new ServiceReference1.MyServiceClient();
    13.  
    14.             Console.WriteLine(client.GenerateGuid().ToString());
    15.             client.Close();
    16.  
    17.             Console.ReadLine();
    18.         }
    19.     }
    20. }


    MSDN's 'Basic Programming Lifecycle'


    Please, post comments if you find errors.
    I'll fix them ASAP and others can enjoy a cleaner clode.

    Hope it helps...

    Saturday, January 7, 2012

    WPF, XAML: TreeView HierarchicalDataTemplate databinding to unknown XML/DataSource

    Problem description
    • I wish to bind my TreeView to a datasource.
    • The TreeView should build its child nodes dynamically (unknows childs in datasource).
    • Each node should display its data or (if no data) its element name.

    Solution
    You need to use and understand these parts:
    1. HierarchicalDataTemplate
      1. HierarchicalDataTemplate.Triggers
    2. Binding XPath

    Usage Example
    Just copy paste and start playing / reading each part's help.

    XAML
    Code Snippet
    1. <Window x:Class="TreeViewDataBinding.Window1"
    2.     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    3.     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    4.     Title="Window1" Height="300" Width="300">
    5.     <Window.Resources>
    6.         <HierarchicalDataTemplate x:Key="NodeTemplate" >
    7.  
    8.             <TextBlock x:Name="tbName" Text="?" />
    9.  
    10.             <HierarchicalDataTemplate.ItemsSource>
    11.                 <Binding XPath="child::node()" />
    12.             </HierarchicalDataTemplate.ItemsSource>
    13.  
    14.             <HierarchicalDataTemplate.Triggers>
    15.                 <DataTrigger Binding="{Binding Path=NodeType}" Value="Text">
    16.                     <Setter TargetName="tbName" Property="Text" Value="{Binding Path=Value}"/>
    17.                 </DataTrigger>
    18.                 <DataTrigger Binding="{Binding Path=NodeType}" Value="Element">
    19.                     <Setter TargetName="tbName" Property="Text" Value="{Binding Path=Name}"/>
    20.                 </DataTrigger>
    21.             </HierarchicalDataTemplate.Triggers>
    22.         </HierarchicalDataTemplate>
    23.  
    24.         <XmlDataProvider x:Key="xmlDataProvider"/>
    25.     </Window.Resources>
    26.     
    27.     <StackPanel>
    28.         <Button Click="Button_Click">Reload</Button>
    29.         
    30.         <TreeView
    31.             ItemsSource="{Binding Source={StaticResource xmlDataProvider}, XPath=*}"
    32.             ItemTemplate="{StaticResource NodeTemplate}" />
    33.     </StackPanel>
    34. </Window>

    Code behind
    Code Snippet
    1. using System.Windows;
    2. using System.Windows.Data;
    3. using System;
    4.  
    5. namespace TreeViewDataBinding
    6. {
    7.     public partial class Window1 : Window
    8.     {
    9.         public Window1()
    10.         {
    11.             InitializeComponent();
    12.         }
    13.  
    14.         private void Button_Click(object sender, RoutedEventArgs e)
    15.         {
    16.             var provider = (XmlDataProvider)this.Resources["xmlDataProvider"];
    17.             provider.Source = new Uri(@"Data\standard.xml", UriKind.Relative);
    18.         }
    19.     }
    20. }

    Additional files



    Performance
    I was able to load 100MB of xml data in around ~6 seconds first time, ~4 seconds from the second time.

    Testbench station
    • i7 (8 cores) @ 2.80GHz
    • 4.00GB RAM
    • 64-Bit OS, Win7 Pro.
    CPU & memory usage
    The CPU was at idle when i started, the RAM was at the base line.

    Results

    Resources

    Hope it helps.

    Wednesday, December 28, 2011

    How to change paypal button image in magento...

    Don't even bother finding the solution at Magento Admin Panel or at PayPal :), spent quit a time looking for the solution over there.

    Steps

    1. You need to access the file (using ftp...) located here:
      1. /app/design/frontend/base/default/template/paypal/express/shortcut.phtml
    2. Edit it:
      1. find the line that contains "img src=".
      2. replace the source with your wanted 'Pay with PayPal' image path.
    Results
    I've managed to change it from this one:

    To this one:



    Resources

    Using PayPal express with magento.

    The story
    I was asked to give the user the ability to pay using PayPal services.
    The site is magento store.
    The user will have two option at PayPal:

    1. He have an acount and will pay after he logged into his PayPal account.
    2. He have no account - he is NOT requiered to open a PayPal account to pay, he'll enter his credit credentiols and pay.
    Simple, right? :-)

    I got into some problems, the community help on this matter is not so obvious, after a day of research and experements, which hopefuly you will avoid,  here are the final steps did to satisfy these requierments:


    The solution
    On Magento Admin Panel
     
    • Magento admin panel => Menu => System => Configuration, click.
    • In the left configuration panel => Sales => PayPal, click.
    • "Email Associated with PayPal Merchant Account" => enter your PayPal account email.
    • "Select a PayPal Solution" => "Express Checkout", checked
    • At "Express Checkout Settings" (*2):
      • "Payment Action" : Usually Sale .
      • "Enable PayPal Guest Checkout" => Yes
      • SAVE CONIFG!
    • At "API/Integration Settings":
      • API Authentication Methods => API Signiture.
      • Get Credentials from PayPal, click:
        • Entering PayPay... Enter your PayPal credential...
        • Just get your API credentials through Profile > My selling tools > API Access > Update > Request API credentials > Request API Signature (*1)
      • Enter the API credentioal, appropriattly, to:
        • API Username, Password & Signature.
      • SAVE CONIFG!
    These steps created a fast & secure checout point for my users to buy products without PayPay account.

    Hope it helped.

    Resources

    Saturday, December 24, 2011

    MAGENTO: can't "Log in to Admin Panel"

    Just solved this problem.

    Problem description
    I've instaled magento in my local computer and I can't login to the admin panel.

    Understanding the problem
    Magento doesn't work well with 'localhost' and '127.0.0.1'. After some readings on the net I understood that these addresses won't allow cookies, resolting in admin panel login failure.

    Solution
    Edit 'host' file located at 'C:\Windows\System32\drivers\etc'.
    Add a new line, for example:
    127.0.0.1 shloemi.com # Localhost virtual development site.

    Usage
    You can now acces magento admin pannel using the site shloemi.com.
    Example: http://shloemi.com/Magento/index.php/

    Saturday, December 10, 2011

    MSConfig - System Configuration UI


    Very helpfull tool.


    (*1) "Some of its functionality varies by Windows versions:

    • In Windows 98 and Windows Me, it can configure advanced troubleshooting settings pertaining to these operating systems. It can also launch common system tools.
    • In Windows 98, it can back up and restore startup files.
    • In Windows Me, it has also been updated with three new tabs called "Static VxDs", "Environment" and "International". The Static VxDs tab allows users to enable or disable static virtual device drivers to be loaded at startup, the Environment tab allows users to enable or disable environment variables, and the International tab allows users to set international language keyboard layout settings that were formerly set via the real-mode MS-DOS configuration files. A "Cleanup" button on the "Startup" tab allows cleaning up invalid or deleted startup entries.
    • In Windows Me and Windows XP versions, it can restore an individual file from the original Windows installation set.
    • On Windows NT-based operating systems prior to Windows Vista, it can set various BOOT.INI switches.
    • In Windows XP and Windows Vista, it can hide all operating system services for troubleshooting.
    • In Windows Vista and later, the tool gained additional support for launching a variety of tools, such as system information, other configuration areas, such as Internet options, and the ability to enable/disable UAC. An update is available for Windows XP and Windows Server 2003 that adds the Tools tab.[1] It also allows configuring various switches for Windows Boot Manager and Boot Configuration Data."




    Read more about it here - http://en.wikipedia.org/wiki/MSConfig

    To activate it, WIN+R (or Start-->Run), then run 'msconfig'.

    Result

    Resources

    Friday, December 9, 2011

    WPF XAML TIP: Label with Target + Control composition == Hotkey control

    Code snippet

    Code Snippet
    1. <Border DockPanel.Dock="Top">
    2.     <StackPanel>
    3.         <Label
    4.             Content="_Last Name:"
    5.             Target="{Binding ElementName=lastName}" />
    6.         <TextBox x:Name="lastName" Width="100" HorizontalAlignment="Left"/>
    7.     </StackPanel>
    8. </Border>


    Usage 
    Press ALT+L to focus the TextBox control 'lastName'.

    Result

    Wednesday, December 7, 2011

    TUTORIAL: VS - Creating Code Snippets - CodeProject

    I was in the middle of creating my experiance/article about the snippets subject when I got an email from http://www.codeproject.com/ with this wonderful article.

    Extending Visual Studio Part 1 - Creating Code Snippets - CodeProject

    I've already created some snippets, feel free to use them:

    'Decorator-Pattern' snippet (activation: dp_decorator + TAB):
    Code Snippet
    1. xml version="1.0" encoding="utf-8" ?>
    2. <CodeSnippetsxmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    3. <CodeSnippet Format="1.0.0">
    4. <Header>
    5. <Title>Decorator DPTitle>
    6. <Shortcut>dp_decoratorShortcut>
    7. <Description>Code snippet for decorator design patternDescription>
    8. <Author>S.OAuthor>
    9. <SnippetTypes>
    10. <SnippetType>ExpansionSnippetType>
    11. SnippetTypes>
    12. Header>
    13. <Snippet>
    14. <Declarations>
    15. <Literal>
    16. <ID>ComponentID>
    17. <ToolTip>Component nameToolTip>
    18. <Default>ComponentDefault>
    19. Literal>
    20. <Literal>
    21. <ID>DecoratorID>
    22. <ToolTip>Decorator nameToolTip>
    23. <Default>DecoratorDefault>
    24. Literal>
    25. Declarations>
    26. <Code Language="csharp">
    27. // Decorator patern:
    28. // http://en.wikipedia.org/wiki/Decorator_pattern#Structure
    29. // http://www.dofactory.com/Patterns/PatternDecorator.aspx
    30. abstract class $Component$
    31. {
    32. public abstract void Operation();
    33. }
    34. abstract class $Decorator$ : $Component$
    35. {
    36. protected $Component$ _$Component$;
    37. public void SetComponent($Component$ component)
    38. {
    39. this._$Component$ = component;
    40. }
    41. public override void Operation()
    42. {
    43. if (_$Component$ != null)
    44. {
    45. _$Component$.Operation();
    46. // + [your operation here]
    47. }
    48. }
    49. }
    50. $end$
    51. ]]>
    52. Code>
    53. Snippet>
    54. CodeSnippet>
    55. CodeSnippets>

    The 'Event changed property' snippet (eprop + TAB):
    Code Snippet
    1. xml version="1.0" encoding="utf-8" ?>
    2. <CodeSnippetsxmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    3. <CodeSnippet Format="1.0.0">
    4. <Header>
    5. <Title>event changed propertyTitle>
    6. <Shortcut>epropShortcut>
    7. <Description>Code snippet for eprop...Description>
    8. <Author>SOAuthor>
    9. <SnippetTypes>
    10. <SnippetType>ExpansionSnippetType>
    11. SnippetTypes>
    12. Header>
    13. <Snippet>
    14. <Declarations>
    15. <Literal Editable="true">
    16. <ID>prop_nameID>
    17. <ToolTip>property nameToolTip>
    18. <Function>PropName()Function>
    19. <Default>PropNameDefault>
    20. Literal>
    21. <Literal Editable="true">
    22. <ID>prop_typeID>
    23. <ToolTip>property typeToolTip>
    24. <Function>PropType()Function>
    25. <Default>ObjectDefault>
    26. Literal>
    27. Declarations>
    28. <Code Language="csharp">
    29. #region $prop_name$
    30. ///
    31. /// Occurs when $prop_name$ changes.
    32. ///
    33. public event EventHandler $prop_name$Changed;
    34. ///
    35. /// Raises the event.
    36. ///
    37. /// The instance containing the event data.
    38. protected virtual void On$prop_name$Changed(EventArgs e)
    39. {
    40. if ($prop_name$Changed != null)
    41. $prop_name$Changed(this, e);
    42. }
    43. private $prop_type$ _$prop_name$ = null;$end$
    44. ///
    45. /// Gets or sets the type of the region.
    46. ///
    47. ///
    48. /// The type of the region.
    49. ///
    50. public $prop_type$ $prop_name$
    51. {
    52. get { return _$prop_name$; }
    53. set
    54. {
    55. if (_$prop_name$ != value)
    56. {
    57. _$prop_name$ = value;
    58. On$prop_name$Changed(new EventArgs());
    59. }
    60. }
    61. }
    62. #endregion
    63. ]]>
    64. Code>
    65. Snippet>
    66. CodeSnippet>
    67. CodeSnippets>

    And the 'TODO' snippet (TD + TAB), need some polish like auto date/time stamp, priority...:
    Code Snippet
    1. xml version="1.0" encoding="utf-8" ?>
    2. <CodeSnippetsxmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    3. <CodeSnippet Format="1.0.0">
    4. <Header>
    5. <Title>TODOTitle>
    6. <Shortcut>TDShortcut>
    7. <Description>Code snippet for TODO...Description>
    8. <Author>SOAuthor>
    9. <SnippetTypes>
    10. <SnippetType>ExpansionSnippetType>
    11. SnippetTypes>
    12. Header>
    13. <Snippet>
    14. <Declarations>
    15. Declarations>
    16. <Code Language="csharp">// TODO:P, TimeStamp, S.O: $end$]]>
    17. Code>
    18. Snippet>
    19. CodeSnippet>
    20. CodeSnippets>

    My advice: if you already created a code pattern twice (meaning - you copied and pasted a code and renamed some variables and function/property names), add it to your snippets, you'll need it and it will save time.

    REMARK: Please follow the codeproject artical if you wish to install/use them...


    Tuesday, December 6, 2011

    TIP: Creating a file, fast, with incremental values (using FOR /L).

    I needed to create a file (called urls.txt) that contains lots of image urls, here is the solution:


    1. Create a batch file (I'll call it gget.bat).
    2. copy and paste the following to gget.bat file.

    REM ~~~~~ gget.bat file content ~~~~~~~~~~~~~~~

    @echo off
    for /L %%a in (0,1,1984) do (
    echo http://domain.com/images/%%a.jpg >>c:\urls.txt
    )

    ECHO DONE!
    pause
    REM ~~~~~ gget.bat file content ~~~~~~~~~~~~~~~


    1. change the numbers in "(0,1,1984)" to the desired ones (please read more about 'FOR /L' here.).
    the result is a file 'c:\urls.txt' that contains this:

    http://domain.com/images//0.jpg 
    http://domain.com/images//1.jpg 
    http://domain.com/images//2.jpg 
    http://domain.com/images//3.jpg 
    ...
    http://domain.com/images//1983.jpg 
    http://domain.com/images//1984.jpg 

    Hope it helps...

    Monday, December 5, 2011

    TIP - How to check an errorlevel of a program...

    First understand a little about error levels... Batch files - Errorlevels:

    Next... Write this code the a batch file and run it (change the runme.exe to the program that you wish to check the error-level).
    #~~~~~~~~~~~~~~~~~~~~~~~~~
    runme.exe
    ECHO.%ERRORLEVEL%
    PAUSE
    #~~~~~~~~~~~~~~~~~~~~~~~~~

    Hope it helps...

    Tuesday, November 15, 2011

    Example: C# dynamic 'Enum' like solution.

    Example usage:


    Code Snippet
    1. using System;
    2. using System.Collections.Generic;
    3.  
    4. namespace GuiLib.TeraRegion
    5. {
    6.     public class TeraRegionModel
    7.     {
    8.  
    9.         /// <summary>
    10.         /// Dynamic enum of RegionTypes.
    11.         /// <remarks>* This is a [Flags] and normal mixed enum!
    12.         /// * 0 is reserved! it's not used!
    13.         /// * 1 is reserved! it's void.
    14.         /// Find it's max and assigne it's next value like this:
    15.         ///     var next_enum_val = RegionTypes.Values.Max<ulong>();
    16.         ///     RegionTypes.Add("new_item", next_enum_val*2);
    17.         /// </remarks>
    18.         /// </summary>
    19.         public static Dictionary<string, ulong> RegionTypes = new Dictionary<string, ulong>()
    20.         {
    21.             {"void", 1}
    22.         };
    23.  
    24.  
    25.         #region RegionType
    26.  
    27.         /// <summary>
    28.         /// Occurs when RegionType changes.
    29.         /// </summary>
    30.         public event EventHandler RegionTypeChanged;
    31.  
    32.         /// <summary>
    33.         /// Raises the <see cref="E:RegionTypeChanged"/> event.
    34.         /// </summary>
    35.         /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
    36.         protected virtual void OnRegionTypeChanged(EventArgs e)
    37.         {
    38.             if (RegionTypeChanged != null)
    39.                 RegionTypeChanged(this, e);
    40.         }
    41.  
    42.         private ulong _RegionType = 1;
    43.  
    44.  
    45.         /// <summary>
    46.         /// Gets or sets the type of the region.
    47.         /// </summary>
    48.         /// <value>
    49.         /// The type of the region.
    50.         /// </value>
    51.         public ulong RegionType
    52.         {
    53.             get
    54.             {
    55.                 return _RegionType;
    56.             }
    57.  
    58.             set
    59.             {
    60.                 if (_RegionType != value)
    61.                 {
    62.                     _RegionType = value;
    63.  
    64.                     OnRegionTypeChanged(new EventArgs());
    65.                 }
    66.             }
    67.         }
    68.         #endregion
    69.  
    70.     }
    71. }

    Monday, November 14, 2011

    Tip: C# dynamic 'Enum' like solution.

    Hi,
    This is very usefull if you wish to be able to create dynamic enums.

    Motivation
    * You need to enumerate something but wish to add items to it in runtime (e.g. your server should support v1 protocol and v2 protocol where v2 protocol extends v1.enum).

    * You wish to extand this enum dynamically by an outside addin.

    Solution and prof



    Code Snippet
    1. enum MyEnum : ulong
    2. {
    3.     // NOTICE: string_name = ulong_value,
    4.     first = 2<<0,
    5.     second = 2<<1,
    6.     last = 2<<2,
    7.  
    8.     max = 2 << 63
    9.     // dynamic string name = dynamic ulong value!
    10. }
    11.  
    12. Dictionary<string, ulong> DynamicEnum1 = new Dictionary<string, ulong>()
    13. {
    14.     {"first", 2 << 0},
    15.     {"second", 2 << 1},
    16.     {"last", 2 << 2},
    17.  
    18.     {"max", 2 << 63}
    19. };
    20.  
    21. public void usage()
    22. {
    23.     MyEnum qwe = MyEnum.first;
    24.  
    25.     DynamicEnum1.Add("another_one", 2 << 3);
    26.     UInt64 qwe2 = DynamicEnum1["first"];
    27.  
    28.     // (UInt64)qwe == qwe2!!
    29. }


    Hope it helps.

    Monday, October 10, 2011

    Bad experience: Reasons why the last project was a disaster.

    Usually I try my best to work in an ordered manner.
    This means:

    1. Interview the project manager (the person responsible for the success of the project) for the story.
    2. Convert this story to requirements.
    3. Present the project manager with the requirements.
    4. If approved go to the next level.
    5. Do a High Level Design (HLD) 
    6. Present this HLD sidelong the requirements and estimate roughly the solution time in human days labor.
    7. If approved go to the next level.
    8. Breakdown the HLD to low level design (LLD).
    9. Estimate LLD and present estimated more accurately time  in human labor.
    10. If approved go to the next level.
    11. Implement the LLD and stick to it (no time for adventures).
    12. Do unit test, system test as much as i can (depends, sometimes not possible).
    13. Present a working machine.
    14. Be happy and relax.

    This time, everything went wrong! Why?

    Here were the flow of things:
    1. Pressure to implement as fast as possible (reasons: no time, no budget).
      1. I broke and agreed to 'be fast'.
    2. Skip HLD + LLD, start implement! ==> no thoughts of risks, everything looks easy when you don't think about it deeply.
    3. Implementation got some problems I didn't see in advance (and frankly, none can think that deeply).
    4. More and more problems arose ==> delivery time breaks ==> more pressure.
    5. No one is happy, all is waiting for the delivery => more pressure ==> shorter code, less secure code, BAD CODE!
    6. ... The test-bench is too complex to operate... Catastrophic :-)

    Next time - Do it right! 
    If the project manager don't want to do it right, ignore him :), take your time, design it, show him the design, say 'i thought about it and found some problems' (when doing the hiding HLD + LLD).


    You only get an advantage in the start, when things get rough (and they do!) you will cross the break-point and start to be slow (because you can't load all the HLD into your head).

    In the end the project worked, the code, barely, but did managed to work, the time for this project took much longer then 'fast and short' (twice if not more the time it should take), and a bad taste was in the mouths.

    Wednesday, September 28, 2011

    getopt — Python's C-style parser for command line arguments.

    Need to support command line arguments and options in your new Python program, here's what I've found:

    Example code - http://www.eurion.net/python-snippets/snippet/Show%20getopt.html
    Tutorial - http://www.doughellmann.com/PyMOTW/getopt/
    Documentation - http://docs.python.org/library/getopt.html

    Tip: HEX to BINARY File Converter Utility

    In some cases - It's much easy to write in HEX in text then convert it to BIN file.

    Intel HEX to BINARY File Converter Utility
    http://hex2bin.sourceforge.net/
    Direct file download: http://www.hex2bin.com/hex2bin/

    Bat To Exe Converter

    Here is an example of requierments:

    • Create a script that automate blabla.... (I've presented a batch file after an hour or so).
    After 5 sec:
    • The script will be presented to out client as an exe file.


    Well, here is the tool I used for the job: Bat To Exe Converter

    Other utils that might come handy:

    Thursday, April 7, 2011

    GUIDE: TDD unit testing tools for Tcl

    As promised in http://shloemi.blogspot.com/2011/03/tdd-tools-for-tcl.html here is my experience with tcltest package and eclipse.


    The story
    Suppose we have a function called 'bits_serialize'.

    This function should serialize a given data into bits_per_io bits per package (for examples see the tests below and what they return).

    This function have the following signature:  bits_serialize {bits_per_io description}, where:
    • bits_per_io
      • How much bits each package have.
    • description
      • a pair of {data bits}, where:
        • data 
          • the data we want to serialize.
        • bits
          • the size, in bits, we want to serialize this data.
    let's test this function using tcltest...

    Test code
    # Generated using http://pygments.org/
    source unit-under-test.tcl ;# contains the definition of bits_serealize 
    
    test base--always-ok {This is as simple as it gets.} -constraints {
    } -setup {
    } -body {
     return TRUE
    } -cleanup {
    } -result TRUE
    
    test bits_serealize--partial-quanta {description here...} -constraints {
    } -setup {
    } -body {
     return [bits_serealize 32 " 0x01 16 "]
    } -cleanup {
    } -result [list 1]
    
    test bits_serealize--full-quanta {description here...} -constraints {
    } -setup {
    } -body {
     return [bits_serealize 32 " 0xFFFFFFFF 32 "]
    } -cleanup {
    } -result [list [ format "%u" 0xFFFFFFFF ]]
    
    test bits_serealize--over-quanta {description here...} -constraints {
    } -setup {
    } -body {
     return [bits_serealize 32 " 0x060504030201 64 "]
    } -cleanup {
    } -result [list [ format "%u" 0x04030201 ] [ format "%u" 0x0605 ]]
    
    test bits_serealize--way-over-quanta {description here...} -constraints {
    } -setup {
    } -body {
     return [bits_serealize 32 " 0x060504030201 320 "]
    } -cleanup {
    } -result [list [ format "%u" 0x04030201 ] [ format "%u" 0x0605 ] 0 0 0 0 0 0 0 0]
    
    test bits_serealize--cross-quanta {description here...} -constraints {
    } -setup {
    } -body {
     return [bits_serealize 32 "
      0xFF 1
      0xFF 2
      0xFF 3
      0xFF 4
      0xFF 6
    
      0x04030201 32
     "]
    } -cleanup {
    } -result [list [ format "%u" 0x201FFFF ] [ format "%u" 0x403 ]]
    
    test bits_serealize--quanta-and-half {description here...} -constraints {
    } -setup {
    } -body {
     return [bits_serealize 32 "
      0xFFEEDDCCBBAA 48
     "]
    } -cleanup {
    } -result [list [ format "%u" 0xDDCCBBAA ] [ format "%u" 0xFFEE ]]
    


    eclipse-unit-testing

    Results

    ++++ base--always-ok PASSED
    ++++ bits_serealize--partial-quanta PASSED
    ++++ bits_serealize--full-quanta PASSED
    ++++ bits_serealize--over-quanta PASSED
    ++++ bits_serealize--way-over-quanta PASSED
    ++++ bits_serealize--cross-quanta PASSED
    ++++ bits_serealize--quanta-and-half PASSED

    My impression 

    I definitely recommend using this unit!! and to my surprise eclipse supports it built in (see picture ==>).