w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
How to convert .NET DateTime.Ticks value into DateTime in SQL Query?
See this answer: Declare @TickValue bigint Declare @Days float Set @TickValue = 634024345696365272 Select @Days = @TickValue * POWER(10.00000000000,-7) / 60 / 60 / 24 Select DATEADD(d, Cast(@Days As int), Cast('0001-01-01' As DATE)) + Cast( (@Days - FLOOR(@Days)) As DateTime)

Categories : SQL

ASP.NET equivalent to Python's os.system([string])
Well it isn't ASP.net specific but in c#: using System.Diagnostics; Process.Start([string]); Or With more access to the specific parts of running a program (like arguments, and output streams) Process p = new Process(); p.StartInfo.FileName = "cmd.exe"; p.StartInfo.Arguments = "/c dir *.cs"; p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardOutput = true; p.Start(); here is how you could combine this with an ASPx Page: First Process.aspx: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Process.aspx.cs" Inherits="com.gnld.web.promote.Process" %> <!DOCTYPE html> <html> <head> <title>Test Process</title> <style> textarea { width: 100%; height: 600px } </style> </head> <body>

Categories : Python

Why method now in Python is obtained as datetime.datetime.now instead of datetime.time.now?
"Now" is a point in time. That means date matters; if it's noon now, yesterday noon is not also now. (Time of day also matters; 9 AM today is also not now.) Thus, it makes sense to have a datetime.datetime.now, but not a datetime.time.now. It could make sense to have a datetime.time.currentlocaltime or datetime.time.currentutctime, but those methods don't exist. You could put in a feature request if you want.

Categories : Python

DateTime.Now.AddSeconds equivalent in IronPython
DateTime is part of the .Net framework, from the System namespace. Anything in the framework is pretty much the same regardless of what language you use. The following is valid in IronPython: import System dt = System.DateTime.Now.AddSeconds(30) The following is a screenshot from the console window in the interactive tutorial. The above assumes you really want to use the .Net System.DateTime object. But if you are doing a lot in python, you may want to use the Python datetime class instead. In Python, the timedelta class works very similar to the TimeSpan class in .Net: from datetime import datetime, timedelta dt = datetime.now() + timedelta(seconds = 30) This will work in any python interpreter, including IronPython. Below is another screenshot from the consol window in the

Categories : C#

Python Thread.start() throws weird exception relating to datetime.datetime
Your code doesn't show where timeout is coming from. It's not "suddenly becoming" anything. Whatever your code, at some point previously, a datetime.datetime was assigned to timeout. Either eliminate that condition, or handle it appropriately (perhaps by catching the exception). Update: You're modifying standard library code, which is an awful idea. Directly or indirectly, you're passing in a datetime.datetime. Use pdb to figure out where. Run your code in the python console. When you trigger the exception do import pdb; pdb.pm(), and you'll drop into the debugger at the site of the exception. You can explore from there.

Categories : Python

does poll system call know if remote socket closed or disconnected?
If the sockets breaks, poll() will return > 0, then you will have to check the return value of recv in order to know if the socket is disconnected (recv() will return 0 in this case). Also, what would poll return on 0 timeout. int rc = poll(fds, nfds, 0); poll() will return immediately, and the return value can be >= 0. You really should read the poll() manpage, there is all you need to know.

Categories : C

where do I find page source of pages on my system which I opened in Chrome and then Closed
it should be at ~/Library/Caches/Google/Chrome. good luck digging there :S this issue of loosing files was fixed years ago, learn how to use git http://try.github.io/

Categories : Osx

how to get system DateTime in webservice
From your error response, I assume that the problem is not in your code, but in the addressing of this method. You're probably trying to parse a string value into a DateTime format, somewhat like this: DateTime date = DateTime.Parse(dateAsString); If the dateAsString variable does not contain a valid date, then the ArgumentException you described will be thrown. You can resolve this by trying to find out what's wrong with the string date you're trying to parse. It could very well be an empty string that's causing the problem. To help you with finding the troublemaker, use DateTime.TryParse to throw a new Exception with some helpful information: DateTime date; if (!DateTime.TryParse(dateAsString, out date) { throw new Exception("Invalid date: " + dateAsString); }

Categories : Asp Net

Boost equivalent of System::String::Format("{0:D9}", x);
Try Boost.Format. The syntax isn't exactly the same, but you should be able to do everything you need with it. You'd write {0:D9} as %1$09d for the first argument (it's 1 based instead of 0 based), zero-padded decimal number with at least 9 digits. cout << format("%1$09d %1$09d") % x << endl; That would print the value of x twice. You can also pad with spaces instead of zeros by either leaving out the 0 or replacing it with a space: cout << format("%1$9d %1$ 9d") % x << endl;

Categories : C#

Is there a Java equivalent of IConvertible/System.Convert?
I'm not sure but i think they is no equivalent in JAVA. But you can test this solution : public String convertString(Object oject1) { if ( oject1 instanceof Integer) { /// convert method return stringConvert } if ( oject1 instanceof Long) { /// Convert method } ...... }

Categories : Java

DateTime, an exception of type 'System.InvalidOperationException'
I am not an expert of Windows Phone, but it seems to me that the Value property of a TimePicker control is defined as DateTime? meaning a nullable DateTime. When you try to assign it to a DateTime variable (that cannot accept null values) and the TimePicker is null you get the InvalidOperationException You could try with startBreak1 = startBreak1.Value ?? DateTime.MinValue;

Categories : C#

create datetime irrespective of system date
The date/time is stored in a particular format regardless of the system locality. Only the the output is affected by the locality. Regardless of how it "looks" you can always change the output using the ToString method And the various formats You can even implement a global cultureinfo to apply which may be what you're looking for

Categories : C#

null reference in coded webtest with system.datetime
You define three arrays: public string[] SessionID; public string[] SessionTime; public string[] CreatedTime; But, they aren't initialized before you attempt to use them. Basically, you are doing this: string[] foo; foo[1] = "bar"; And you need to do this: string[] foo = new string[10]; // sized appropriately foo[1] = "bar";

Categories : C#

implicit conversion between '' and 'System.DateTime' error
Cast it to DateTime?: private DateTime? pApproveDate=null; pApproveDate =(Reader["ApproveDate"]==DBNull.Value)?(DateTime?)null: Convert.ToDateTime(Reader["ApproveDate"]);

Categories : C#

How to solve System.DateTime does not contain a definition for TryParseExact" on Windows CE and C#
Checkout this explanation, it shows how to make your own tryparse, because compact framework does not have it's own. http://www.yortondotnet.com/2009/11/tryparse-for-compact-framework.html

Categories : C#

System.FormatException: String was not recognized as a valid DateTime
Try this if your Date's format is "yyyy/MM/dd": String[] date = typedDate.Text.Split(new char[] { '/' }); Datetime dy = new DateTime(int.Parse(date[0]), int.Parse(date[1]), int.Parse(date[2]));

Categories : C#

Issue to get current system datetime dynamically using windows service
The answer to this forum question says: If your Windows Service is running under the SYSTEM account or other account without a profile it will use the settings defined under the HKEY_USERS/.DEFAULT/Control Panel/International registry key. You can change these values from Control Panel / Regional and Language Options / Advanced by checking the check box Apply all settings to the current user account and to the default user profile. Also, read more about the issue on this similar question: Why is my CurrentCulture en-GB and my CurrentUICulture en-US.

Categories : C#

Property or indexer 'System.DateTime.TimeOfDay' cannot be assigned to — it is read only
You can only create new DateTime instances. According to your shown code, you want to set only the day time. This should do it: newStartDateGroup = DateTime.Today.Add(i.OpenTime); DateTime.Today is today at 00:00.

Categories : C#

Unable to convert MySQL date/time value to System.DateTime in VS2010
Set both of these configurations in your connection string. "Convert Zero Datetime=True" "Allow Zero Datetime=True" http://bugs.mysql.com/bug.php?id=26054 Please check manual under connect options and set "Allow Zero Datetime" to true, as on attached pictures, and the error will go away. Check this also: http://mdid.org/mdidwiki/index.php?title=Unable_to_convert_MySQL_date/time_value_to_System.DateTime_exception To fix this problem, either replace all invalid timestamps with NULL or a valid timestamp, or add Allow Zero Datetime=true

Categories : C#

Error converting value {null} to type 'System.DateTime' in input json
As the error is trying to tell you, .Net value types like DateTime cannot hold nulls. If you want to allow nulls, use nullable types: DateTime? StartDateFrom { get; set; }

Categories : C#

Benchmarking System performance of Python System
I would try and remove as many other processes as possible in order to get a repeatable benchmark. For example, I would set up a separate, dedicated server with an NFS mount to the directories. This server would only run inotify and the Python script. For simple server measurements, I would use top or ps to monitor CPU and memory. The real test is how quickly your script "drains" the directories, which depends entirely on your process. You could profile the script and see where it's spending the time.

Categories : Python

add datetime with datetime in python
You could do this: In [1]: import datetime as DT In [2]: d = DT.datetime(1900,1,1,2,0) In [3]: m = DT.datetime(1900,1,1,6,0) In [4]: delta = d - DT.datetime(1900,1,1,0,0) In [5]: m + delta Out[5]: datetime.datetime(1900, 1, 1, 8, 0) But note that this will give you a different answer if the year/month/date of d are different than 1900/1/1.

Categories : Python

Python 2: SMTPServerDisconnected: Connection unexpectedly closed
Most probably the gmail server rejected the connection after the data command (very nasty of them to do so at this stage :). The actual message is most probably this one: retcode (421); Msg: 4.7.0 [ip.octets.listed.here 15] Our system has detected an unusual rate of 4.7.0 unsolicited mail originating from your IP address. To protect our 4.7.0 users from spam, mail sent from your IP address has been temporarily 4.7.0 rate limited. Please visit 4.7.0 https://support.google.com/mail/answer/81126 to review our Bulk Email 4.7.0 Senders Guidelines. qa9si9093954wjc.138 - gsmtp How do I know that? Because I've tried it :) with the s.set_debuglevel(1), which prints the SMTP conversation and you can see firsthand what's the issue. You've got two options here: Cont

Categories : Python

How to execute code when a Python script is closed out?
import MySQLdb con = MySQLdb.connect(...) cursor = con.cursor() try: # do stuff with your DB finally: con.close() The finally clause is executed on success as well as on error (exception). If you hit Ctrl-C, you get a KeyboardInterrupt exception.

Categories : Python

Python Redis connection should be closed on every request? (flask)
By default redis-py uses connection pooling. The github wiki says: Behind the scenes, redis-py uses a connection pool to manage connections to a Redis server. By default, each Redis instance you create will in turn create its own connection pool. This means that for most applications and assuming your redis server is on the same computer as your flask app, its unlikely that "opening a connection" for each request is going to cause any performance issues. The creator of Redis Py has suggested this approach: a. create a global redis client instance and have your code use that. b. create a global connection pool and pass that to various redis instances throughout your code. Additionally, if you have a lot of instructions to execute at any one time then it may be worth having

Categories : Python

Finalizing a Cursor that has not been deactivated or closed or database not closed error
When you are done with the cursor, you need to call Cursor.close(). Leaving it not closed leads to memory leaks. E.g.: Cursor cursor = null; try { cursor = getContentResolver().query(myUri, MY_PROJECTION, null, null, null); if (cursor != null && cursor.moveToFirst()) { // moar code } } finally { if (cursor != null) { cursor.close(); } }

Categories : Android

Run a python socket server and if closed remotely start it listening again
The way you usually program a threaded socket server is: call accept() in a loop spawn a new thread to handle the new connection A very minimal example would be somethig like this: import socket import threading import time server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server.bind(('0.0.0.0', 9999)) server.listen(1) def handle(conn): conn.send(b'hello') time.sleep(1) # do some "heavy" work conn.close() while True: print('listening...') conn, addr = server.accept() print('handling connection from %s' % (addr,)) threading.Thread(target=handle, args=(conn,)).start() You're spawning new threads in which you create your listening socket, then accept and handle your connection. And while socketIsOpen is True your programm will be using a lot of

Categories : Python

Is there something in emacs package system equivalent to gemfile and gemfile.lock in ruby projects?
Cask is the closest you will get to Ruby Gem management. Due to limitations in Emacs package management there are some shortcomings though, for instance there is no way to fix dependencies to a specific version. But I am of the opinion that sophisticated dependency management is not really required in Emacs Lisp, anyway. After all, it's still an extension language for a text editor, however sophisticated, and no dollars are lost and no children die if some dependency breaks. Disclaimer: I am one of the maintainers of Cask.

Categories : Emacs

what is the python equivalent of "new" in C++
My problem is that this append happens by reference and I can't figure out how to initialize newdata to new memoryspace. If you're trying to append objects into a list by value, you might want to use something like copy.copy or copy.deepcopy to make sure what is being appended is copied. >>> # The Problem >>> class ComplexObject: ... def __init__(self, herp, derp): ... self.herp = herp ... self.derp = derp ... >>> obj = ComplexObject(1, 2) >>> list = [] >>> list.append(obj) >>> obj.derp = 5 >>> list[0].derp 5 >>> # obj and list[0] are the same thing in memory >>> obj <__main__.ComplexObject instance at 0x0000000002243D48> >>> list[0] <__main__.ComplexObject instance

Categories : Python

Application gets closed when terminal is closed, how to stop this?
Use nohup to prevent child processes from being killed when the terminal closes. spawn nohup /usr/bin/firefox https://www.google.com/ I assume there's more to the script, since there's no need to use Expect just to start firefox.

Categories : Python

Ruby equivalent for python try
begin some_code rescue handle_error ensure this_code_is_always_executed end Details: http://crodrigues.com/try-catch-finally-equivalent-in-ruby/

Categories : Python

equivalent from MATLAB to Python
Matplotlib offers nearly all plotting options Matlab does. Surface plots can be done as well: http://matplotlib.org/mpl_toolkits/mplot3d/tutorial.html#surface-plots To load images scipy has a PIL-wrapper (no clown included, sorry), which loads matplotlib-compatible numpy arrays. To sum up, you want the following packages: numpy, scipy, matplotlib and PIL. The combination of those four libraries should give you all you need. Also check out the pylab interface of these libraries, as it is very similar to Matlab. Example that does what I believe you want to do: from mpl_toolkits.mplot3d import Axes3D from scipy.misc import imread from matplotlib.pyplot import figure, show from numpy import linspace, meshgrid, sqrt, sin, mean, flipud clown = imread('clown.png') fig = figure() ax = fig.gca

Categories : Python

GAE - Python equivalent of getRemainingMillis()
Assuming that anything available as a method call would be available in their development system to facilitate offline development, there's no record of anything close in their 1.8.3 Python library. The apiproxy code making RPC calls appears to just set/use plain old socket timers, which doesn't appear to have a "how much longer until my timeout hits" method of any sort. Looks like you might be on your own to implement such a check, but would be an awesome feature request to make to Google, I'd vote it up myself: https://code.google.com/p/googleappengine/issues/

Categories : Python

Python list equivalent in C++?
Maybe storing boost::any in a std::vector? http://www.boost.org/doc/libs/1_54_0/doc/html/boost/any.html Here is a simple working example. See James comments below too. #include "../boost_1_54_0/boost/any.hpp" #include <vector> #include <string> #include <iostream> int main() { std::vector<boost::any> myList; myList.push_back(std::string("Hello")); myList.push_back(10); myList.push_back(std::string("World")); std::string any1 = boost::any_cast<std::string> (myList[0]); int any2 = boost::any_cast<int> (myList[1]); std::string any3 = boost::any_cast<std::string> (myList[2]); std::cout<<any1<<" "<<any2<<" "<<any3<<std::endl; return 0; }

Categories : C++

Is there a python equivalent to Laravel 4?
Yes. Pyramid is what you are looking for. It's written from the ground up to be based in common Python libraries and components, and you can swap out pieces for other pieces as you wish. Python as a language is geared for TDD, and Pyramid takes advantage of that. You can push your own libraries, if they are abstract enough, out to PyPi for yourself, if you wish, but you can of course just keep them within your own projects too. There are other Python frameworks, but if you're looking for modular and extensible, without a whole lot of framework interference in your working style preference, Pyramid is the way to go. P.S. this question is better suited for programmers.stackexchange.com.

Categories : Python

Equivalent expression in Python
Here's the thing... you can't do pointers in python, so what you're showing here is not "portable" in the sense that: float *px, *pz; <-- this doesn't exist int lx = LX; /* constant defined somewhere else */ int lz = LZ; /* constant defined somewhere else */ px = &(table[kx[i]][0][0])+lx; pz = &(table[kz[i]][0][0])+lz; ^ ^ ^ | | | +----+----------------------+---- Therefore none of this makes any sense... What you're trying to do is have a pointer to some offset in your multidimensional array table, because you can't do that in python, you don't want to "port" this code verbatim. Follow the logic beyond this, what are you doing with px and pz? That is the code you need to understand to try and port.

Categories : Python

Is there an equivalent of the "in" function from Python in C++?
If you are using C++ vectors: if (std::find(vector.begin(), vector.end(), yourItem)!=vector.end() ) .... would be the equivalent of if yourItem in vector:

Categories : C++

Scala equivalent of Python help()
I do not know of one built-in but you should use Scaladocs to find the same information. Unless you use eclipse which has an auto complete with short explanations. For instance it will give you all the commands for arrays after typing 'array.'.

Categories : Python

Python: Trying to create the equivalent of and(or(value,value,value))
In python, the output of an expression containing BOOLEAN OPERATORS need not be a BOOLEAN (http://docs.python.org/2/library/stdtypes.html) e.g., sysReq1 = ('system requirements' and '?') will make sysReq1='?' and note here that sysReq1 is not a boolean value but a string equalling to QUESTION MARK. Similarly, sysReq2 will also be equal to ? . And also, look for TRUTH VALUE TESTING in the above link as that will explain what values will be considered as FALSE expressions.

Categories : Python

IDL interpol equivalent for python
In your notation, the IDL interp function uses a as the input values, b as input abscissa values and c is the desired abscissa values you want to interpolate onto. In python (for 1D) it would be scipy.interpolate.interp1d: from scipy import interpolate interpfunc = interpolate.interp1d(b,a, kind='linear') x=interpfuc(c) scipy includes many more interpolation functions, including interp2d and griddata that you may find useful: http://docs.scipy.org/doc/scipy/reference/interpolate.html

Categories : Python



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.