Saturday, May 5, 2012

Understanding Anchor point in iOS

Just to take notes for this regarding anchor point in iOS.

This is taken from

Specifying a Layer’s Geometry

While layers and the layer-tree are analogous to views and view hierarchies in many ways, a layer's geometry is specified in a different, and often simpler, manner. All of a layer’s geometric properties, including the layer’s transform matrices, can be implicitly and explicitly animated.
Figure 1 shows the properties used to specify a layer's geometry in context.

Figure 1  CALayer geometry properties
CALayer geometry properties

The position property is a CGPoint that specifies the position of the layer relative to its superlayer, and is expressed in the superlayer's coordinate system.
The bounds property is a CGRect that provides the size of the layer (bounds.size) and the origin (bounds.origin). The bounds origin is used as the origin of the graphics context when you override a layer's drawing methods.
Layers have an implicit frame that is a function of the positionboundsanchorPoint, and transform properties. Setting a new frame rectangle changes the layer'sposition and bounds properties appropriately, but the frame itself is not stored. When a new frame rectangle is specified the bounds origin is undisturbed, while the bounds size is set to the size of the frame. The layer's position is set to the proper location relative to the anchor point. When you get the frame property value, it is calculated relative to the positionbounds, and anchorPoint properties.
The anchorPoint property is a CGPoint that specifies a location within the bounds of a layer that corresponds with the position coordinate. The anchor point specifies how the bounds are positioned relative to the position property, as well as serving as the point that transforms are applied around. It is expressed in the unit coordinate system-the (0.0,0.0) value is located closest to the layer’s origin and (1.0,1.0) is located in the opposite corner. Applying a transform to the layer’s parent (if one exists) can alter the anchorPoint orientation, depending on the parent’s coordinate system on the y-axis.
When you specify the frame of a layer, position is set relative to the anchor point. When you specify the position of the layer, bounds is set relative to the anchor point.

Figure 2 shows three example values for an anchor point.

Figure 2  Three anchorPoint values
Three anchorPoint values

The default value for anchorPoint is (0.5,0.5) which corresponds to the center of the layer's bounds (shown as point A in Figure 2.) Point B shows the position of an anchor point set to (0.0,0.5). Finally, point C (1.0,0.0) causes specifies that the layer’s position is set to the bottom right corner of the frame. This diagram is specific to layers in Mac OS X. In iOS, layers use a different default coordinate system, where (0.0,0.0) is in the top-left corner and (1.0,1.0) is in the lower-right.
The relationship of the frameboundsposition, and anchorPoint properties is shown in Figure 3.

Figure 3  Layer Origin of (0.5,0.5)
Layer Origin of (0.5,0.5)

In this example the anchorPoint is set to the default value of (0.5,0.5), which corresponds to the center of the layer. The position of the layer is set to (100.0,100.0), and the bounds is set to the rectangle (0.0, 0.0, 120.0, 80.0). This causes the frame property to be calculated as (40.0, 60.0, 120.0, 80.0).
If you created a new layer, and set only the layer’s frame property to (40.0, 60.0, 120.0, 80.0), the position property would be automatically set to (100.0,100.0), and the bounds property to (0.0, 0.0, 120.0, 80.0).
Figure 4 shows a layer with the same frame rectangle as the layer in Figure 3. However, in this case the anchorPoint of the layer is set to (0.0,0.0), which corresponds with the bottom left corner of the layer.

Figure 4  Layer Origin of (0.0,0.0)
Layer Origin of (0.0,0.0)

With the frame set to (40.0, 60.0, 120.0, 80.0), the value of the bounds property is the same, but the value of the position property has changed.
Another aspect of layer geometry that differs from Cocoa views is that you can specify a radius that is used to round the corners of the layer. The cornerRadius property specifies a radius the layer uses when drawing content, clipping sublayers, and drawing the border and shadow.
The zPosition property specifies the z-axis component of the layer's position. The zPosition is intended to be used to set the visual position of the layer relative to its sibling layers. It should not be used to specify the order of layer siblings, instead reorder the layer in the sublayer array.

For complete reference on the Core animation programming, see link

Comet - long-polling using Ajax

I just wanted to save this video for any references wanted to understand what Comet is.

So what exactly Comet is? Comet is still using AJAX but its just a technique done in the server. It uses timestamp for comparison of updates, then AJAX request will have just to wait until the server will response, so it's the sever will have to push data to the browser. This is a long-polling method and can save traffic than running an AJAX request from time-to-time.

checkout only one file using git

First clone the repo with the following command below,
git clone -n git://path/to/the_repo.git --depth 1

The -n option suppresses the default checkout of all files, and the --depth 1 option, which means it only gets the most recent revision of each file
Then check out just the file you want like so:
Then you can checkout the file that you wanted to get or save to your machine.

$> cd the_repo
$> git checkout HEAD name_of_file

Monday, April 30, 2012

Building packages in Linux from source

Always remember that when you build packages in Linux, always do consider these packages as its requirement by the compiler to build the package from source.
  • git-core 
  • build-essential
  • libboost-dev 
  • libboost-program-options-dev
  • libboost-thread-dev 
  • libboost-filesystem-dev
  • scons
  • gcc-c++
  • glibc-devel