Monthly Archives: May 2016


How to “group by” and sum in Excel

In the following example we used the Subtotal feature to create a spreadsheet that shows the partial sum based on another column.

Methodology:

  1. Click the Data tab in Excel’s ribbon toolbar
  2. Click the Sort button to sort our data by the user column
  3. Click the Subtotal button and fill in the dialog as appropriate, then click OK

In our example, we had only two columns (User and Lot), we wanted to produce the total sum of lots per user and so filled the dialog as follows:

Subtotal

What the above options do is the following:

  • Use the User column to group on by checking when its value changes
  • Use the Sum function on the columns that will be selected later on
  • Apply the function on the Lot column

Java: Given a path to a file, create the folders to it

Assuming you have a full path to a file you want to create but the folder to it might exist or not, you can use the following code in your program to check if the folder exists and if it doesn’t, create it.

//The file we want to create;
final String logFileName = "./someFolder/anotherFolder/etc/myFile.txt";
//We find the last occurrence of the File.separator value, which will allow us to separate the path from the filename
final int lastIndex = logFileName.lastIndexOf(File.separator);
//The actual path we want to make sure it exists
final String dirPath = logFileName.substring(0, lastIndex > 0 ? lastIndex : logFileName.length());
//We try to use the folder by assigning it to a File object
final File theDir = new File(dirPath);
//Make the check that the folder exists
if (!theDir.exists()) {
    //If the folder does not exist, create it
    theDir.mkdirs();
}
//Continue with execution

C++: Get size of enum 1

We used the following application in C++ to test the size of an enum:

#include <iostream>
using namespace std;

enum SINGLE {
        S_ZERO = 0x0,
        S_FULL = 0xFFFFFFFF
};

enum DOUBLE {
        D_ZERO = 0x0,
        D_FULL = 0xFFFFFFFFFFFFFFFF
};

int main() {
        cout << "Single Zero: Size '" << sizeof(S_ZERO) << "' Value '" << S_ZERO << "'" << endl;
        cout << "Double Zero: Size '" << sizeof(D_ZERO) << "' Value '" << D_ZERO << "'" << endl;

        cout << "Single Full: Size '" << sizeof(S_FULL) << "' Value '" << S_FULL << "'" << endl;
        cout << "Double Full: Size '" << sizeof(D_FULL) << "' Value '" << D_FULL << "'" << endl;
        return 0;
}

The output we got is the following:

Single Zero: Size '4' Value '0'
Double Zero: Size '8' Value '0'
Single Full: Size '4' Value '4294967295'
Double Full: Size '8' Value '18446744073709551615'

From the result it is pretty easy to understand that the size of an enum will grow to 64bit when any of its values is greater than 32bit.

For our test we used g++ (GCC) 5.3.1 20160406 (Red Hat 5.3.1-6) on a 64bit Fedora 23.


Fedora 23: Support exfat

The Background:

Recently we got our hands on a GoPro Hero4 Black camera and we used a 64GB memory card as storage. The file system on the card is exFAT (Extended File Allocation Table), which is a Microsoft file system designed for flash drives. It is proprietary and Microsoft owns patents on several elements of its design. exFAT has been adopted by the SD Card Association as the default file system for SDXC cards larger than 32GiB.

The issue:

Fedora does not support exFat due to the licensing issues that Microsoft applied to the product and thus we could not mount the card on our machine.

The solution:

We installed the fuse-exfat driver from rpmfusion.org using the following commands.

#Enable access to both the free and the nonfree repository
#free repository: for Open Source Software (as defined by the Fedora Licensing Guidelines) which the Fedora project cannot ship due to other reasons
#nonfree repository: for redistributable software that is not Open Source Software (as defined by the Fedora Licensing Guidelines); this includes software with publicly available source-code that has "no commercial use"-like restrictions 
su -c 'dnf install http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm';

#Perform the installation
sudo dnf install fuse-exfat;

More background:

RPM Fusion provides software that the Fedora Project or Red Hat doesn’t want to ship. That software is provided as precompiled RPMs for all current Fedora versions and Red Hat Enterprise Linux 5 and 6.