Sunday, November 25, 2012

vim problems with ^M (caret M), due to file format incompatibility

The problem with ^M or caret M that you see in files during editing or modifying is that incompatibility with vim's default file format.

Usually, if I have a file edited or created in Mac OS X, and when its edited via Linux, I got ^M plus the lines are displayed as one line which is freaking hard to edit. To fix this, just do edit the file, then reload the file in vim,

:e ++ff=mac


:e ++ff=unix

if it was created in Unix. This will render with a great view editor of your file from what you expected it should be.

According to vim's Wiki,
unixLF only (each line ends with an LF character).
dosCRLF (each line ends with two characters, CR then LF).
macCR only (each line ends with a CR character).
CR is carriage return (return cursor to left margin), which is Ctrl-M or ^M or hex 0D

You can read for more info for file format in this page

Monday, November 12, 2012

Understanding Threads and Multithreading

In this blog, I just wanna accumulate all things that I need to note regarding threads.

Threads are just a light-weight process. It's actually a process but it runs under a process, literally a subsets of a process, where in this process, threads can share resources like memory. Threads in this subject is distinct from multi-core systems, which deals with instructions that are sent in the hardware resources like instruction set pass from USB to processor, stuff like that, in which multi-core can empower an OS to implement multi-threading. So multi-core is more of dealing with central processing units to execute program instructions.

Multithreading aims to increase utilization of a single ore by using thread-level as well as instruction-level parallelism. As the two (multithreading in cores and threads in OS) techniques are complementary, they are sometimes combined in systems with multiple multithreading CPUs and in CPUs with multiple multithreading cores.

courtesy of Wikipedia:


Some advantages include:
  • If a thread gets a lot of cache misses, the other thread(s) can continue, taking advantage of the unused computing resources, which thus can lead to faster overall execution, as these resources would have been idle if only a single thread was executed.
  • If a thread cannot use all the computing resources of the CPU (because instructions depend on each other's result), running another thread can avoid leaving these idle.
  • If several threads work on the same set of data, they can actually share their cache, leading to better cache usage or synchronization on its values.


Some criticisms of multithreading include:
  • Multiple threads can interfere with each other when sharing hardware resources such as caches or translation lookaside buffers (TLBs).
  • Execution times of a single thread are not improved but can be degraded, even when only one thread is executing. This is due to slower frequencies and/or additional pipeline stages that are necessary to accommodate thread-switching hardware.
  • Hardware support for multithreading is more visible to software, thus requiring more changes to both application programs and operating systems than multiprocessing.

Pleas


Pre-emptive multitasking - temporarily interrupting a task being carried by a computer system without requiring cooperation and with the intention of resuming the task at a later time.

Context switch - This is what is happening when doing a pre-emptive multitasking. It is normally carried out by a privileged task or a part of the system known as a preemptive scheduler.

Pre-emptive multitasking is carried out by privileged task.

Race conditions - where something like data are bumping. Like for example, two variables might get into racing who comes first to get the change the state of such value where these two variables are in different threads/task.

There are two kinds of race conditons:
critical race occurs when the order in which internal variables are changed determines the eventual state that the state machine will end up in.

non-critical race occurs when the order in which internal variables are changed does not alter the eventual state. In other words, a non-critical race occurs when moving to a desired state means that more than one internal state variable must be changed at once, but no matter in what order these internal state variables change, the resultant state will be the same.

Thursday, August 30, 2012

Programming Advice

I wanna take note on this blog "The Best Programming Advice I Ever Got" with Andrei Alexandrescu as I found this notably important as a programmer or developer.

How about yours? What do you think a good programmer should have?

Programming Opinions - Great Blog to Read

I think this blog is cool to read

20 controversial programming opinions

Wednesday, August 29, 2012

Lossy Image Optimization

I have enjoyed this youtube video regarding lossy image optimization from Velocity.

Hope you find this video helpful.

O'Reilly Webcast: The Best of Velocity - Take it all off! Lossy Image Optimization

Wednesday, August 8, 2012

Coding standard in C

I got this file as such a noteworthy to read.

JPL Institutional Coding Standard for the C Programming Language

Hope you like it :-)

Monday, August 6, 2012

difference between Orthogonal and Isometric

I wanna note this myself so I can't forget this stuff.

Orthogonal vs Isometric Via
or this link StackExchange Orthogonal vs Isometric

Orthogonal vs Isometric via Yahoo Asnwers

With regards to foreshortened, according to Wikipedia on Perspective, it means as,

Foreshortened: the size of an object's dimensions along the line of sight are relatively shorter than dimensions across the line of sight

Sunday, August 5, 2012

10 Reasons You're Not the Boss

I came across reading this article from Yahoo and wanted to save this as a note for myself. This is such a good article and notes to follow, IMHO.

Wednesday, August 1, 2012

On Multiple programming languages ?

Well, I just wanted to note from this blog Keeping multiple programming languages straight. I found this very helpful to read, and thus he has also his notes with what he had done and contributed so far, in Open Source world.

Keep on reading on his blog. It has lot to learn from what he have done so far.

Sunday, July 29, 2012

MySQL: list all fields into a CSV result or set custom delimiter

So the topic here is how would you come up with listing all the fields of a table where it will output into a comma separated values?

Say for example, you have a database named BILLING with a sample table name and fields below.

|                 |
|    CUSTOMERS    |
| name            |
| address         |
| username        |
| password        |

and wanted to have a result of name, address, username, and password. You have to query the database supplied by default in MySQL using the DB name INFORMATION_SCHEMA and then filter the result with its table name and select only the COLUMNS field.

So the query should look something like this,

// set a value for the variable @table
mysql > set @table='customers';


The result would look like:


Hope this helps.

Tuesday, July 24, 2012

Zend Framework: How to include directories with dash or hyphen

So before I can forgot it in Zend, I will post this as a notes and reference.
When you want to include a directory with dash or hyphen (-) symbol, like for example, a helper. You can do it by using the code below.

    protected function _initActionHelpers()
            APPLICATION_PATH . '/../library/dash-classes/Action/Helper/',

Where you have your helper stored in ../library/dash-classes/Action/Helper/Example.php

Where your Example.php might look something as,

class DashClasses_Action_Helper_Example extends Zend_Controller_Action_Helper_Abstract
    function direct()
        $session = new Zend_Session_Namespace('exampleSession');
        return $session;

Converting mp4 to AVI using ffmpeg

I got this commands until it works on mine. Currently, I am running on Mac OS X Lion so, in particular, I would say this works in my part using Mac OS X Lion.

$> ffmpeg -i batman.begins.mp4 -vcodec libxvid -ab 192k -sameq -acodec libmp3lame -ar 48000 -ac 2 batman-begins.avi

Specifically, my choices are are need to be converted to AVI so I can put it into my USB and play via our HD TV which seemed to consistently support using this encoding or conversion.

-vcodec which I use libxvid codec for my video encoding
-ab        192k which, I believe, using stereo would need this bit rate.
-sameq   So I got the same quantization values
-acodec  so I use libmp3lame
-ar          is set to 48000 audio sampling frequency
-ac          is set to 2 to have a dual stereo type of audio

Hope this helps.

Monday, July 23, 2012

Richest man in the valley

You know, I got this story from my e-mail a very very long time ago and still, this is the most shortest and simplest story that I like most in my entire life.

Anyway, here it goes. [courtesy of]

Enjoy reading!!!

The Richest Man In The Valley

A rich landowner named Carl often rode around his vast estate so
he could congratulate himself on his great wealth.  One day
while riding around his estate on his favorite horse, he saw
Hans, an old tenant farmer.  Hans was sitting under a tree when
Carl rode by.  Hans said, "I was just thanking God for my food."

Carl protested, "If that is all I had to eat, I wouldn't feel
like giving thanks."

Hans replied, "God has given me everything I need, and I am
thankful for it."

The old farmer added, "It is strange you should come by today
because I had a dream last night.  In my dream a voice told me,
'The richest man in the valley will die tonight.'  I don't know
what it means, but I thought I ought to tell you."

Carl snorted, "Dreams are nonsense," and galloped away, but he
could not forget Hans' words: "The richest man in the valley
will die tonight."  He was obviously the richest man in the
valley, so he invited his doctor to his house that evening.
Carl told the doctor what Hans had said.  After a thorough
examination, the doctor told the wealthy landowner,

"Carl, you are as strong and healthy as a horse.  There is no
way you are going to die tonight."

Nevertheless, for assurance, the doctor stayed with Carl, and
they played cards through the night.  The doctor left the next
morning and Carl apologized for becoming so upset over the old
man's dream.  At about nine o'clock, a messenger arrived at
Carl's door.

"What is it?" Carl demanded.  The messenger explained,

"It's about old Hans.  He died last night in his sleep."

Hope you just like what I have shared.

Tuesday, July 10, 2012

Partial Derivative

For my notes, this is a good explanation of partial derivative is.

Saturday, June 9, 2012

what is love?

Love is patient, love is kind, Love does not insist on its own way. Love bears all things, believes all things, Hopes all things, Endures all things. Love never fails

- 1 Corinthians 13:4-8

Saturday, June 2, 2012

Locate Downloaded Apps in Apple's App Store

1. Open Terminal
2. Enter defaults write ShowDebugMenu -bool true
3. Open AppStore Application
4. Choose the menu item Debug Menu -> Show Download Folder

Then you can check here where's the downloaded files are located.

Wednesday, May 30, 2012

Dijkstra's Algorithm

I found this great tutorial in youtube under Creative Commons Attribution 2.5 Canada License.

This one too is helpful from Khan

and this one is a long discussion but it's helpful.

There are good links or sites also that has a sample code and explanation. Follow the links below. - has a Java Code's_algorithm_(Java)#chunk def:relax the edge (u,v) - has a java code too with explanation (cool!)

Hope you enjoy learning Dijkstra's Algorithm.

Thursday, May 24, 2012

Explaining B-Trees: animated video

This video is not owned by me, I just screen casted it and put into video so you can do track by time compared to their flash base which is annoying when you wanted to back track.

This video is taken from

Using your calculator to validate logarithms with exponents and get result of logarithms

I just stumbled this earlier when I was playing with my calculator and I forgot how to use it, so I remember that logarithms is just a way of a reverse formula of exponents.

So I came up with this solution,

log2(8) = 3

in calculator,
press 8 + press x radical symbol(y) + press 3 = 2

log2(3) = 1.58496250072116

in calculator
press 3 + press x radical symbol(y) + 1.58496250072116 = 2

log4(16) = 4294967296
in calculator
press 4294967296 + press x radical symbol(y) + 16 = 4

So the formula is,

logbase(logarithm number) = result


result as the index then radical symbol(logarithm number as the radicand) = base


baseresult = logarithm number

Now to get the result of a logarithm in calculator, you can use natural logarithm. To calculate it,


ln(16)/ln(2) = 4

which is equivalent to,

log2(16) = 4

another ex.

ln(65536)/ln(4) = 7.99 = 8

which is equivalent to
log4(65536) = 8

Sunday, May 6, 2012

Using "use strict" in JavaScript

Using Firefox, as of this writing, version 12.0. Here's a tiny part of using "use strict" syntax in JavaScript.

without "use strict",

var x = 17;
var evalX = eval("var x = 42; x");
alert(x === 17); // results to false
alert(x === 42); // results to true
alert(evalX === 42); // results to true

with "use strict",

var x = 17;
var evalX = eval("'use strict'; var x = 42; x");
alert(x === 17); // results to true
alert(x === 42); // results to false

alert(evalX === 42); // results to true

To know more about "use strict", read more on Mozilla's page at or another interesting blog to read at

A tabular view shows what browsers does support strict mode in JavaScript. Taken from, as of this writing, I got this tabular view below,

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