Posts

c# - Which numeric type conversion is better for simple math operation? -

i want know conversion better (regarding performance/speed , precision/most less loss) simple math operation , makes them different? example: double double1 = integer1 / (5 * integer2); var double2 = integer1 / (5.0 * integer2); var double3 = integer1 / (5d * integer2); var double4 = (double) integer1 / (5 * integer2); var double5 = integer1 / (double) (5 * integer2); var double6 = integer1 / ((double) 5 * integer2); var double7 = integer1 / (5 * (double) integer2); var double8 = convert.todouble(integer1 / (5 * integer2)); var double9 = integer1 / convert.todouble(5 * integer2); actually question conversion not type itself. edit in response totally changed question: the first line double double1 = integer1 / (5 * integer2); integer division, don't that. also line var double8 = convert.todouble(integer1 / (5 * integer2)); doing integer division before converting result double, don't either. other that, different approaches list end calling il instru...

c - Error "'strcpy' makes pointer from integer without a cast" -

struct phaseshiftpin { int _psppin_index; //psp = phase shift pin int _pspvalue; char _pspname[512]; }; struct phaseshiftpin *_phaseshiftpin[500000]; int p3int = 0; strcpy ( _phaseshiftpin[i]->_pspvalue, p3int ); the above code part of full code. when compiled full program happened error strcpy' makes pointer integer without cast @ line strcpy ( _phaseshiftpin[i]->_pspvalue, p3int ); i have referred post @ here makes pointer integer without cast strcpy after tried use strncpy , follow method showed in post still fail in compilation.hope can guide me problem.thanks. if @ definition of strcpy can see char *strcpy(char *dest, const char *src); but _phaseshiftpin[i]->_pspvalue integer , p3int also. you can use memcpy void *memcpy(void *dest, const void *src, size_t n); strcpy ( &(_phaseshiftpin[i]->_pspvalue), &(p3int), sizeof(p3int) ); or said in comment _phaseshiftpin[i]->_pspvalue = p3int; if try copy p3i...

javascript - Running CSS keyframes on click -

i'm trying have message appear when button clicked. want have "go!" fade in/out signify start of game when start button clicked. i'm trying javascript @ moment using jquery , library teacher gives combination of on mouse click , on screen tap 'ontap' lter use mobiles. i have set add animation class when button clicked animation won't play, if add animation class beginning animation plays not when button clicked. went wrong adding javascript , how can achieve basic click button , text fades in/out? <script type="text/javascript"> $(document).ready(function() { $("#addfrogbut").ontap(function() { $("#gotext").addclass(".goanim"); }); }); </script> <head> #addfrogbut { position: fixed; bottom: 20px; font-family: fantasy; font-size: 32px; left: 20px; text-transform: uppercase; text-shadow: -1px 0 white, 0 1px white, 1px 0 white, 0 -1px white; padding: 2px 18px; backgro...

java - org.hibernate.util.JDBCExceptionReporter] Duplicate entry X for key 'PRIMARY' -

i writing back-end java code active-mq in producer consumer model. when multiple consumers runs using , try update in table question following exception occured , transaction rollbacked. multiple threads running inside each consumer task. warn [org.hibernate.util.jdbcexceptionreporter] sql error: 1062, sqlstate: 23000 07:10:31,609 error [org.hibernate.util.jdbcexceptionreporter] duplicate entry '69-947' key 'primary' 07:10:31,615 error [com.xminds.bestfriend.consumers.questiongeneration] exception failed question generation org.springframework.dao.dataintegrityviolationexception: not insert: [com.xminds.bestfriend.frontend.model.friendship]; any 1 can suggest solution this. i think trying insert record using existing primary key. make sure primary key unique.

c# - Apply Where conditionally (OR between them) LINQ -

i have filters in asp.net project , want add expression list condition: expression<func<mymodel, bool>> func; var list = new list<expression<func<mymodel, bool>>>(); i want conditionally apply (or between them). example: if(sth){ func = p => p.a <= b; list.add(func); } if (sth else){ func = p => p.c >= d; list.add(func); } var fq = session.query<mymodel>(); fq = list.aggregate(fq, (current, expression) => current.where(expression)); how can this? looks extension method public static class enumerableextensions { public static ienumerable<t> conditionalwhere<t>(this ienumerable<t> list, bool condition, func<t,bool> predicate) { if(!condition) return list; return list.where(predicate); } } usage be: var fq = session.query<mymodel>(); var result = fq.conditionalwhere(sth, p => p.a...

How to enable php run python script on GPU? -

in php website, call python script using theano , running on gpu. however, when calling python script php, seems apache doesn't have permissions on gpu program falls on cpu, far less efficient compared gpu. how can grant apache rights run programs on gpu? i split up, save requirement event in storage (redis example or rabbitmq) , listen daemonized script (cron bad joice since hard make run more every minute). script update storage entry results , can access again in http stack. can implement functionallity via ajax or utilize usleep command in php wait results. if using while loop, dont forget break after 1 second or something, request not running long. your problem might configured user, executes php binary - maybe not permitted access binaries on system. typically www-data user. adding www-data user necessary group, might able solve without splitting up. have @ binary's ownerships , permissions figure out.

PHP / HTML - Load image from outside root folder -

i trying load in image in <img> tag within html. images folder in same folder root folder, meaning need go 1 folder access images folder. i looked around internet , found method using requests within src attribute image, unfortunately without success. folder structure: img > somefile.png foo.png bar.png html > index.php imagerequest.php //other root files i cannot use following: <img src="../img/somefile.png"> because points towards non existant (duh!). attempted use request. my html <div> <img src="imagerequest.php?requested=somefile.png"> </div> my php (imagerequest.php) $filename = $_get['requested']; fetchimage(); function fetchimage(){ global $filename; if(!isset($filename)) return; $filepath = dirname($_server['document_root'])."/img/".$filename; if(file_exists($filepath)){ readfile($filepath); ...