MySQL Error #1071 – Specified key was too long; max key length is 767 bytes

When I executed the following command: ALTER TABLE `mytable` ADD UNIQUE ( `column1` , `column2` ); I got this error message: #1071 – Specified key was too long; max key length is 767 bytes Information about column1 and column2: column1 varchar(20) utf8_general_ci column2 varchar(500) utf8_general_ci I think varchar(20) only requires 21 bytes while varchar(500) only … Read more

TypeError: a bytes-like object is required, not ‘str’ when writing to a file in Python 3

I’ve very recently migrated to Python 3.5. This code was working properly in Python 2.7: with open(fname, ‘rb’) as f: lines = [x.strip() for x in f.readlines()] for line in lines: tmp = line.strip().lower() if ‘some-pattern’ in tmp: continue # … code After upgrading to 3.5, I’m getting the: TypeError: a bytes-like object is required, … Read more

Converting string to byte array in C#

I’m converting something from VB into C#. Having a problem with the syntax of this statement: if ((searchResult.Properties[“user”].Count > 0)) { profile.User = System.Text.Encoding.UTF8.GetString(searchResult.Properties[“user”][0]); } I then see the following errors: Argument 1: cannot convert from ‘object’ to ‘byte[]’ The best overloaded method match for ‘System.Text.Encoding.GetString(byte[])’ has some invalid arguments I tried to fix the … Read more

How do I initialize a byte array in Java?

You can use an utility function to convert from the familiar hexa string to a byte[]. When used to define a final static constant, the performance cost is irrelevant. Since Java 17 There’s now java.util.HexFormat which lets you do byte[] CDRIVES = HexFormat.of().parseHex(“e04fd020ea3a6910a2d808002b30309d”); This utility class lets you specify a format which is handy if you find other formats easier … Read more