Random programming things I'd want to remember

Monday, January 20, 2014

System.Windows.Control.ListBox does not scroll

An interesting one today. My ListBox would not scroll, and after looking into all usual suspects it still would not work. Turns out that the offender was the Grid, containing the ListBox. Here is XAML:
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <StackPanel Orientation="Horizontal">
                ...
            </StackPanel>            
           
            <ListBox ItemsSource="{Binding}" Grid.Row="1">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Description}" />
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </Grid>

My ListBox has a bunch of items and it does not scroll, even though there is no StackPanel in the DataTemplate. But, if I change the RowDefinition on the second row to say
                <RowDefinition Height="*" />

Then it scrolls just fine.

Friday, January 10, 2014

Initial git setup for a local project

Git is a great version control system available for free for private use. It is easy and very efficient. There is a short free book that explains the basics. Here is my short take on how to set up a git project locally (assuming that Git is already installed in the system.)

Open up the command shell and navigate to the root folder of the project. Then, issue the following commands (all comments come after the "#" mark):

  git init #initialize a git repository here
  notepad .git/info/exclude #optional step, here you can exclude files or folders that need no tracking
  #notepad will open with the document where you can type in values. 
  #If nothing needs to be excluded, just close the file.
  #to exclude a folder, mark it as so: bin/
  #to exclude all files with extension "sap", type in *sap
  git add . #to add all files recursively
  git status #(optional)see the files that will be committed.
  git commit -m "initial version" #commit with message "initial version"
  git log #check what's committed



Update from Feb 28, 2014: Here is another way to set up git locally, the difference between the script above is that the excluded files will be tracked by ".gitignore" file rather than "exclude" file. For sample of .gitignore files, check out this GitHub repository: github/gitignore, there are plenty of examples there for all kinds of programming projects. Here is the script:

  git init #initialize a git repository here, make sure you have a .gitignore file in the root folder of your project
  git add .gitignore #(optional)create or add a file that specifies which file(types) and/or folders to ignore
  git commit -m "Added .gitignore" #optional if you did not add .gitignore file
  git add . #to add all files recursively
  git status #(optional) see the files that will be committed.
  git commit -m "initial version" #commit with message "initial version"
  git log #check what's committed

And the first commit is done. It's that easy. To utilize tags, branching/merging, and other features of git that make it so good, read the book. The next logical step for the local repository is to create a distributed repository online and upload your code there. Bitbucket or GitHub are a places to start looking around.


Thursday, January 9, 2014

Monday, January 6, 2014

Karma, Angular.JS "Module is not available!" error

I was troubleshooting "Module '{0}' is not available!" error while testing an Angular.js app with karma and it got me puzzled quite a bit. Worst of all -- Google was not helpful (which clearly indicated that the problem is at my end). This url: http://docs.angularjs.org/error/$injector:nomod did not help either. My problem was that I forgot to include my controller js file into the files: [] array in karma configuration. Doh!

C# display integer in binary format

I was trying to understand an algorithm in this post here and it helped to visualize integers in binary format. A bit of Googling showed exactly how to do that:
    Convert.ToString(value, 2);