Author Archives: Angel Marquez

Yum makes it easy

Often when I’m trying to figure out how to do something in Centos I’ll do the same thing as millions of other programmers and just Google the answer. But for some reason Centos top-hit results seems to have very convoluted answers for things that have much, much easier answers.

Note that I’m currently working with Centos 6.6/6.7. YMMV for other versions.

As a minor example: when you’re new to centos and want to find out how to install the epel repo you end up with guides having you wget or curl an rpm and then using rpm to install it. This top result from Google is one example of this: http://www.tecmint.com/how-to-enable-epel-repository-for-rhel-centos-6-5/

It’s not really that hard to do … and it certainly works …but there’s a way to do it in yum with the install you already have. You could just issue a

sudo yum install epel-release

It’s much the same for trying to figure out how to get a more recent release of python installed on the system. Centos comes with Python 2.6 and sometimes being able to use Python 2.7 or 3.3 would make life so much better. Here’s the top StackOverflow result for this topic: http://stackoverflow.com/questions/10624511/upgrade-python-without-breaking-yum

Those methods certainly work … but what if there was an easier way with just a yum command or two?  Indeed, newer packages are just a yum command away:

yum install centos-release-SCL

Additional information here: https://wiki.centos.org/AdditionalResources/Repositories/SCL
and here: https://www.softwarecollections.org/en/

And Python 2.7.8 – https://www.softwarecollections.org/en/scls/rhscl/python27/

Hope this helps save others some time

Commandline-fu

Derping around a GUI is all fine and good for many things but sometimes you really just need to get things done and your GUI just won’t cut it. Having a powerful command line interface and being knowing how to use it are critical skills. I’ve recently found myself having to use the command line a bit more than usual, so below are some of the learned or re-learned tidbits of knowledge that might help others.

Note: I’m a Windows developer, but the commands below all use bash in Cygwin.

Q: How can I generate a file of an arbitrary size with random data?

A: Use dd in conjunction with /dev/urandom

# 2 Megs
dd if=/dev/urandom of=a.log bs=1M count=2

# 2 Gigs (1 Meg * 2 * 1024)
dd if=/dev/urandom of=a.log bs=1M count=2K 
Note that 1kB = 1000 and 1K = 1024, 1MB = 1000 * 1000 while 1M =1024 * 1024, and so on.
Credit for this protip goes to the Linux Commando blog: http://linuxcommando.blogspot.com/2008/06/create-file-of-given-size-with-random.html

 

Q: How can I sort a file, remove duplicate elements, and do it all in-place?

A: sort temp.txt -o temp.txt

Q: How can I pipe the output from foo.exe to bar.exe if bar.exe does not accept input from stdin?

A: The obvious answer is to redirect stdout to a file then use the file as an input parameter.
(Note: md5sum *does* accept stdin input. Ignore that for the sake of the example)

echo -n hello > temp.dat
md5sum temp.dat
rm temp.dat

The command below can skip the intermediate step.

md5sum <(echo -n hello)
I wasn’t familiar with this syntax till recently. I discovered it in this bash redirections cheat sheet: http://www.catonmat.net/download/bash-redirections-cheat-sheet.pdf

My Reading List

I’ve been on a big reading spree this year. By genre, but otherwise in no particular order:

Non-fiction

Coding Related:

Career & Self:

Fiction

  • Dark Swan Series (Richelle Mead)
    • Storm Born
    • Thorn Queen
    • Iron Crowned
    • Shadow Heir
  • The Wise Man’s Fear (Patrick Rothfuss)
  • A Dance with Dragons (George R.R. Martin)
  • The Farseer Trilogy (Robin Hobb)
    • Assassin’s Apprentice
    • Royal Assassin
    • Assassin’s Quest
  • Southern Vampire Mysteries (Charlaine Harris)
    • Dead in the Family
    • Dead Reckoning
    • Deadlocked

 

Updating C++ project to VS2012

I’m currently working on updating one of our core projects to compile on Visual Studio 2012. These upgrades can sometimes be seamless. More often than not, though, there’s some issues that have to be resolved manually. Posting this up in hopes it might save someone out there some time if they’re hitting the same issues.

Item 0:

Before anything else it’s worth taking a look at the C++ breaking changes in VS2012. If I had done this first thing I would have saved some time trying to figure out why I couldn’t find afxcomctl32.h. The answer is it was removed.

Removed Fusion support (afxcomctl32.h); therefore, all methods that are defined in afxcomctl32.h have been removed. Header files afxcomctl32.h and afxcomctl32.inl have been deleted.

http://msdn.microsoft.com/en-us/library/bb531344.aspx

You can find for more information on activation contexts at http://msdn.microsoft.com/en-us/library/aa374153(v=vs.100).aspx

Item 1: Solution Configuration Combo Box

This one is just an annoyance, but worth posting up. The VS2012 standard bar doesn’t have an obvious way to resize the Solution Configuration combo box.

I was able to find the solution to the problem here:

 

Item 2: Error CA0053

Visual Studio 2010 apparently hard-codes some paths which cause issues for projects being upgraded. Solution info is here:

Item 3: makehm.exe errors

We have a custom build step that runs makehm.exe at the end of the build process. It kept generating an error and reporting that it was unable to open the output file. It looks like it’s just a bug with the program. It’s easy enough to work around by not specifying output and just using redirection to dump stdout output to a file. So instead of:

makehm.exe input_parameters_here output_file

change your command to

makehm.exe input_parameters_here > output_file

Item 4: warning RC4011: identifier truncated to ‘_CRT_SECURE_CPP_OVERLOAD_STANDA’

This error is caused by non-standard #include directives in your .rc files. In my case there was an “#include richedit.h” that was generating the issue. If not for Google this might have proved very difficult to track down as there is no clear indication what the culprit is. As you’ll find in the first link below:

RC files usually just include resource.h (which is just a list of #defines for control identifiers in your dialogs, etc.) and afxres.h (which includes winres.h and is like a cut-down version of the windows headers).
Reference:

Item 5: SAFESEH

The error at hand is “error LNK2026: module unsafe for SAFESEH image.”

Apparently when the project was upgraded the switch was turned on whereas previously the project had contained no value for this Advanced Linker switch.

 

If /SAFESEH is not specified, the linker will produce an image with a table of safe exceptions handlers if all modules are compatible with the safe exception handling feature. If any modules were not compatible with safe exception handling feature, the resulting image will not contain a table of safe exception handlers.

 

http://msdn.microsoft.com/en-us/library/9a89h429(v=vs.110).aspx

 

So you can either rebuild the libraries responsible for the error or you can disable it for the project you are building. Be aware there may be security implications to consider if you decide to turn the switch off. You can do so by going to the properties for the project and under Linker->Advanced the very last item should be “Image Has Safe Exception Handlers.” You can explicitly disable or just delete the entry to rely on default behavior.

 Item 6: Casting Errors

This post at Stack Overflow captures my issue. Essentially a casting operation that was working in VS2010 stopped working when I tried to compile the exact same code in VS2012.

C++ Compile Error in Visual Studio 2012: LPCWSTR and wstring

Coming soon:

 Item X: Unreachable Code

 Item X: BuildShadowTask

 

Today I learned: HOWTO trim WinSXS size

The C:\Windows\WinSXS directory can get way too big for comfort. On my Win2k8 VMWare image it was 10.9 gigs. On a VMWare image that’s just wasted space. After a little research I settled on a few steps to help me trim the fat down to 6.72 GB:

  1. Issued the command: dism /online /cleanup-image /spsuperseded
  2.  Install and run CCleaner
  3. Delete all the files in C:\windows\winsxs\Backup
I also experimented with WinSxs Lite — but it was taking too long for me to be able to see what a difference it makes. I’ll leave it running overnight at some point and report back. By the way, you’d be crazy to try using WinSxSLite on a real machine. I’m doing it because if it hoses my VMWare I restore with the press of a single button.

 

Using your domain for OpenID

Logging in to Stack Overflow today my curiosity about using OpenID got the better of me. I wanted to use my domain name as my login identifier. I quickly found instructions on using my domain with Google as my OpenID provider but I wanted to use myopenid.com

Turns out the process is really easy. The process is covered here: https://www.myopenid.com/help#own_domain

You just add the following tags to your page’s head tag.

<link rel="openid.server" href="http://www.myopenid.com/server" />
<link rel="openid.delegate" href="http://youraccount.myopenid.com/" />
<link rel="openid2.local_id" href="http://youraccount.myopenid.com" />
<link rel="openid2.provider" href="http://www.myopenid.com/server" />
<meta http-equiv="X-XRDS-Location" 
    content="http://www.myopenid.com/xrds?username=youraccount.myopenid.com" />

Voila! You can now use your domain as your login for OpenID!

WinDBG !locks is broken

This is old news, but I just discovered it today.

Apparently WinDbg !locks command is broken in the last stand-alone release of Debugging Tools for Windows. To fix the issue you need to download the WDK or downgrade to the previous version (6.10).

Found via http://www.voyce.com/index.php/2009/06/03/windbg-locks-command-broken/ while trying to track down a deadlock. I forgot how fun crash analysis can be . I say that both seriously and sarcastically at the same time. When your tools are broken it can lead to hours of wasted time. 🙁

-Angel

Personal note for later lookup: MS Symbol server path (for easy pasting):
SRV*W:\Symbols*http://msdl.microsoft.com/download/symbols;c:\temp

Dump any spare symbols you need in temp (not a best practice!)

MongoDB Notes

Some notes I took as I went through trying to compile the C++ driver for mongodb under win32.

  • Hit up MongoDB C++ Page
    • http://www.mongodb.org/pages/viewpage.action?pageId=133409
  • Downloaded driver linked from Driver Download Page & some other prerequisites
    • http://downloads.mongodb.org/cxx-driver/mongodb-linux-x86_64-v2.0-latest.tgz
    • http://www.mongodb.org/download/attachments/12157032/boost_1_42_vs2010_partial_prebuilt.7z
  • Went to C++ Driver Compiling and Linking and scrolled down to Windows
    • http://www.mongodb.org/pages/viewpage.action?pageId=21266598
  • Hrm. I’d rather not have to mess with scons … so how do I build the lib?
  • WTF? I want to try including client/mongo_client_lib.cpp in my project but IT’S NOT IN THE FRAKING ARCHIVE!
  • OK. Fine. Let’s fire up git and clone the full git source.
  • Ahh…. ok, found mongo_client_lib.cpp. Why the hell even bother putting up the tar ball?
  • Loaded simple_client_demo into visual studio.
  • Boost missing. Ok .. Let’s set up project to point to proper includes and precompiled libraries
  • Holy shit that compiled.
  • Fired up MongoDB Shell and created a collection.
  • Ran through the debugger. Everything works, but how come code references test.foo but in the shell it shows name is just ‘foo?
  • Apparently didn’t need perl regex files? (referenced elsewhere)
  • bo and bob? really?! (in bson seralization class)

Angel Marquez

February 8, 2012

My activity this evening? Downloaded the C++ driver for MongoDB and got it compiling in Visual Studio 2010. The BSON utility class seems pretty cool.