How to parse into base64 string the binary image from response?

I think part of the problem you’re hitting is that jQuery.ajax does not natively support XHR2 blob/arraybuffer types which can nicely handle binary data (see Reading binary files using jQuery.ajax). If you use a native XHR object with xhr.responseType=”arraybuffer”, then read the response array and convert it to Base64, you’ll get what you want. Here’s a … Read more

Is there a performance hit using decimal data types (MySQL / Postgres)

Pavel has it quite right, I’d just like to explain a little. Presuming that you mean a performance impact as compared to floating point, or fixed-point-offset integer (i.e. storing thousandsths of a cent as an integer): Yes, there is very much a performance impact. PostgreSQL, and by the sounds of things MySQL, store DECIMAL / … Read more

Why does calling Python’s ‘magic method’ not do type conversion like it would for the corresponding operator?

a – b isn’t just a.__sub__(b). It also tries b.__rsub__(a) if a can’t handle the operation, and in the 1 – 2. case, it’s the float’s __rsub__ that handles the operation. >>> (2.).__rsub__(1) -1.0 You ran a.__rsub__(2.), but that’s the wrong __rsub__. You need the right-side operand’s __rsub__, not the left-side operand. There is no … Read more

Why does java promote long parameter to float/double when there’s no method which accepts long?

Java Language Specification is pretty clear on that (emphasis mine): 15.12.2 Compile-Time Step 2: Determine Method Signature […] The first phase (§15.12.2.2) performs overload resolution without permitting boxing or unboxing conversion […] If no applicable method is found during this phase then processing continues to the second phase. […] The second phase (§15.12.2.3) performs overload … Read more

Convert Data to String in Swift 3

This is an example using a completion handler: class func getFilm(filmID: Int, completion: @escaping (String) -> ()) { let url = URL(string: “https://api.kinopoisk.cf/getFilm?filmID=\(filmID)”)! URLSession.shared.dataTask(with:url) { (data, response, error) in if error != nil { print(error!) completion(“”) } else { if let returnData = String(data: data!, encoding: .utf8) { completion(returnData) } else { completion(“”) } } … Read more

How to convert .txt file to Hadoop’s sequence file format

So the way more simplest answer is just an “identity” job that has a SequenceFile output. Looks like this in java: public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException { Configuration conf = new Configuration(); Job job = new Job(conf); job.setJobName(“Convert Text”); job.setJarByClass(Mapper.class); job.setMapperClass(Mapper.class); job.setReducerClass(Reducer.class); // increase if you need sorting or a special … Read more

Convert from scala.collection.Seq to java.util.List in Java code

You’re on the right track using JavaConversions, but the method you need for this particular conversion is seqAsJavaList: java.util.List<String> convert(scala.collection.Seq<String> seq) { return scala.collection.JavaConversions.seqAsJavaList(seq); } Update: JavaConversions is deprecated, but the same function can be found in JavaConverters. java.util.List<String> convert(scala.collection.Seq<String> seq) { return scala.collection.JavaConverters.seqAsJavaList(seq); }