convert

How to convert unix timestamp to date in Spark

匿名 (未验证) 提交于 2019-12-03 02:14:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a data frame with a column of unix timestamp(eg.1435655706000), and I want to convert it to data with format 'yyyy-MM-DD', I've tried nscala-time but it doesn't work. val time_col = sqlc.sql("select ts from mr").map(_(0).toString.toDateTime) time_col.collect().foreach(println) and I got error: java.lang.IllegalArgumentException: Invalid format: "1435655706000" is malformed at "6000" 回答1: Since spark1.5 , there is a builtin UDF for doing that. val df = sqlContext.sql("select from_unixtime(ts,'YYYY-MM-dd') as `ts` from mr") Please check

Convert a username to a SID string in C#/.NET

匿名 (未验证) 提交于 2019-12-03 02:14:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: There's a question about converting from a SID to an account name ; there isn't one for the other way around. How do you convert a username to a SID string, for example, to find out which HKEY_USERS subkey relates to a user of a given name? 回答1: The podcast tells me I should ask, and answer, questions when they're not answered on SO already. Here goes. The easy way, with .NET 2.0 and up, is this: NTAccount f = new NTAccount("username"); SecurityIdentifier s = (SecurityIdentifier) f.Translate(typeof(SecurityIdentifier)); String sidString = s

How do I convert decimal to hexadecimal in Perl?

匿名 (未验证) 提交于 2019-12-03 02:14:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How can I convert a number, $d = 1024 , in decimal to 0xFF in hex in Perl? The d variable needs to be assigned to a different variable and be printed, so for readability I required it to be in hexadecimal format. 回答1: 1024 in decimal is not 0xFF in hex. Instead, it is 0x400 . You can use sprintf as: my $hex = sprintf("0x%X", $d); 回答2: Caveat: sprintf overflows at 2 64 19 , on 32-bit even already at only 2 32 9 . For large numbers, enable the lexical pragma bigint . as_hex is documented in Math::BigInt . use bigint; my $n = 2**65; print $n-

How do I convert a org.w3c.dom.Document object to a String?

匿名 (未验证) 提交于 2019-12-03 02:14:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I want to convert a org.w3c.dom.Document object to a String. I'm using Java 6 and am open to using any (completely free) technology that is up to the task. I tried the solution from this thread -- Is there a more elegant way to convert an XML Document to a String in Java than this code? , where they have DOMImplementationLS domImplementation = ( DOMImplementationLS ) doc . getImplementation (); LSSerializer lsSerializer = domImplementation . createLSSerializer (); String html = lsSerializer . writeToString ( doc ); but was greeted

PHP convert date format dd/mm/yyyy => yyyy-mm-dd [duplicate]

匿名 (未验证) 提交于 2019-12-03 02:14:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: Possible Duplicate: PHP Date String Format I am trying to convert a date from dd/mm/yyyy => yyyy-mm-dd . I have using the mktime() function and other functions but I cannot seem to make it work. I have managed to explode the original date using '/' as the delimiter but I have no success changing the format and swapping the '/' with a '-' . Any help will be greatly appreciated. 回答1: Dates in the m/d/y or d-m-y formats are disambiguated by looking at the separator between the various components: if the separator is a slash ( / ),

PIL - Convert GIF Frames to JPG

匿名 (未验证) 提交于 2019-12-03 02:14:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I tried to convert an gif to single images with Python Image Library, but it results in weird frames The Input gif is: Source Image http://longcat.de/gif_example.gif In my first try, i tried to convert the image with Image.new to an RGB image, with 255,255,255 as white background - like in any other example i've found on the internet: def processImage ( infile ): try : im = Image . open ( infile ) except IOError : print "Cant load" , infile sys . exit ( 1 ) i = 0 try : while 1 : background = Image . new ( "RGB" , im . size , ( 255

Cannot implicitly convert type 'double' to 'float'

匿名 (未验证) 提交于 2019-12-03 02:14:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm doing a simple program for converting temperatures with Kelvin, Celsius and Fahrenheit, but I'm getting this error when doing anything with kelvin: Cannon implicitly convert type 'double' to 'float' The line the error occurs: public static float FahrenheitToKelvin(float fahrenheit) { return ((fahrenheit - 32) * 5) / 9 + 273.15; } The button click: private void button1_Click(object sender, EventArgs e) { var input = float.Parse(textBox1.Text); float FahrenResult = FahrenheitToCelsius(input); textBox2.Text = FahrenResult.ToString(); float

Convert image (jpg) to base64 in Excel VBA?

匿名 (未验证) 提交于 2019-12-03 02:14:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I need to convert an image inside Excel (or through VBA) to base64 (in the end I will make XML output). How can I do this? Do I need to make a reference to DOM? this question but it only works for text strings not images... Does anyone have any code that I can see? 回答1: Heres a function. Can't remember where I got it from. Public Function EncodeFile ( strPicPath As String ) As String Const adTypeBinary = 1 ' Binary file is encoded ' Variables for encoding Dim objXML Dim objDocElem ' Variable for reading binary picture Dim objStream

Convert character matrix into numeric matrix

匿名 (未验证) 提交于 2019-12-03 02:14:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a 7 by 31 character matrix called extra4 and its structure looks like this: > str(extra4) chr [1:7, 1:31] "36.88 " " 45.48 " " 52.46 " " 111.31 " " 138.45 " " 121.09 " " 122.62" ... - attr(*, "dimnames")=List of 2 ..$ : chr [1:7] "1990" "1991" "1992" "1993" ... ..$ : chr [1:31] "1" "2" "3" "4" ... After reading similar questions in SO I've tried the following but I've failed: >matrix(as.numeric(unlist(extra4)),nrow=nrow(extra4)) Warning message: In matrix(as.numeric(unlist(extra4)), nrow = nrow(extra4)) : NAs introduced by coercion

Convert multi-channel PyAudio into NumPy array

匿名 (未验证) 提交于 2019-12-03 02:14:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: All the examples I can find are mono, with CHANNELS = 1 . How do you read stereo or multichannel input using the callback method in PyAudio and convert it into a 2D NumPy array or multiple 1D arrays? For mono input, something like this works: def callback(in_data, frame_count, time_info, status): global result global result_waiting if in_data: result = np.fromstring(in_data, dtype=np.float32) result_waiting = True else: print('no input') return None, pyaudio.paContinue stream = p.open(format=pyaudio.paFloat32, channels=1, rate=fs, output