convert

perl: convert a string to utf-8 for json decode

匿名 (未验证) 提交于 2019-12-03 08:48:34
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm crawling a website and collecting information from its JSON. The results are saved in a hash. But some of the pages give me "malformed UTF-8 character in JSON string" error. I notice that the the last letter in "cafe" will produce error. I think it is because of the mix of character types. So now I'm looking for a way to convert all types of character to utf-8 (hope there is a way perfect like that). I tried utf8::all, it just doesn't work (maybe I didn't do it right). I'm a noob. Please help, thanks. UPDATA Well, after I read the

Cannot convert value of type 'UnsafePointer<Double>' to expected argument type 'UnsafePointer<_>'

匿名 (未验证) 提交于 2019-12-03 08:48:34
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm working with an external C library in Swift for OS X. I get a value cda, which is defined in C as a double* (it is a pointer to a double array). When importing into Swift, it recognizes the type as UnsafeMutablePointer. I'm trying to convert this pointer and the count into a double array. Here's the code that I'm using (assume arrlen is the correct count of the array): let doublearrptr = UnsafePointer<Double>(cda) let xptarr = UnsafeBufferPointer<Double>(start: doublearrptr, count:arrlen) However, when compiling this code fragment, I get

convert double to float in Python

匿名 (未验证) 提交于 2019-12-03 08:48:34
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: In a Python program, I have these two values: v1 = 0.00582811585976 v2 = 0.00582811608911 My hypothesis is that v1 is a 64-bits floating point value, and v2 is v1 converted to a 32-bits floating point value. How can I verify this? Details: The first value comes from a hardware board that calculates with 64-bits precision. The board sends the value to a PC, but it should also convert the value to 32-bits precision and send that to another board, which in turn sends it to a PC. I just want to verify that this is really happening and all I have

How to convert date in .csv file into SQL format before mass insertion

匿名 (未验证) 提交于 2019-12-03 08:48:34
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a csv file with a couple thousand game dates in it, but they are all in the MM/DD/YYYY format 2/27/2011,3:05 PM,26,14 (26 and 14 are team id #s), and trying to put them into SQL like that just results in 0000-00-00 being put into the date field of my table. This is the command I tried using: LOAD DATA LOCAL INFILE 'c:/scheduletest.csv' INTO TABLE game FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n' (`date`, `time`, `awayteam_id`, `hometeam_id`); but again, it wouldn't do the dates right. Is there a way I can have it

How can I convert an onload promise into Async/Await

匿名 (未验证) 提交于 2019-12-03 08:48:34
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have the following Typescript that I would like to use async / await on. But I can't seem to sort it out in my head how to do this. private getWorkbookFromFile2(excelFile: File): Promise<xlsx.IWorkBook> { var loadedPromise = new Promise<xlsx.IWorkBook>((resolve, reject) => { var reader = new FileReader(); reader.onload = (event: any) => { var data = event.target.result; var workbook = xlsx.read(data, { type: 'binary' }); console.log(workbook.SheetNames); resolve(workbook); }; reader.readAsBinaryString(excelFile); }); return loadedPromise;

is it possible to convert a string to varbinary in PHP without using the SQL function

匿名 (未验证) 提交于 2019-12-03 08:48:34
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I was wondering if it is possible to convert a string to varbinary with PHP to get the same effect as with using the SQL function CONVERT(varbinary, 'data') I would like to do this because I am using codeigniter and would like to use active records for this query, and because of this not directly use a string of SQL, but I need to insert the data into a varbinary field in MS-SQL. Thanks :) 回答1: you can cast a string as a binary if you are using a recent enough version of PHP. $binary = (binary)$string; (binary) casting and b prefix forward

How to convert a pygame Surface to a PIL Image?

匿名 (未验证) 提交于 2019-12-03 08:46:08
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm using PIL to transform a portion of the screen perspectively. The original image-data is a pygame Surface which needs to be converted to a PIL Image. Therefore I found the tostring-function of pygame which exists for that purpose. However the result looks pretty odd (see attached screenshot). What is going wrong with this code: rImage = pygame.Surface((1024,768)) #draw something to the Surface sprite = pygame.sprite.RenderPlain((playboard,)) sprite.draw(rImage) pil_string_image = pygame.image.tostring(rImage, "RGBA",False) pil_image =

Convert Double to ByteArray or Array&lt;Byte&gt; Kotlin

匿名 (未验证) 提交于 2019-12-03 08:46:08
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Given a Double val double = 1.2345 How can I convert that to a Kotlin ByteArray , and/or Array<Byte> ? Whose content would look like the following after converting 1.2345 00111111 11110011 11000000 10000011 00010010 01101110 10010111 10001101 In Java, there is a sollution that involves Double.doubleToLongBits() (A static method of java.lang.Double), but in Kotlin, Double refers to Kotlin.Double , which has no such (or any other useful in this situation) method. I don't mind if a sollution yields Kotlin.Double inaccessible in this file. :)

D3js : How to convert svg text to path?

匿名 (未验证) 提交于 2019-12-03 08:46:08
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Is there a D3.js way to convert a text element into a path element? So when I grasp the generated svg, I could keep my the texts shapes. 回答1: There is no way in JavaScript (d3 or any other tool) to access the vector path information about the shape of individual letters in system or web fonts. It's a requested feature for SVG 2, but there are no firm proposals for how it would work. The Raphael method described in the question linked by Lars Kotthoff uses a font object that has already been converted to JavaScript, using the Cufon font

Convert json to pandas DataFrame

匿名 (未验证) 提交于 2019-12-03 08:46:08
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a JSON file which has multiple objects such as: {"reviewerID": "bc19970fff3383b2fe947cf9a3a5d7b13b6e57ef2cd53abc52bb2dfedf5fb1cd", "asin": "a6ed402934e3c1138111dce09256538afb04c566edf37c16b9ba099d23afb764", "overall": 2.0, "helpful": {"nHelpful": 1, "outOf": 1}, "reviewText": "This remote, for whatever reason, was chosen by Time Warner to replace their previous silver remote, the Time Warner Synergy V RC-U62CP-1.12S. The actual function of this CLIKR-5 is OK, but the ergonomic design sets back remotes by 20 years. The buttons are all