What does the Ruby method ‘to_sym’ do?

to_sym converts a string to a symbol. For example, “a”.to_sym becomes :a. It’s not specific to Rails; vanilla Ruby has it as well. It looks like in some versions of Ruby, a symbol could be converted to and from a Fixnum as well. But irb from Ruby 1.9.2-p0, from ruby-lang.org, doesn’t allow that unless you add your own to_sym method to Fixnum. I’m … Read more

Why would cv2.COLOR_RGB2GRAY and cv2.COLOR_BGR2GRAY give different results?

RGB->gray conversion actually isn’t an average — different channels are weighed differently. Specifically: This is also mentioned in the documentation. Thus, it’s expected that RGB2GRAY and BGR2GRAY give different results. Regarding the discrepancy between sum-then-divide and divide-then-sum approaches, i.e. between and Recall that cv2.imread returns a uint8 numpy array. Thus, the latter operation (where all channels are combined … Read more

Any shortcut to initialize all array elements to zero?

A default value of 0 for arrays of integral types is guaranteed by the language spec: Each class variable, instance variable, or array component is initialized with a default value when it is created (§15.9, §15.10) […] For type int, the default value is zero, that is, 0.   If you want to initialize an one-dimensional array to a different … Read more

How to run PHP locally on MacOS

OSX comes with php installed : So you can run your php file. But don’t forget to include your code between <?php … ?>. So now you can run in your terminal: Apache is not needed.

Using OpenMP with clang

Update Building the latest trunk of LLVM/Clang (clang-3.8), installing libiomp5, and specifying the location of the gomp omp header files worked. Note that the Ubuntu package for libiomp5 isn’t quite correct, so you will need to add a symlink in /usr/lib from /usr/lib/libiomp5.so to /usr/lib/libiomp5.so.5. I’m using g++-5.1 and clang++-3.6 on Linux Mint 17.2 (essentially … Read more

What does ** mean in C++?

There is no specific ** operator in C++, instead it’s two separate asterisks, and asterisks in a declaration denotes pointer declaration. So in the declaration the argument head is declared to be a pointer to a pointer to IntElement.