data-conversion

Input an integer, find the two closest integers which, when multiplied, equal the input

Deadly 提交于 2019-11-30 21:30:40
Ok my problem is of mathematical nature. I have an array of bytes whose length is X, i need to find the two closest numbers which multiplied together equal X. I need to do this because i am bulding a bitmap from an array of bytes and i need to make the bitmap look like a square as much as possible. I am coding this in C# but don' t worry about syntax, any algorithm or pseudo-code will do. Thanks in advance for your help There's probably a better algorithm for this, but off the top of my head: 1) Take the square root of the number X; we'll call it N. 2) Set N equal to the ceiling of N (round up

Why does Powershell file concatenation convert UTF8 to UTF16?

妖精的绣舞 提交于 2019-11-30 16:53:23
问题 I am running the following Powershell script to concatenate a series of output files into a single CSV file. whidataXX.htm (where xx is a two digit sequential number) and the number of files created varies from run to run. $metadataPath = "\\ServerPath\foo" function concatenateMetadata { $cFile = $metadataPath + "whiconcat.csv" Clear-Content $cFile $metadataFiles = gci $metadataPath $iterations = $metadataFiles.Count for ($i=0;$i -le $iterations-1;$i++) { $iFile = "whidata"+$i+".htm"

Fast integer to decimal conversion

て烟熏妆下的殇ゞ 提交于 2019-11-30 16:12:32
问题 Given an (unsigned) integer, what is the generally fastest way to convert it into a string that contains its decimal representation? The naïve way of doing that is repeatedly dividing by 10, until you reach zero. I dislike this approach, because it uses integer division, which is both slow and not available on some integrated platforms requires the programmer to flip the string afterwards. This doubles the number of memory operations needed. I thought of the following method to convert

Convert nested JSON to CSV file in Python

早过忘川 提交于 2019-11-30 16:06:17
问题 I know this question has been asked many times. I tried several solutions but I couldn't solve my problem. I have a large nested JSON file (1.4GB) and I would like to make it flat and then convert it to a CSV file. The JSON structure is like this: { "company_number": "12345678", "data": { "address": { "address_line_1": "Address 1", "locality": "Henley-On-Thames", "postal_code": "RG9 1DP", "premises": "161", "region": "Oxfordshire" }, "country_of_residence": "England", "date_of_birth": {

Convert nested JSON to CSV file in Python

二次信任 提交于 2019-11-30 15:48:17
I know this question has been asked many times. I tried several solutions but I couldn't solve my problem. I have a large nested JSON file (1.4GB) and I would like to make it flat and then convert it to a CSV file. The JSON structure is like this: { "company_number": "12345678", "data": { "address": { "address_line_1": "Address 1", "locality": "Henley-On-Thames", "postal_code": "RG9 1DP", "premises": "161", "region": "Oxfordshire" }, "country_of_residence": "England", "date_of_birth": { "month": 2, "year": 1977 }, "etag": "26281dhge33b22df2359sd6afsff2cb8cf62bb4a7f00", "kind": "individual

UTF conversion functions in C++11

做~自己de王妃 提交于 2019-11-30 13:30:26
问题 I'm looking for a collection of functions for performing UTF character conversion in C++11. It should include conversion to and from any of utf8, utf16, and utf32. A function for recognizing byte order marks would be helpful, too. 回答1: Update : The functions listed here are maintained in a GitHub repo, .hpp, .cpp and tests. Some UTF-16 functions have been disable because they do not work correctly. The "banana" tests in the utf.test.cpp file demonstrate the problem. Also included a "read_with

SSIS how to convert string (DT_STR) to money (DT_CY) when source has more than 2 decimals

。_饼干妹妹 提交于 2019-11-30 09:27:49
问题 I have a source flat file with values such as 24.209991, but they need to load to SQL Server as type money. In the DTS (which I am converting from), that value comes across as 24.21. How do I convert that field in SSIS? Right now, I am just changing the type from DT_STR to DT_CY, and it gives a run error of 'Data conversion failed. The data conversion for column "Col003" returned status value 2 and status text "The value could not be converted because of a potential loss of data.".' Do I use

Multiple y-axis conversion scales

一笑奈何 提交于 2019-11-30 07:42:16
Hi I'm trying to create plots which incorporate parallel conversion scales for two sets of units on the y-axis; using the two different styles of: offset ('parasitic') y-axes and overlaid/shared y-axes to replicate the style of the left-hand y-axes in the attached example images. I'd like to find the simplest generic way of producing both of the above example plots, which also allows me to generate the y-axis conversion scales by defining the relationship between the two sets of units as a function (in this example: mmHg = kPa * 7.5). If it's possible to add the third right-hand y axes (vapour

SQLAlchemy: Convert column value back and forth between internal and database format

核能气质少年 提交于 2019-11-30 03:49:23
问题 In my database, I have some columns where data is stored in some weird format. Since the database is used by other code, too, I cannot change the data format. For example, one of the weird formats is that a time value is represented as a string like 23:42:30 . I would like to have some magic that allows me to always use datetime.time objects on the python side. A very simple solution would be something like: col_raw = Column('col', String(7)) @property def col(self): return datetime.strptime

Convert string with comma to integer

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-30 01:05:45
Is there any neat method to convert "1,112" to integer 1112, instead of 1? I've got one, but not neat: "1,112".split(',').join.to_i #=> 1112 How about this? "1,112".delete(',').to_i You may also want to make sure that your code localizes correctly, or make sure the users are used to the "international" notation. For example, "1,112" actually means different numbers across different countries. In Germany it means the number a little over one, instead of one thousand and something. Corresponding Wikipedia article is at http://en.wikipedia.org/wiki/Decimal_mark . It seems to be poorly written at