exists

check if there exists a[i] = 2*a[j] in an unsorted array a?

匿名 (未验证) 提交于 2019-12-03 08:46:08
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Given a unsorted sequence of a[1,...,n] of integers, give an O(nlogn) runtime algorithm to check there are two indices i and j such that a[i] =2*a[j]. The algorithm should return i=0 and j=2 on input 4,12,8,10 and false on input 4,3,1,11. I think we have to sort the array anyways which is O(nlogn). I'm not sure what to do after that. 回答1: You're right that the first step is sorting the array. Once the array is sorted, you can find out whether a given element is inside the array in O(log n) time. So if for every of the n elements, you check

Message: Undefined index: REMOTE_HOST in $_SERVER

匿名 (未验证) 提交于 2019-12-03 08:46:08
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Why do i get this error when i try to retrieve host name of remote user ? Message: Undefined index: REMOTE_HOST When reading documentation i came to know that it needs to be enabled in httpd.conf. But i am not sure what needs to be edited in httpd.conf. Can anybody help me figuring out the directive? Thanks in advance :) 回答1: This is not an error, it's a notice. REMOTE_HOST is not defined in all cases. REMOTE_ADDR is. You need to reconfigure your webserver if you need it. HostnameLookups On does it, but it incurs a slowdown. Alternative: Let

C++: Boost: how do I check the existence of a folder inside another folder in my working directory?

匿名 (未验证) 提交于 2019-12-03 08:44:33
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: code: boost :: filesystem :: path config_folder ( Config :: CONFIG_FOLDER_NAME ); if ( !( boost :: filesystem :: exists ( config_folder ))) { std :: cout << "Network Config Directory not found...\n" ; std :: cout << "Creating folder called " << Config :: CONFIG_FOLDER_NAME << "\n" ; boost :: filesystem :: create_directory ( config_folder ); } if ( !( boost :: filesystem :: exists ( boost :: format ( "%s/%s" ) % config_folder % Config :: fmap [ Config :: current_hash_function ])); { std :: cout << "This hash has not been configure

Error: Global connection already exists. Call sql.close() first

匿名 (未验证) 提交于 2019-12-03 08:44:33
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Hi I am creating node js restful api by using sqlserver database , i prepare get api when i am using that api output is shown in json format, while refreshing that browser gain its shows "Error: Global connection already exists. Call sql.close() first."error . I am adding code var express = require("express"); var sql = require("mssql"); var app = express(); //Initiallising connection string var dbConfig = { user: 'sa', password: 'India123', server: 'localhost', database: 'sample' }; app.get('/login', function (req, res) { // connect to your

Using Directory.Delete() and Directory.CreateDirectory() to overwrite a folder

匿名 (未验证) 提交于 2019-12-03 08:42:37
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: In my WebApi action method, I want to create/over-write a folder using this code: string myDir = "..."; if(Directory.Exists(myDir)) { Directory.Delete(myDir, true); } Directory.CreateDirectory(myDir); // 1 - Check the dir Debug.WriteLine("Double check if the Dir is created: " + Directory.Exists(myDir)); // Some other stuff here... // 2 - Check the dir again Debug.WriteLine("Check again if the Dir still exists: " + Directory.Exists(myDir)); Issue Strangely, sometimes right after creating the directory, the directory does not exist! Sometimes

File contains a path separator.

匿名 (未验证) 提交于 2019-12-03 08:36:05
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: When I try to check the existence of a particular file, I get java.lang.illegalArgumentException: File contains a path separator What is the right way to do this using getFileStreamPath(..)? File file = getActivity().getFileStreamPath("mnt/sdcard/photo/1342147146535.jpg"); if(file.exists()){ Toast.makeText(getActivity(), "File exists in /mnt", Toast.LENGTH_SHORT); } I also tried the following to replace the first line of the above codes. None of these worked. File file = getActivity().getFileStreamPath("file:///mnt/sdcard/photo/aviary

Creating an Oracle User if it doesn&#039;t already exist

匿名 (未验证) 提交于 2019-12-03 08:36:05
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to create a script that will create users if they do not already exist . CREATE USER "Kyle" PROFILE "DEFAULT" IDENTIFIED BY "password" ACCOUNT UNLOCK WHERE NOT IN //Also tried 'WHERE NOT EXISTS' ( SELECT username FROM all_users WHERE username = 'Kyle' ) The following error is given: SQL Error: ORA-00922: missing or invalid option I was able to do this in SQL Server 2008 by using: IF NOT EXISTS (SELECT name FROM master.sys.server_principals WHERE name = 'Kyle') BEGIN CREATE LOGIN Kyle WITH PASSWORD = 'temppassword' MUST_CHANGE,

Check if directory exists on FTP server

匿名 (未验证) 提交于 2019-12-03 08:36:05
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I'm running a check to see if a directory exists on my FTP server: public bool DirectoryExists ( string directory ) { bool directoryExists ; var request = ( FtpWebRequest ) WebRequest . Create ( directory ); request . Method = WebRequestMethods . Ftp . ListDirectory ; request . Credentials = new NetworkCredential ( "user" , "pass" ); try { using ( request . GetResponse ()) { directoryExists = true ; } } catch ( WebException ) { directoryExists = false ; } return directoryExists ; } In this case: directory = @ "ftp://ftp.example.com

Postgres database create if not exists [duplicate]

匿名 (未验证) 提交于 2019-12-03 08:36:05
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: This question already has an answer here: Simulate CREATE DATABASE IF NOT EXISTS for PostgreSQL? 3 answers Is there an analog to CREATE TABLE IF NOT EXISTS for creating databases? Background: I am writing a script to automatically set up the schema in PostgreSQL on an unknown system. I am not sure if the database (or even part of the schema) was already deployed, so I want to structure my code to not fail (or ideally even show errors) if some of the structure already exists. I want to differentiate the errors that prevent me from creating a

Check whether a path exists on a remote host using paramiko

匿名 (未验证) 提交于 2019-12-03 08:35:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Paramiko's SFTPClient apparently does not have an exists method. This is my current implementation: def rexists(sftp, path): """os.path.exists for paramiko's SCP object """ try: sftp.stat(path) except IOError, e: if 'No such file' in str(e): return False raise else: return True Is there a better way to do this? Checking for substring in Exception messages is pretty ugly and can be unreliable. 回答1: See the errno module for constants defining all those error codes. Also, it's a bit clearer to use the errno attribute of the exception than the