Posts

performance while doing string concatenation - algorithm string strings c# -

i using following code append strings string res = string.empty; int ite = 100000; for(int i= 0; < ite; i++) { res += "5"; } it taking lot of time, later changed code string res = string.empty; int ite = 100000; res = getstr(ite / 2) + getstr(ite - (ite / 2)); //body of getstr method private static string getstr(int p) { if (p == 1) return "5"; else if (p == 0) return string.empty; string r1 = getstr(p / 2); //recursive string r2 = getstr(p - (p / 2)); //recursive return (r1 + r2); } which in opinion nothing number of times strings concatenated approximately same in previous approach. but using approach there significant improvement in performance code taking around 2500 ms (on machine) taking 10 ms. i ran profiler on cpu time , couldn't arrive @ understanding why there improvement in performance. can please explain this. note: intentionally not using stringbuilder, in order understand above. ...

Batch file syntax for multiple criteria? -

is possible have if statement check 2 criteria? or have 2 if statements? i want "if user name 'owen' or 'oiverson' goto this..." no! there many different ways work around. try this: set username=owen set found=no if [%username%]==[owen] set found=yes if [%username%]==[oiverson] set found=yes if %found%==yes goto :yes goto :no :yes @echo found user :no

android - $_FILES array empty via Java upload -

i'm trying upload file via android php $_files array comes empty: array() . i'm using httpurlconnection. i've substituted ip address of server , client , other personal information "<>". i verified file being uploaded (wireshark dump): no. time source destination protocol length info 16 2.493417 <ip_addr> <ip_addr> http 877 post /test.php http/1.1 frame 16: 877 bytes on wire (7016 bits), 877 bytes captured (7016 bits) ethernet ii, src: cisco_5a:0b:41 (<mac_address>), dst: <mac_address> (<mac_address>) internet protocol version 4, src: <ip_addr> (<ip_addr>), dst: <ip_addr> (<ip_addr>) transmission control protocol, src port: 52506 (52506), dst port: http (80), seq: 1958, ack: 461, len: 811 [3 reassembled tcp segments (2485 bytes): #13(306), #14(1368), #16(811)] hypertext transfer protocol post /test.php http/1.1\r\n...

javascript - jquery function not calling on button click -

below code, want alert "hi" , "hello" can put actual codes there. <html> <head> <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <script type="text/javascript"> if (typeof jquery == 'undefined') { document.write(unescape("%3cscript src='jquery-1.11.1.min.js' type='text/javascript'%3e%3c/script%3e")); } </script> <script src="jquery-ui.js"></script> <link rel="stylesheet" href="jquery-ui.css"> </head> <script> $(document).ready(function(){ alert("hi"); $('form[name="lgform"]').submit(function(evnt){ evnt.preventdefault(); }); $("#btn_login").click(function(){ alert("hello"); }); }); </script> <body> <form name="lgform...

html - Use jquery to crop a list and hide and show random list elements with a set maxium? -

i have <ul> on 6 <li> elements. want show 6 @ time. trick need randomly select elements hide, , stagger hide/show. for example current markup : <ul> <li>1<li> <li>2<li> <li>3<li> <li>4<li> <li>5<li> <li>6<li> <li>7<li> <li>8<li> <li>9<li> </ul> is possible use jquery hide/show elements provide random this: <ul> <li style="display:none">1<li> <li>2<li> <li style="display:none">3<li> <li>4<li> <li>5<li> <li>6<li> <li>7<li> <li style="display:none">8<li> <li>9<li> </ul> you should try things before posting questions here, include code have tried show have tried. however, simple, i'll answer question. expanding on this answer question generatin...

javascript - calling addEventListener without a DOM element -

i see salesforce lightning code calling addeventlistener without dom element , couldn't figure out doing. 1) why there not dom element before addeventlistener ? 2) purpose of '({' , '})' here ? ({ doinit: function(component, event, helper) { //listen iframe's message addeventlistener("message", function(event) { if(event.data.type === 'ready' && component.find("vfiframe")) {//iframe loaded component.iframeready = true; } else if(event.data.type === 'response') {//send response var cmpevt = component.getevent("response"); cmpevt.setparams({ "data" : event.data.response}); cmpevt.fire(); } }, false); }, makerequest : function(component, event, helper) { helper.makerequest(component, event); } })

linux - Python: Cannot import name/IndexError: List index out of range -

i'm still pretty new python, , didn't write of code, i'm trying work. have following 2 .py files: this 1 called fnsim.py- import numpy,sys, os import math def intfn(kvars,params): # not change name of function sinth = kvars['y']/(numpy.sqrt(kvars['y']**2+(1000.)**2)) = 4*((numpy.sin((numpy.pi*.7*sinth)/.0006)/((.7*sinth)/.0006))**2)*numpy.cos((numpy.pi*1.2*sinth)/.0006)**2 if not math.isnan(i): return else: print 'hello' return 0.0 ''' sinth = kvars['y']/(numpy.sqrt(kvars['y']**2+(params['r0'])**2)) a1 = numpy.complex(params['a1r'],params['a1i'])*numpy.e**(((-numpy.pi*params['p']*sinth)/.0006)*1j) a2 = numpy.complex(params['a2r'],params['a2i'])*numpy.e**(((numpy.pi*params['p']*sinth)/.0006)*1j) return (a1+a2)*numpy.conjugate(a1+a2) ''' def simfn(): """ function actual simulating. fill out filepaths below. "...