Saturday, February 20, 2016

How to Search with Git

Git offers several powerful options to search for commits or changes.

Find Files by Content Pattern: Git Grep

To search for a specific pattern in repository files, you can use the Git grep command.

git grep pattern

Pattern can be a regular expression.

By default Git grep searches in the current directory but you can pass a branch name or directory to search instead. Git grep has two advantages over the shell's grep command. First, it only searches tracked files so you get more relevant results. Secondly, the shell's grep command requires that you have all the source files you need to search locally. On the other had, Git grep can search any known branch whether it's checked out or not and whether it's local or remote.

git grep pattern remote/branch

Here we search a remote branch that doesn't exist in the local repository for a pattern.

Find Commits by Message Pattern: Git Log Grep

To find commits by a pattern in the message added with the commit, not the diff, use the --grep option for the git log command.

git log --grep='Fixing bug 103'

Find Commits by Diff: Pickaxe

To find commits using the actual diff the commit added you can use the -S option for the log command, which is known as pickaxe. Note there's no space after the -S.

git log -Skeyword
git log -Smethod()

Find Commit by Line: Blame

To find the commit id for each line in a file use the git blame command. This command will show the commit that added each line in the file. This is useful when trying to figure out which commit introduced a change.

git blame filename

Find Commit by Test: Bisect

Bisect is a binary search mode Git offers to find a commit that introduced a bug or problem by allowing the user to examine commits and specify whether the commit is good or bad until, using binary search, Git narrows down the search and finds the single commit needed. You are free to use whatever test needed to determine whether the commit you have is good or bad. This is useful when we are searching by functionality or behavior not a pattern.

Git needs to know the last known good commit to have a starting point for searching. Git also needs a bad commit which is by default HEAD.

git bisect start
git bisect bad
git bisect good HEAD~20

In the commands above, we tell Git to start bisect search. Then we specify HEAD as a bad commit and the commit 20 changes back as the last known good commit.

Now Git will start checking out commits and asking whether the commit is good or bad.

git bisect bad
git bisect bad
git bisect good
git bisect good
git bisect bad

Now bisect search ends and Git tells us exactly which commit introduced the first bad change.

Dangling Commits: Git Fsck

Finally, the commit we need might be dangling and thus not searchable by the above methods. A commit is considered dangling if it is not connected to the repo tree, meaning there is no path of changes that a user can use to see the commit or checkout its changes.

A commit that is disconnected from other objects is referenced by the reflog for a configurable period with a default of 90 days before it becomes dangling. After the reflog expiration for disconnected objects, the commit is garbage collected and becomes dangling.

To find dangling commits use the Git fsck command. If there are any dangling commits, they will be shown.

git fsck

If you find a dangling commit, you can see its content using the Git show command.

git show commit-hash-id

To see the diff:

git show -p commit-hash-id



posted by T Alrahem
0 Comments    Links to this post

Wednesday, January 25, 2012

How to Release iOS Ad Hoc Beta Builds with Xcode

After you have a running app and you have done enough testing on your iPhone and your other iDevices, the next step before submitting to the AppStore is to test on as many devices as possible. This type of testing is usually called beta testing. Beta testing is crucial in developing a great mobile app because of generally two types of feedback given by beta testers:
  1. Compatibility problems. Even though everything might be sweet and sublime on your iPhone or iPad, it might not be the case for every combination of device and iOS version. Beta testing with hardware/software diverse testers will uncover all or most of those problems.
  2. General story/usability flaws. This category is not about bugs. It's about understanding what part was confusing to your beta users or what false assumptions did you make. Beta testing will help bring your assumptions and perspective inline with real users.

In this guide I will give the procedure for how to generate ad hoc builds that you can send to your beta testers to try. I could not find a single tutorial that covered all the related issues so I decided to write this. This procedure does not require registering in the iOS Developer Enterprise Program. All that is required is the standard iOS Developer Program. This guide was written using Xcode 4.2.

  1. Ask your users for their device ID's and add them in the iOS Provisioning Portal. Testers can find their device ID's from iTunes or from Xcode in the Organizer window. Using TestFlight (more on that later) can also simplify getting device ID's from users. TestFlight will email the tester's device ID once he/she registers.
  2. Create a Distribution Ad Hoc Provisioning profile in iOS Portal and select all the devices for the beta users.
  3. Download the new provisioning profile and install it in Xcode by double-clicking it or dragging it into the Xcode icon. Keep this file handy because we will need upload it to the web along with the ipa file and allow users to download it. Select this provisioning profile for code signing for the Release version of your project and targets.

  4. Select "iOS Device" from your build schemes. the Archive button is disabled when the Simulator is selected.

  5. Add an Entitlements file. In Xcode 4.2 you cannot add an Entitlements file by going to File -> New -> New File --like previous versions. You must select your project in the top left corner then click on your main target. Then scroll all the way to the bottom and check the box for Enable Entitlements.
  6. If you have more than one target in your project then you must select "Yes" for the Skip Install setting under Deployment for all targets other than your main project target. You will end up with multiple targets if you are linking to other projects or have unit tests.
  7. From the main menu select Product --> Archive.
  8. From the Organizer - Archives window press the button Share.
  9. Select iOS App Store Package (.ipa) and the correct signing identity for your build. Then press Next.
  10. Type into the Save As field on top the name you want to give the files. Check the box for Save for Enterprise Distribution on the bottom. Enter the URL where the file will be hosted without the file name. All you need is the URL up to the directory path. Add a title for your app then press Save.
  11. You should now have generated two files, a .ipa file and a .plist file. All you have to do now is upload these two files to your website along with your provisioning file (from step 3) then link to them on a webpage like shown below. The ipa and plist file must be in the same directory and must have the same name except for the extension. Your users should install the provisioning file first then install the app.

    Another option is instead of simply hosting these files on your website, you can utilize a service like TestFlight for better tracking and user experience. Using TestFlight is easy and you can use the TestFlight SDK to allow the users to send feedback and track how long the testers used the app and so on. For more on TestFlight visit:

    <title>Install iOS App</title>

    <a href="My_Provisioning_Profile_Ad_Hoc.mobileprovision">Install Team Provisioning File</a>

    <a href="itms-services://?action=download-manifest&url=http://yourwebsite/betafolder/myFavAppName.plist">Install Application</a>


You should provide your testers with links to the provisioning profile (.mobileprovision) and IPA file as shown above. Instruct them to install the provisioning profile first. However you should look into TestFlight for better management and tracking. There, that should get you started with installing all your cool apps on your friends' devices before you hit the AppStore.

posted by T Alrahem
0 Comments    Links to this post

Saturday, October 1, 2011

Use Doubly Linked Not Singly Linked Lists

If you're going to write a general use library and use a linked list, please make it doubly linked. I was recently working with the Box2d library which I have to say is a great physics engine. The engine maintains a linked list of what it calls Fixtures attached to each body. While I was trying to use this list I was shocked to find that it was a singly linked list. In other words the list only had a "next" pointer, no previous pointer.

Unless you have a good reason like tail-sharing I really don't see why someone would do that especially in a general opensource library that would be used in a broad range of applications. First off, before we go into the pros and cons of both designs let's briefly talk about linked lists. A linked list is a data structure used to store a group of data objects by connecting objects with a "link". The link is basically a pointer from one object to the next one, previous one, or both. If there's only one link it's called a singly linked list. If there's both a previous and a next link, it's called a doubly linked list. The best part about a linked list is that it's very cheap to add and remove objects. All we need to do is add a new link or remove a link and assign a pointer to a different object. The worst part about a linked list is random access. If we need to access an object that happens to be in the middle of the list, there's no way to reach that object but to traverse through all the objects before it or after it.

When designing software, we're supposed make libraries as flexible and general as reasonably possible. We already know that access is the main weakness of linked lists. The least we can do to make accessing objects a little easier is to make the list a doubly linked one. In the case of linked lists it's easy to see why someone might need to go backwards in a list. But even if it weren't so obvious, if adding something doesn't cost much and it satisfies a common use it should be done in a general purpose type of library.

Looking at the pros and cons of a singly and doubly linked list, it also makes more sense to make them doubly linked. The only pro of using singly linked lists is that it saves memory but all we're saving is a pointer which is about 32 or 64 bits per object. The con is being limited to traverse a list in only one direction. Singly linked lists also make it more challenging to delete objects. The pro of having a doubly linked list is that from any object in the list we can move in either direction. Also it's a lot easier to delete an object in a doubly linked list. The con of doubly linked lists is that we use a little more memory for the second pointer. However the additional memory (32 or 64 bits per object) used is insignificant. In terms of asymptotic notation, we're still using O(n) memory which means our memory usage is linear with respect to the number of objects.

The good news is that I was able to modify the list and make it doubly linked. Take home message: bi-linking = bi-winning.

Labels: , , , , ,

posted by T Alrahem
0 Comments    Links to this post

Monday, September 19, 2011

throw vs throw ex: C# .NET Exceptions

There are a couple options to raise an exception again after it has been caught. One option is to raise the exception again by using the "throw exception" keyword like below:

   ...//code that encounters an exception
catch (Exception ex)
   ...//exception handling code
   throw ex; //raise the exception again

The disadvantage in this way is that the original context of the exception is lost. There is no longer a meaningful call stack attached to the exception because it will contain the latest context from the newly added throw. If you plan to throw the exception in this matter you should wrap the original exception into another new more high level (application) exception. The new exception would add more high level info about the original exception.

The second option is to use the throw keyword alone with out passing the actual exception variable. This tells the .NET framework to throw the original exception without updating its context like below:

   ...//code that encounters an exception
catch (Exception e)
   ...//exception handling code
   throw; //notice the exception e is omitted

This way should be used when the exception is trivial enough and the code is too small to require wrapping into another exception. Again the advantage here is that you maintain the original call stack so that any user of this code can track the cause of the exception.

It's worth noting that Java is different in this aspect and using "throw ex" in Java will retain the original stack trace.

Labels: , , , , , , ,

posted by T Alrahem
0 Comments    Links to this post

Sunday, January 2, 2011

Nearby Windows Phone 7 Reviews and Maps App

Nearby is a new Windows Phone 7 (WP7) app. The app can be downloaded here from the Windows Phone 7 app store.

Download Now for Windows Phone 7

Nearby nearby screenshot

Nearby shows the user nearby places automatically upon opening. The user can scroll through the list of nearby places and find more information on a location he is interested in. Information for a location includes phone, address, website, rating, and distance. You can see the directories where the location is found such as Yelp, Yahoo and CitySearch. Using Nearby, you can view the location's page on Yelp and other sources within the app. Browsing to the Yelp or Yahoo page for the business allows you to see reviews and more info.

Nearby directions screenshot

With Nearby, you can find step-by-step directions to the location you are interested in. You can also navigate through the itinerary steps and see the steps on the map.

Nearby details screenshot

Nearby allows you to bookmark your favorite locations so that you can find them easily. You may also share a location with a friend via SMS text or email. Calling a place is as easy as touching the phone icon or phone number after selecting a business.

Nearby favorites screenshot

List of favorite places and businesses for easy access.

Find out more about Nearby at

Labels: , , , , , , , , , , ,

posted by T Alrahem
0 Comments    Links to this post

Friday, October 15, 2010

Just Draw - Drawing App for iPad

Available on the App Store

Just Draw is the latest mobile app I launched on the Apple App Store. Currently it's only compatible with the iPad. Future versions might extend support to iPhone and iTouch depending on demand.

Just Draw is a nice simple app that allows iPad users to use their fingers to draw then save or share their drawings via Facebook, Twitter, or email. The app is useful if you want to jot down ideas while thinking then come back to them later. It's also good for quickly mocking up designs of anything. If you ever wanted to quickly write or draw something on a picture and then send it to a friend, Just Draw is the app you've been looking for.

Perhaps one of the unique features of Just Draw is the "replay" feature. You can have the app trace every move you make by hitting the replay button. So you can take your time and draw something creative then hit replay and watch the app animate your drawing by repeating everything you did.

The cool thing about this app is that it is built on top of OpenGL which gives it the smooth performance. Just Draw supports multi-touch drawing. So you and your friends can draw at the same time! The app makes use of a few API's such as Facebook and TwitPhoto.

Since this is the first release, there are many nice features that can be added to Just Draw. I am open to any ideas or suggestions on what users want to add to the app. Have fun with the app and I look forward to hearing your feedback and comments.

Here are some screenshots from Just Draw:

Labels: , , , , , , , , , ,

posted by T Alrahem
0 Comments    Links to this post

Sunday, January 10, 2010

iPhone Project Management with TA Project

available on the iphone app store

I just finished developing an iPhone App called TA Project that's on the Apple App Store now. The mobile application allows a user to create tasks or to do lists for a project. It can be simply used for task management. But it can also be used for more complex budget and schedule tracking. TA Project can also compute project management metrics such as the Schedule Performance Index (SPI) and the Cost Performance Index (CPI).

You can also graph your estimate and actual cost to visually compare your performance to what you have estimated. The graph is useful to foresee whether your actual cost is going to exceed your estimate or not. Another feature of TA Project is allowing the user to post the status of a project on Twitter. One of the tabs for each project is a Twitter tab that allows reading previous posts and posting new Tweets.

I was the only developer working on the project. I used CorePlot for graphing. Overall the most complex pieces of the project were handling task dependencies, graph formatting, and making the application robust. Making the application robust includes memory management and handling network events. Integrating with Twitter was fairly simple. The app uses CoreData for data storage which uses SQLite underneath.

Xcode and CoreData make using SQLite very convenient. After getting the data model down in Xcode, most of the data pluming is done for you under the hood. This project presented some data challenges because almost every single action the user makes has to be retained.

Below are some screenshots from the app.
my projects screenshot
Home page screen. This screen shows the list of projects.

tasks screenshot
The Tasks tab. After selecting a project you come to this tab which shows the tasks for the selected project.

performance screenshot
The Performance tab. The Performance tab shows the CPI and SPI metrics in addition to the estimate and actual cost graphs.

landscape graph

Flipping the phone shows the graph in landscape mode.

twitter tab screenshot
The Twitter tab. This tab allows the user to read posts and update the status of the project on Twitter.

posted by T Alrahem
0 Comments    Links to this post

Monday, August 10, 2009

SQL Server SP Parameter Default Value

SQL Server does not allow creating a stored procedure with parameter default values that are not constant. This can be a problem if you want to give a parameter a default value that is predictable but not constant such as giving a datetime parameter a default value of the current time.

There are two ways to resolve this. One is solution but it's not very flexible. The other is a workaround but can be used in more situations. First the solution. If the parameter is used as a minimum or maximum value check, you can totally ignore the value if it's null.

Here is an example of the first solution. Let's say we want to write a stored procedure to get all records from an Activity table that occured from one point in time to another. In this case we want to include all records if the boundry variable is not specified. In the example below we simply do this by checking for NULL and using the logical OR.


   SELECT * FROM Activity
   WHERE (@From is null or LogTime >= @From)
   and (@To is null or LogTime <= @To)

Another way to do this that is more flexible is to check if the parameter is null and in that case set it equal to whatever value you wish.

For example, in the code below I check if the @To variable is null and if it is I set it equal to the current time.


   IF @To is null
      SET @To = GetDate()

   SELECT * FROM Activity
   WHERE (@From is null or LogTime >= @From)
   and LogTime <= @To

Labels: , , , , , ,

posted by T Alrahem
0 Comments    Links to this post

Sunday, March 29, 2009

C# .NET Default Access Modifiers

It's good to refresh what the default access modifiers are in C#. Default access modifiers could explain why you can't see something you declared when expect to see it and vice versa.

First let's quickly review all the access modifiers in C#.
private: Can be accessed by members of the same class only.
protected: Can be accessed by members of the same class plus members of derived classes only.
internal: Can be accessed by all that is in the same assembly regardless of what class they are in. But can only be accessed from the same assembly.
public: Can be accessed by everything.

The general rule is that the default access modifier is as secured as possible for the declaration context. This does not mean that everything is private by default because private does not make sense for everything. So here is the breakdown.

Data types: class, struct, enum
For data types such as classes the most strict reasonable access modifier is internal. And that is exactly the default modifier. So when declaring a new class it is internal by default so that it can be accessed by other classes in the same assembly. It does not make sense for a class to be private by default because it would inaccessible.

Members: variables, methods
For member variables and methods which are inside a certain data type from the list above, the most restrictive reasonable modifier is private and that is it. Any time a member is declared with no access modifier, it is private by default.

Labels: , ,

posted by T Alrahem
0 Comments    Links to this post

Monday, March 16, 2009

Inline ASP.NET Tags Differences <%#, <%, <%=, <%$, <%--, <%@

It gets confusing at times when figuring out which ASP.NET tag is best to use. Moreover, it is good to know the settle difference between a couple of the similar tags. One might think that for example the "<%#" tag and "<%=" are the same for certain cases and can be used interchangeably. Actually they are different and in most cases only one of them would work unless some code change is done. So here is a summary of the tag attributes and the differences amongst them:

<% ... %>

This tag is used to insert code into an ASP.NET page usually with a .aspx extension. One of the most common use of this tag is conditional statements where you can choose to display certain content only when a condition is met.

<% if(isLoggedIn){ %>
Hello user
<% } else { %>
Please login
<% } %>

For more info:

<%# ... %>

This tag is used with data binding. It can be used with DataBinder.Eval() or DataBinder.Bind() or just with any protected or public member as shown in the example. The trick about this tag is that it must be used inside a server-side element (with runat="server"). Also the DataBind() method of that element must be called at some point. However, certain ASP.NET elements automatically call their DataBind() method in their PreRender() methods. So there is no need to is explicitly call their DataBind() methods. Such elements are GridView, DetailsView, and FormView.

<div id="div1" runat="server">
Hello <%# userName %>

In the code behind:

protected void Page_Load(object sender, EventArgs e)

For more info:

<%= ... %>

This tag is similar to the above tag in the sense that it is used to evaluate the value of a protected or public member variable. The tag evaluates the ToString() method of the variable used and displays it. The nice thing about this tag is that it does not need to be inside a server-side element and its parent element does not even need to have a name.

Hello <%= userName %>

For more info:

<%$ ... %>

This tag is used to evaluate expressions in a configuration file. It is usually used for connection strings but it can be used with AppSettings and other configurations.

<asp:SqlDataSource ID="SqlDataSource1" Runat="server"
SelectCommand="SELECT * FROM [Employees]"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString1 %>">

For more info:

<%@ ... %>

This is usually used at top of a page as a directive to register controls or import a library.

<%@ Register TagPrefix="uc" Namespace="MyCustomUserControl" %>

For more info:

<%-- ... --%>

This tag allows you to add server-side comments which would never show in the HTML output. This is different from using an HTML comment (<! -->) because HTML comments do get rendered in the outputted HTML.

<%-- this is a comment --%>

For more info:

That should be a good summary but there is obviously more to some of tags.

Labels: , , ,

posted by T Alrahem
0 Comments    Links to this post