Red Day, Green Day

I have started tracking stocks on Yahoo. Not that I am investing, but I find that looking a certain set of stocks helps explain the news. Specifically, I have a list that has two main types of stocks: Tech and Oil. Here is the list:

VMW 10:29AM ET 46.76 Up 0.38 Up 0.82% 251,554 17.93B Chart, Messages, Key Stats, More
YHOO 10:34AM ET 28.33 Up 0.24 Up 0.85% 4,203,632 37.88B Chart, Messages, Key Stats, More
AAPL 10:34AM ET 143.57 Up 3.32 Up 2.37% 8,182,315 126.18B Chart, Messages, Key Stats, More
JAVA 10:34AM ET 16.06 Up 0.15 Up 0.94% 1,501,868 14.46B Chart, Messages, Key Stats, More
DELL 10:34AM ET 19.84 Up 0.37 Up 1.91% 3,191,453 43.34B Chart, Messages, Key Stats, More
EMC 10:29AM ET 14.40 Up 0.07 Up 0.52% 4,446,405 30.26B Chart, Messages, Key Stats, More
IBM 10:29AM ET 114.99 Down 0.53 Down 0.46% 1,447,515 159.18B Chart, Messages, Key Stats, More
ORCL 10:34AM ET 19.79 Up 0.36 Up 1.85% 11,308,559 101.65B Chart, Messages, Key Stats, More
MSFT 10:34AM ET 28.30 Up 0.25 Up 0.89% 10,469,087 263.39B Chart, Messages, Key Stats, More
GOOG 10:33AM ET 449.14 Up 5.06 Up 1.14% 1,378,627 140.75B Chart, Messages, Key Stats, More
GGP 10:28AM ET 38.58 Down 0.13 Down 0.34% 727,075 9.41B Chart, Messages, Key Stats, More
RHT 10:29AM ET 18.31 Up 0.78 Up 4.45% 1,322,182 3.56B Chart, Messages, Key Stats, More
NOVL 10:34AM ET 6.24 Up 0.07 Up 1.13% 304,018 2.20B Chart, Messages, Key Stats, More
BP 10:29AM ET 60.73 Up 0.07 Up 0.12% 1,307,600 191.53B Chart, Messages, Key Stats, More
HAL 10:29AM ET 39.29 Up 0.19 Up 0.49% 2,895,156 34.58B Chart, Messages, Key Stats, More
SLB 10:29AM ET 86.40 Up 1.02 Up 1.19% 1,678,732 103.48B Chart, Messages, Key Stats, More
KBR 10:28AM ET 28.97 Up 0.59 Up 2.08% 140,700 4.92B Chart, Messages, Key Stats, More
XOM 10:29AM ET 86.95 Up 0.75 Up 0.87% 3,768,280 465.18B Chart, Messages, Key Stats, More
MT 10:29AM ET 79.93 Up 1.08 Up 1.37% 1,044,700 113.63B Chart, Messages, Key Stats, More
COP 10:29AM ET 76.21 Up 0.48 Up 0.63% 2,057,477 119.00B Chart, Messages, Key Stats, More
 

A couple of steel stocks are mixed in at the end, and KBR is Kellog Brown and Root, the company that Haliburton spun off and that fed me while I was deployed to Haiti all those years ago. GGP is General Growth Properties, and represents both real estate and the retail market. What I look at first and foremost is the overall color. I don’t care about any particular stock so much as if the tech sector is all red but the oil sector is green, or if the whole thing is one or the other.

I realize that all of this summary info is available on the headlines of the Wall Street Journal or on the finance pages, but there is something about being able to draw your own conclusion from the presentation of the data that makes it easier to comprehend quickly.

Another piece of information that leaps out from this display is if a given stock is behaving differently from its market. There is a difference between Oracle going up 5% on a tech green day and a tech red day.

Tufte would be proud .

Things you can send to Soldiers in Iraq

www.anysoldier.com

Based on What Soldiers have requested, here are things you can send to Iraq. Different units have different degrees of support. Personally, I try to find line Infantrymen like the folks in my old unit 1st Battalion 27th Infantry, The Wolfhounds. Not that everyone else doesn’t need support, too. But these guys are the ones out on the streets patrolling.

  • batteries
  • beef jerky
  • Brownies
  • bumble bee chicken,
  • Camping Food
  • Canned Tuna Fish
  • cereal (whole grain),
  • chapstick,
  • chips and salsa (bean/cheese dip),
  • DVDs
  • energy/Protein bars
  • face wipes
  • Foot Powder
  • Good Coffee, preground.
  • granola bars
  • Letter Writing Material
  • lifting supplements
  • magazines (Maxim, MensHealth, FHM, STUFF, Flex, MuscleFitness, Time, the Economist, Kiplingers, Gun and Auto Magazines)
  • Minute Rice
  • Multi Vitamins
  • Music CDs
  • Olive Drag Green Wool Socks (Army Issue)
  • Oreos
  • peanut butter
  • Playing Cards
  • popcorn (regular, cheese, and caramel flavored)
  • Poptarts
  • Powdered Gatorade
  • Pringles
  • protein powder
  • Razors
  • Sardines
  • shampoo
  • Shaving crème
  • Soap
  • Socks, White
  • Sunscreen
  • Toothpaste
  • trail mix/nuts
  • Video Games (XBOX 360 …)
  • Vienna Sausages
  • White socks, with no patterns

A couple of gdb tricks

If you run a command with arguments in gdb like this

>run -a -b -c

The next time you go to run, gdb will assume you want the same arguments.   You can work around this by running:

>run —

Which tells the standard options to not process anything after the double dash as an option.

Also, If you have a stack track but not a complete core dump, you can find the line that corresponds with an address (say 0x80808881) in the trace  by using

info symbol 0x80808881

More musings

Synagogue would be a hell of a lot more fun if more people heckled the Rabbi.

Ayn Rand seems to appeal to men in their mid twenties.

Martin Fowler is responsible for popularizing some of the most important ideas in software design.

There is an amazing power in large combinations of simple things. The universe is defined by a very small number of rules repeated a lot of times.

Even if we accept that there should be a categorical imperative, how can we determine which aspect of our action should be the generalizable part and which is the part that is adapted to our present situation?

Considering how much information is stored on me in computers, I still have to fill out my address an excessive number of times. Shouldn’t we be at the point that my address is be pre-filled in a web form?

High fiber cereal does not make a good dinner.

Wrestling and rock climbing a very complimentary sports. Both require a sense of balance in your body. Rock climbing develops hand grip strength that is a benefit to wrestling. Both require and develop a strong core.

Binary search is the primary tool of debugging anything.

The build-execute-change cycle is the key to productivity in software. Building high performance software usually kills you in the build step.

We wasted too much time on Drill and Ceremony at West Point. If Napoleon Bonaparte ever invades, the United States Corps of Cadets will be ready.

No drug can be more addictive than the sound of your own child’s laughter.

How to extract from tgz, rpm, and deb files

The most common way to move a bundle of files around in Linux is a combination of tar (tape archive), which appends all of the files together into a single large file,  and gzip, a compression utility.  These are often referred to as tarball. They will have an extension like tar.gz or tgz.  Sometimes bzip2 is used as the comprseeion utility, and they file will end with tar.bz2.

To see the list of files in the  tarball for sage, run:

tar -ztf  sage-2.10.2-linux-ubuntu64-opteron-x86_64-Linux.tar.gz

To extract the files, create a target directory and change to it, thenextract the file from it’s original location

mkdir /tmp/sage

cd /tmp/sage

tar -zxf  ~/Desktop/sage-2.10.2-linux-ubuntu64-opteron-x86_64-Linux.tar.gz

All of the files will be put into the current directory.  There is no rule that says that all the files in a tarball are under on subdirectory, so it really behooves you to do this in a empty directory.  That way you know all of the files you see post extraction are files from the tarball.

Debian uses a package management system called dpkg based on this technology.  The packages will end with .deb, but you can see what Linux thinks the  file type is by using the file command.  Here it is run on automake_1.10+nogfdl-1_all.deb:

 adyoung@adyoung-devd$ file ~/Desktop/automake_1.10+nogfdl-1_all.deb
/home/adyoung/Desktop/automake_1.10+nogfdl-1_all.deb: Debian binary package (format 2.0)

To See the list of included files, run:

dpkg –contents automake_1.10+nogfdl-1_all.deb

And to extract use the –extract command line parameter.  Note that you have to supply the target directory as well.

dpkg –extract automake_1.10+nogfdl-1_all.deb /tmp/deb/

Again, make sure the target directory is empty to avoid intermingling your own files and files from the package.

The letters RPM stand for Redhat Package Manager.  The file extension rpm is used for packages of software designed to be installed on a some distributions of GNU/Linux.   RPM is used on Redhat, SuSE, and distributions based off of these two major distributions, such as Fedora, CentOS, and  OpenSuSE.  RPMs are shipped in a format called cpio. This format has the advantage of allowing longer file names, and providing stroage and compression all in one utility and format.  However, RPMs are not exactly cpio format, and you have to run a converter first, before you can extract the files.  This converter is called rpm2cpio.  It reads the filename in as the first command line parameter, and outputs the cpio file to standard output.  So if you run it without redirecting output, you are going to spew binary data all over your terminal.  Better to redirect it into the cpio utility, with the command line switches -di.  These switches mean extract the files, and build any subdirectories required.  Again, run this in a clean directory:

rpm2cpio ../testware-e.x.p-00000.i386.rpm | cpio -di

Deadpoint

When you throw something straight up in the air, there is a point where it has no movement at all. Before this point, it is rising, after this point it is falling. But for an instant, it is floating. This is the deadpoint.

Thanks, Randall!

(Courtesy of Randall Munroe)

When climbing, you want your body at the deadpoint when grabbing a climbing hold. If you grab before the deadpoint, your own momentum will continue to carry you upward and off the hold. If you grab after the deadpoint, your downward momentum will put additional strain on your fingers, making it harder to hold on. If you grab exactly at the deadpoint, you will maximize your ability to hold on to small holds.

Don’t do Java bean properties in C++

The reason why Java has the bean API is to ensure that the caller does not delete the object when setting it.

void setX(String val){

if (val == null) return;

this.x = val;

}

This is not necessary in C++, since the parent object owns the memory of the child object.  The equivalent C++ code would be simple

o.x = val;

If you want to do validation (see my earlier posts about regex validation) use a subclass that does the validation in its constructor and assignment operator.

Basic Body Position for Rock Climbing

The first rule of climbing is to climb on straight arms.

Compare these two pictures.

the_x.jpegbent_arms.jpeg

The climber in the first picture is supporting his weight on his skeleton. In both pictures, the climbers are actively using the muscles that keep the fingers curled, but the first climber is using only those muscles, the second climber is using far more. Aside from the obvious bicep and latissimus dorsai muscles, the bent arm position in the second picture shows a climber stressing out the muscles in the forearm. It is this mistake, spending too much time on bent arms, that is responsible for the pumped feeling a new climber gets after a few climbs. There is a tendon system that runs down your arm and connects to your back. when you climb on straight arms, you hang on this tendon system. It is a holdover from our monkey ancestors that swung through the trees. Remember crossing the monkey bars as a kid? You swung from straight arm to straight arm. When you climb up, you want to use straight arms, too.

Try this simple experiment:

Hold a book by the two fingers, one at the top of the binding, one at the bottom. If you hold the spine perfectly vertical, the pages splay out. If you tilt the book so the the top is no longer over the bottom, the whole book will rotate so the open pages are all pointed straight at the ground.

In geometry, we learn that a triangle is defined by three points, and that a plane is also defined by three points. We can make a triangle out of our book example with one point on the top of the spine, one on the bottom of the spine, and one in the center of gravity. What we see is that the plane defined by these three points will always rotate itself to align perpendicular to the ground. The two fixed points act like the hinges on a poorly hung door. The door will always swing to point toward the center of the earth.

This holds true for climbing. The simplest example is a climber holding on with both hands and no feet. The climber naturally dangles toward the ground. For people, the center of balance is typically the abdomen. Thus the triangle is formed by the two hands and the navel.

.the_triangle.png

In order to move smoothly, you are going to be holding on to the wall with only two points of contacts much of the time. In order to it is far more important that you align the triangle of you body with the ground. If you don’t you will be fighting your bodies tendency to rotate. One way that climbers do this is to only move one limb at a time while keeping three in contact with the wall. This limits your options significantly. The other way is to try and overuse the muscles of the forearm to battle the rotation, causing premature flame-out.

The longest line of the body if from hand to opposite side foot. This follows either the red or green line of the body. Note that where these two lines cross is near the center of balance.

the_x.png

Let’s put together these items. The longest line of the body is from one foot to the opposite side hand, and this line crosses through the center of balance. We want to keep the center of balance in line with the contact points on the wall. This leads to body positions similar to the one displayed below.

in_line.jpeg

First and foremost, the climber is holding on with a straight left arm. This climbers body is in line from left hand, through abdomen, to right foot. His left foot and right arm counter balance each other to keep his body in line. If he finds his center of balance is off, he can adjust either limb to bring it back aligned. If he moves is right hand in or out along the dotted red line, his center of balance will adjust in or out parallel to that line. Additionally, he can move his hand in a circle and adjust his center of balance accordingly as well.

in_line_hand_adjust.png

His left leg follows the same rules. If he extends it out along the red dotted line,it pulls his center of gravity out along it. If he lowers his leg along the circle, he pulls his center of gravity in toward his body.

in_line_foot_adjust.png

The general pattern in climbing, especially in the gym, it reach up with the inside arm, and then to pivot so that arm becomes the outside arm. When you reach up with your left hand, you left hip will be pressed against the wall. Once you have that hold, you will pivot so that your right hand is against the wall. The climber in the picture above could well end up in a position similar to this:

right_side_against_wall.jpeg

The climber is leaning back against the side pull held by the left hand. He flags his left foot to provide a counter balance. This moves his center of gravity toward the line between his right foot and his left hand. If he continues to torque around on this axis, he can push with his toe against the wall to provide a counter force. Once he grabs the hold with his right, he is likely to step through so his left hip is against the wall, standing on the outside of the left foot. This pattern of alternating the hip against the wall while reaching with the inside arm is a motion similar to swimming or salsa dancing.

Contrast this with an attempt to use both limbs on the same side of the body. When the climber lets go with the right hand, and unloads the right foot, gravity pivots his body around the axis of the two remaining points of contact and the climber ends swinging out from the wall, a movement called “Barn Dooring”

barn_door.png

Here the green line shows the axis of the pivot, and the red arrow the movement of the swing.

C++ optimization for string16

Since wchar_t is 32 bits on Linux, I need to transform wstring to a different type in order to call the ODBC functions. The Windows code, on the other hand, can just use wstrings c_str() function to access the internal representation of the string. My goal is to minimize the code differences between platforms. On Linux, I will create a new class for string16 see earlier post). On Windows, I will just typedef wstring to string16. My hope then is to get the OS specific code down to the Linux implementation of string16, and to have the typedef optimize away the differences.

Here is a simplified version of the code that will be built and run on Windows:

typedef wstring& sqlstring;

void dothing(wstring s){
sqlstring sql(s);
wcout << sql << endl;
}

void doanother(wstring s){
wcout << s << endl;
}

And the result of building and disassembling using g++. Note that the code is the same. Hopefully Windos C++ complier will behave the same.

0000000000400ae0 <_Z9doanotherSbIwSt11char_traitsIwESaIwEE>:
400ae0: 48 83 ec 08 sub $0x8,%rsp
400ae4: 48 89 fe mov %rdi,%rsi
400ae7: bf c0 12 60 00 mov $0x6012c0,%edi
400aec: e8 07 fe ff ff callq 4008f8 <_ZStlsIwSt11char_traitsIwESaIwEERSt13basic_ostreamIT_T0_ES7_R
KSbIS4_S5_T1_E@plt>
400af1: 48 83 c4 08 add $0x8,%rsp
400af5: 48 89 c7 mov %rax,%rdi
400af8: e9 0b fe ff ff jmpq 400908 <_ZSt4endlIwSt11char_traitsIwEERSt13basic_ostreamIT_T0_ES6_@pl
t>
400afd: 90 nop
400afe: 66 90 xchg %ax,%ax

0000000000400b00 <_Z7dothingSbIwSt11char_traitsIwESaIwEE>:
400b00: 48 83 ec 08 sub $0x8,%rsp
400b04: 48 89 fe mov %rdi,%rsi
400b07: bf c0 12 60 00 mov $0x6012c0,%edi
400b0c: e8 e7 fd ff ff callq 4008f8 <_ZStlsIwSt11char_traitsIwESaIwEERSt13basic_ostreamIT_T0_ES7_R
KSbIS4_S5_T1_E@plt>
400b11: 48 83 c4 08 add $0x8,%rsp
400b15: 48 89 c7 mov %rax,%rdi
400b18: e9 eb fd ff ff jmpq 400908 <_ZSt4endlIwSt11char_traitsIwEERSt13basic_ostreamIT_T0_ES6_@pl
t>
400b1d: 90 nop
400b1e: 66 90 xchg %ax,%ax

Reading C++ symbols in a binary

objdump -t will pull the raw symbols out of an elf binary, but it is mangled format like this

0000000000000000       F *UND*  0000000000000006              _ZNSt13basic_ostreamIwSt11char_traitsIwEElsEPFRS2_S3_E@@GLIBCXX_3.4

c++ file will translate this to a human readly string that maps to the rigianlfunction definition:

 adyoung@adyoung-devd$ echo _ZNSt13basic_ostreamIwSt11char_traitsIwEElsEPFRS2_S3_E@@GLIBCXX_3.4 | c++filt
std::basic_ostream<wchar_t, std::char_traits<wchar_t> >::operator<<(std::basic_ostream<wchar_t, std::char_traits<wchar_t> >& (*)(std::basic_ostream<wchar_t, std::char_traits<wchar_t> >&))@@GLIBCXX_3.4

To do this for an entire file, you want to print only the last column, a task custom made for awk:

 objdump -t   casttest | awk ‘{print $(NF)}’ | c++filt