Cmake tips

  • When adding an install target (so that your library/file is installed during “make install"), you use:
    install(TARGETS <target> DESTINATION <path>).
    <target> is what you used in your add_library (or add_executable).
    The <path> is somewhat tricky. If the path is not absolute, then cmake will automatically add CMAKE_INSTALL_PREFIX to the generated cmake_install file.
    For example:
    install(TARGETS mylib DESTINATION "path/to/lib") will result in: FILE(INSTALL DESTINATION "${CMAKE_INSTALL_PREFIX}/path/to/lib" ... inside the cmake_install.cmake file.
    A common mistake is to do: install(TARGETS mylib DESTINATION "${CMAKE_INSTALL_PREFIX}/path/to/lib")
    which will generate: FILE(INSTALL DESTINATION “/whatever-CMAKE_INSTALL_PREFIX-was-during-cmake/path/to/lib” which is not what you want (it will use the CMAKE_INSTALL_PREFIX value at cmake time and “hardcode” it inside cmake_install.cmake). If, then, you run something like:
    cmake install -DCMAKE_INSTALL_PREFIX=new/path -P cmake_install.cmake
    it will not use the new/path.
  • When explicitly specifying library names in CMakeLists or via -D flag in the cmake command line, here is something to keep in mind:
    The actual library file name might be something like libfoo.so (or libfoo.dylib) but the name you specify in the -l option is without the “lib” prefix, like so: -lfoo. If you specify -llibfoo it won’t find it.

Cmake tips

Christmas comes early to DB2 for z/OS development team

With holiday season upon us, DB2 developers have one more reason for the cheer 😉 – we have transformed our development infrastructure to Git.

This was a monumental effort (both size and significance-wise) and took us close to 11 months to complete, including a month-long “live” switch between old and new environments (or as I call it, “changing tires on the car while driving”). Last similar effort took more than 2 years, so I think we must have set some kind of record for transforming a legacy build infrastructure 😉

Here are some highlights I think might be interesting:

  • Prior to git (we use GitHub) our source code was in several legacy SCMs: SPA, CMVC, and RTC. We moved all of it to GitHub (our older releases v10 and v11, and our current release v12).
  • Moving the code over was the simplest part. The biggest complexity was in the way we deliver fixes to customers. It’s difficult to describe in few sentences for someone not familiar with what a PTF is, but essentially, we ship each fix (commit) as individually applicable (via SMP/E) object, and customers can pick and choose which fix to apply. This means our build infrastructure has to track and manage all changes (commits), because if several commits changed the same file, they would need to be built, packaged, and later applied, in certain order.
  • Because Db2z is mission critical to all our customers, we had to minimize impact to the service stream. We had to engineer a way to handle in-flight fixes that were already built and were in the test pipeline (and had to be shipped from the old environment) while also allowing new fixes to be developed and tested in the new environment. Unfortunately, because developers knew the migration schedule, they naturally rushed in all their fixes in the last day of the old environment. We ended up with about 270 different fixes (APARs) in-flight to handle during the switch. That’s close to 6 times our normal in-flight numbers.
  • The switch was further complicated by the usual things common to many software development projects, such as: fixes failed test and had to be re-worked and re-submitted, major new function delivery perfectly timed to coincide with the migration, build infrastructure bugs, Murphy law (most of the things that could go wrong did in fact go wrong), etc. Nevertheless, through some heroic effort from everyone on the infrastructure team, the migration has been completed with a small window if “inactivity” (where no new fixes were shipped out).
  • We use GitHub, Jenkins builds that invoke z/OS build, and set of (micro)-services that we use as building blocks for automation and development/build tooling.

The reason I believe this is a big deal and is a good reason to celebrate is that git is such a great tool for developers. Some teams out there might take it for granted, but we all use SCM every day (and most of the day). So finally switching to a decent tool like git that doesn’t get in a way of your dev flow (and has abundant set of capabilities to address all sorts of corner use cases when needed), is a good enough reason, IMO, to jump with joy and even make a few cartwheels in the office hallway 😉
From the infrastructure development perspective, git is really easy to work with (and also GitHub APIs). Have you tried using RTC APIs? (what an abomination).
From performance perspective, git is at least an order of magnitude faster than RTC (RTC is what we used before). Developing Db2z will be a lot more fun with this new git-based infrastructure.

Christmas comes early to DB2 for z/OS development team

Accessing Db2 for z/OS from Python

In order to access Db2 for z/OS from Python, you need to install the ibm_db driver and have a proper license file.

To install the driver:

$ easy_install ibm_db

Then copy the IBM CLI license (should be named db2consv_zs.lic) to the license folder of where ibm_db clidriver was installed, (e.g. /usr/local/lib/python3.5/site-packages/ibm_db-2.0.7-py3.5-macosx-10.6-intel.egg/clidriver/license). If you are unsure where it was installed on your environment, you could use locate clidriver command to find it.

If you are doing this on Mac, you may need to explicitly add couple of paths to DYLD_LIBRARY_PATH:

$ export DYLD_LIBRARY_PATH=[your path to clidriver]/lib:$DYLD_LIBRARY_PATH
$ export DYLD_LIBRARY_PATH=[your path to clidriver]/lib/icc:$DYLD_LIBRARY_PATH

 

Refer to https://github.com/ibmdb/python-ibmdb/tree/master/IBM_DB/ibm_db for more details.

After you installed the driver and got your license in place, start Python and verify that you can connect:

>>> import ibm_db
>>> conn = ibm_db.connect('DATABASE=x;HOSTNAME=x;PORT=x;PROTOCOL=TCPIP;UID=x;PWD=x;','','')

Replace x, in the command above with the appropriate values of the location name, hostname, port, user name, and password.

References

You can visit the ibm_db driver page at https://pypi.python.org/pypi/ibm_db/
It lists all supported Python versions (at the time of this writing: 2.6, 2.7, 3.3, 3.4, 3.5). You can also download the latest version.

https://github.com/ibmdb/python-ibmdb contains some info on APIs, installation details, etc.

Accessing Db2 for z/OS from Python

RTC – how to hide widget header in dashboard

Here is a quick RTC (Rational Team Concert) tip.
When trying to make your team dashboard look nicer, you can hide the widget header by default. This is especially handy for HTML widget when using that widget as section separator (for readability).
For example, here is the view with the default – headers shown:Screen Shot 2017-10-05 at 12.17.26
You can observe the HTML headers showing up in the widgets. Note that you could change the title from default “HTML” to something less noticeable (I changed it to a “.” in the middle widget that says For Reviewers. You cannot have an empty title), but it still shows the icon and the header bar.
Here is the view with the headers hidden:Screen Shot 2017-10-05 at 12.30.31

You can see there are no more ugly headers and looks much better.

Here is how you do this.
In the widget header, select the Menu (little triangle icon) and then Appearance.
Under appearance, choose to remove the header background (the last icon in the list of background boxes, the one with a red line across). Once you select it, you will see an option to “Hide Header” in the upper right of the widget. Click it to hide the header and then click OK and don’t forget to click Save to save the dashboard:
Screen Shot 2017-10-05 at 12.39.15

 

RTC – how to hide widget header in dashboard

How to synchronize multiple element transformations in CSS

Here is a CSS trick to make multiple elements do something in synch, using child combinators. In my case, I wanted to have my nav sidebar slide out on mouse hover and, at the same time, have the menu icon rotate:

beforeafter
The pictures show before and after (icon rotated 90°, sidebar slide out).
The trick to do this (without using JavaScript) is to put the elements under the common parent element and then use child combinator with the hover selector, like so:

Put menu icon and menu slider under common parent:

html1

Use child combinator to specify the transformations:

.al-menu-combo:hover>.menu-btn {
  transform: rotate(-90deg);
}
.al-menu-combo:hover>.menu-slider {
  transform: translate3d(0px, 0, 0);
}

That’s it.
For the working demo look here: JSBin demo.

How to synchronize multiple element transformations in CSS

Why the digits of multiples of 9 add up to 9

Today (happy π day!), my daughter told me that she learned a cool trick at school. They are learning multiplication, and so she showed me that when you multiply a number 1 through 9 by 9 and then add up the digits of the result, they add up to 9.

I was curious why it is true, and it is easy to see with some arithmetic:

we want to show that if 9x = ab, where 0 < x ≤ 9 and a,b are digits, i.e. 9x = 10a+b
then a + b = 9.
9x = 10x-x+10-10 = 10x-10 +10-x = 10(x-1) + (10-x) = 10a+b = 9a + a+b = 9(x-1) + a+b
9x-9(x-1) = a+b
9 = a+b.

In general, if number is divisible by 9 then the sum of its digits will be also divisible by 9.
e.g.  number abcd = 1000a + 100b +10c +d = 999a + 99b + 9c + a+b+c+d =
= 9 (111a+11b+c) + a+b+c+d ==> a+b+c+d is divisible by 9.

This also generalizes nicely to any base-n such that, if number is divisible by n-1 then the sum of its digits is divisible by n-1.
e.g. number abcd = n³a + n²b + nc + d = (n³-1)a + (n²-1)b + (n-1)c + a+b+c+d =
= (n-1) ((n²+n+1)a + (n+1)b + c) + a+b+c+d ==> a+b+c+d is divisible by n-1.

Leave a comment if you know a nicer way to prove this or if you find any errors.

 

 

Why the digits of multiples of 9 add up to 9

U.S. schools are teaching math wrong

Recently, I got a chance to attend a presentation by Dr. Jo Boaler, who is the professor of Mathematics Education at Stanford University and co-founder of youcubed (www.youcubed.org). She shared her views on the issues of math education in the U.S. and presented some ideas on what teachers and parents could do to improve the way we teach math to our kids.
I will not go into the details of the talk, because a lot of the same information could be found on the youcubed web site, which, I believe, is a great source of inspirational material for parents and teachers. But I did feel compelled to shout out this blog, because so much of what Dr. Boaler said resonated with me.
As a background, I’ve learned math in another country. My family emigrated to U.S. from Russia after I graduated high school, but I had to take a senior year of high school in the U.S. in order to get some course work needed for getting into college  (and also to learn English), so my comparisons are based on the two different teaching approaches that I got exposed to personally.
Below are some points I took away from Dr. Boaler’s talk, in bold, along with  my comments. They are not the most important points (she presented many other great ideas/facts), but I just list two of them, where I had to restrain myself from shouting “hallelujah, amen to that!”

Math is not a speed race
So true. My high school exit exam, we were given five problems and six hours to solve them (actually I can’t recall exact time since it was long ago, but it was at least an hour per problem). They were difficult problems; only about ten kids solved four and only two kids solved all five. Tests throughout the school year were similar – about three problems per test and about 45  minutes to solve. Fast forward to my U.S. experience, I used to joke that all we are being tested on is who can add and multiply the fastest. It was a shock to my system at first, because my brain was trained/wired to tackle problems that did not have an obvious answer and several techniques or approaches had to be considered before discovering the solution. When I took the SAT test, it was a really a test of how fast I could read a problem text and then perform basic operation(s). To be fair, when I took AP Calculus test, it was a real math test.

Memorizers are lowest achievers
This made me flash back yet again into my own experience. The emphasis was always made on showing the understanding of the concepts and showing the work. Correct answer without showing how one arrived to it was not accepted. And, in some cases, when work showed correct logic but had an arithmetic error, that error played little role in the final grade. There were many kids who just tried to memorize all the formulas and they never did as good as kids who actually tried to understood the principles. I’ve always thought why should I memorize something I could easily derive. Of course, it is still useful, and in some cases essential, to remember some facts and formulas, so it is a balance and not one extreme or the other. The point is that, when learning, it is better to understand the idea and then try to remember some shortcut/formula than to memorize shortcut/formula in order to avoid having to understand the idea. There is nothing wrong with memorizing things later on. In fact, why even bother memorizing anything you could quickly look up somewhere. But, you can’t memorize or look up problem solving skills.

When I look at the new Common Core materials, I see a step in the right direction. There are, of course, many other issues that stand in the way, so just moving to the Common Core is not nearly enough to turn around the math education in U.S. However, it is very encouraging to have people like Dr. Boaler who inspire, educate,  and empower parents and teachers to make a difference in their kids’ math education.
It was a very good talk by Dr. Boaler, and I got some value and great insight out of it.
Visit the youcubed web site for tons of great material!

U.S. schools are teaching math wrong

Picking up the team’s trash

In any decent society, majority of citizens, when noticing a piece of trash on their way, would pick it up and throw it in a garbage can. They do it because it is the right thing to do, and does not take that much extra effort.
Don’t take this too literally (yeah, depends on what kind of trash it is, it’s size, stinkiness, consistency, etc.), but the idea is that people go about their business towards some goal or task, and then they notice something that is not right, that is totally unrelated and not really in their way, but they just fix it anyway.

Software development is social. A team working together is kind of a small society with it’s own common beliefs and principles, practices and rituals. Wouldn’t the same “being a good citizen” principles of the human society apply to developing software and be beneficial to the team?
Robert C. Martin describes “the boy scout rule” and advocates to “Always check a module in cleaner than when you checked it out.”, as well as not “littering” in the first place. As he points out, it’s just “common decency”, and I think of it as “being a good citizen”. It should be applicable to everything we do in the society/team.

Working in a team, I frequently encourage the “picking up the trash” behavior that goes beyond the coding aspect. For example, one recent real life example of “trash” manifestation we’ve run into was when some testing of a functional change was not done, because “extra setup” was required that apparently would take days to achieve. Team decided to look for reasons and justifications of why that particular test was not necessary. Even if there was a perfectly reasonable justification of not performing more comprehensive test in this specific case, the “picking up the trash” behavior would be for the team to at least investigate why this resource intensive setup was needed to test the part of our product and to communicate to the team that we have a gap in our test environment setup. Maybe I am too picky, but seems like a reasonable expectation to me.

 

Picking up the team’s trash