HashSet contains duplicate entries

The problem is that your Element class has not overridden the equals and hashCode methods or these implementations are broken. From Object#equals method javadoc: The equals method implements an equivalence relation on non-null object references: It is reflexive: for any non-null reference value x, x.equals(x) should return true. It is symmetric: for any non-null reference … Read more

Unique hardware ID in Mac OS X

For C/C++: #include <IOKit/IOKitLib.h> void get_platform_uuid(char * buf, int bufSize) { io_registry_entry_t ioRegistryRoot = IORegistryEntryFromPath(kIOMasterPortDefault, “IOService:/”); CFStringRef uuidCf = (CFStringRef) IORegistryEntryCreateCFProperty(ioRegistryRoot, CFSTR(kIOPlatformUUIDKey), kCFAllocatorDefault, 0); IOObjectRelease(ioRegistryRoot); CFStringGetCString(uuidCf, buf, bufSize, kCFStringEncodingMacRoman); CFRelease(uuidCf); }

Composite PRIMARY KEY enforces NOT NULL constraints on involved columns

If you need to allow NULL values, use a UNIQUE constraint (or index) instead of a PRIMARY KEY (and add a surrogate PK column – I suggest a serial or IDENTITY column in Postgres 10 or later). Auto increment table column A UNIQUE constraint allows columns to be NULL: CREATE TABLE distributor ( distributor_id GENERATED … Read more

Find index where elements change value numpy

You can get this functionality in numpy by comparing each element with it’s neighbor; v[:-1] != v[1:] array([False, False, False, False, True, False, False, True, True, True, True, True, True, True, True, True, False, False], dtype=bool) to get the indices you use the “where” function np.where(v[:-1] != v[1:])[0] array([ 4, 7, 8, 9, 10, 11, … Read more