Posts

java - Which code performs better in terms of Time-complexity? -

below 2 java codes find number of 1 bits in integer n. code 1: int count = 0; while (n != 0) { n = n & (n - 1); count++; } return count; code 2: int = n; = - ((i >>> 1) & 0x55555555); = (i & 0x33333333) + ((i >>> 2) & 0x33333333); = (i + (i >>> 4)) & 0x0f0f0f0f; = + (i >>> 8); = + (i >>> 16); return & 0x3f; as far understand, first approach has complexity of o(n), while second 1 o(1). second 1 supposed better. however not sure it. you have take care when talking time complexity. big-o provides measure of asymptotic runtimes, means need measure runtimes arbitrarily large n. programming languages not provide (by default) int types arbitrarily large fudge issue bit , pretend do. the first code snippet works if pretend int can large possible. runs 1 loop per 1 in binary representation of n , in worst case takes log_2(n) iterations. it's o(log n). the second code snippet doesn...

laravel 5 - CLI stopped working error -

i "cli stopped working" error when press upload button.i used sample code 1 of website upload file database column. use laravel 5.2.39. command used: php artisan serve code:(only test version) form.blade.php <form method="post" enctype="multipart/form-data" action="/upload_file"> {{ csrf_field() }} <input type="file" name="file" /> <input type="submit" name="submit" value="upload" /> </form> routes.php (not ideal place code file upload test purpose) route::get('/upload_form', function() { $data['files'] = attachment::get(); return view::make('form', $data); }); route::post('/upload_file', function() { $rules = array( 'file' => 'required|mimes:doc,docx,pdf', ); $validator = validator::make(request::all(), $rules); if(request::hasfile('file...

computation theory - A language that is RE complete with respect to polynomial-time reductions? -

is there language in re complete regard polynomial-time reductions? i think a_tm example,but i'm not sure... yes, a tm re -complete respect polynomial-time reductions. given re language l, let m recognizer it. function f(w) = can computed in polynomial time (for reasonable representation of tuples) because m fixed machine , length of w in encoded version should @ polynomially larger original input w. have w &in; l if , if m accepts w if , if &in; a tm , f polynomial-time reduction arbitrary re language l a tm , making a tm re -complete respect polynomial-time reductions. i'm not sure why you'd interested in particular notion of re -completeness, since re useful notions of computability (can solve problem @ all?) while polynomial-time reductions complexity (can solve problem efficiently?) if have interesting use case them, though, i'd love hear it!

python - How to pick key words from a list, after appending a .csv file to that list? -

i need able pick keywords excel csv file, i've appended file list. program phone troubleshoot, , need input ("the screen won't turn on") have same output if inputted ("the display blank"). "troubleshooting program give user solution trouble they've encountered based on inputted key words." phoneprob=input("what problem having phone? ") prob=open("phone.csv","r") phone=prob.read() prob.close() eachprob=phone.split("\n") print(eachprob) problist=[eachprob] print (problist) are trying build keyword dictionary or retriving sentence problem ? in both case, need associate problem keywords. a basic approch keywords split sentence in words (using s.split()) , update keyword list used of them... difflib can here. since don't know given file schema, assume it's list of sentence , provided keyword/problems elsewhere (situation dict). for example: csv_ret = ["i can't tu...

java - How to manage Repository and UnitOfWork on top of JDBC -

i'm wondering best way of implementing unitofwork pattern on top of jdbc when using repository pattern. i want use uow commit or rollback commands potentially multiple different repositories. came repositories connection going execute commands on uow object , let manage committing or rolling back. now question how shall uow manage connections? shall 1 connection on start of cycle , share repositories when call connection , @ end either commit or roll back. or shall let datasource manage connections, , keep reference connections obtained in 1 session in order able commit or rollback of them? which way use best out of connection pooling , have less trouble in managing connections? maybe worth noting use single threaded approach, meaning whole cycle (single uow) run on single thread , there no fancy multithreading management required neither in uow nor in repositories. multiple cycles may run in parallel each on own thread.

java - Random User Id in MobileFirst 7.1 Test Token Endpoint -

i trying implement integration tests mobile first adapters. adapters use user identity custom realm. when writing tests adapters, need know user id, can prepare data in database , prepare mocked services. the problem test token endpoint generates random user id. , seems there no way configure provide same user id each request. there solution ? given there no way change in mobilefirst platform foundation 7.1, ore mentioned in comments, perhaps should return same mock data irregardless of user identity.

vb.net - Troubles to connect to Siemens S7 probably cause of bad protocol used -

i encounter many troubles connect plc, that, use libnodave library. here last informlations got : cpu 412-2 communication : cp 443-1 so far, manage connect automaton, but, if use - usertransport protocol, programs crashes when try read datum - isotpc or mpi protocols, can't connect plc ... so far, code isn't different 1 : http://www.automation-sense.com/medias/images/source-code-and-example-visual-basic-libnodave.jpg in case, port number 25, rack value 0 , slot value 3. what may suggest me do? thanks