Posts

iphone - How to download and set a UIImage not on the main thread -

i'm adding image web service. how code it's not on main thread? want view load first , image load user doesn't experience slowness when detail view controller loads. what i'm unsure of how add dispatching code. here's code far: nsdata *imagedata = [nsdata datawithcontentsofurl:[nsurl urlwithstring:mainimageurl]]; uiimage *image = [[uiimage alloc] initwithdata:imagedata]; uiview *v = [[uiview alloc] initwithframe:cgrectmake(10, 150, 300, 180)]; uiimageview *iv = [[uiimageview alloc] initwithframe:cgrectmake(0, 10, 300, 180)]; [iv setimage:image]; [_scrollview addsubview:v]; [v addsubview:iv]; and i'm thinking can use threading: dispatch_async( dispatch_get_global_queue(dispatch_queue_priority_default, 0), ^{ // add code here background processing // // dispatch_async( dispatch_get_main_queue(), ^{ // add code here update ui/send notifications based on // results of background processing }); }); thanks help you can use gcd d...

arrays - 'Repa' performance for planetary simulation -

i have written simulation of outer planets of solar system using euler symplectic method , implemented a) using repa , b) using yarr . yarr seems perform x30 quicker repa . given this, didn't try use parallelism. there obvious performance problems in repa code? repository @ github . can produce cut-down repa -only version if helpful, won't performance comparison against yarr . alternatively, how debug performance issues in repa ? most euler numeric integration methods suffer cumulative round-off error cause simulation "blow up". may want investigate advanced numerical integration methods, such 4th-order runge-kutta or predictor-corrector. another place n-body problem simulations become sticky when 2 bodies close, such moon eccentric orbit planet. if 1 uses fixed time increments simulation, error during large changes of angular velocity can lead division-by-zero errors or division small values result in simulation blowing up. use of variable...

html - Set height of p-element as percentage of containing div -

i want set height of <p></p> tag. many suggest setting line-height or margin, won't suffice, want p-tag percentage of containig div. actually, want vertically distribute p-tags across height. if them same size, can vertical-align , display: table , display: table-cell <div> <p>foo<p> <p>bar<p> </div> i know number of <p></p> tags. <p height="int%">lala </p> that set height of line of text percentage of containg div believe if not <div height="int%" > <p> lalal </p> </div> set padding work. work. if want font stretched think need new font.

winapi - Calling Win32 DLL from C++ -

i new dll world. have been given win32 dll has lot of functions. need call these dll functions c++ i want call createnewscanner creates new scanner object , results in c++. function mentioned in dll is: bool createnewscanner(newscanner *newscan); and newscanner struct , below, // structure newscanner defined in "common.h" . typedef struct{ byte host_no; // <- host_no =0 long time; // <- command timeout (in seconds) byte status; // -> host adapter status handle obj; // -> object handle scanner }newscanner; how call function? started c++ , here managed, #include <iostream> #include <windows.h> using namespace std; int main(){ hinstance hinstance; if(!(hinstance=loadlibrary("winscanner.dll"))){ cout << "could not load library" << endl; } /* pointer function in dll*/ farproc handle = getprocaddress(hmodule(hinstance), "createnewscanner"); if(!handle){ // h...

file - Portable way to check if directory exists [Windows/Linux, C] -

i check if given directory exists. know how on windows: bool directoryexists(lpctstr szpath) { dword dwattrib = getfileattributes(szpath); return (dwattrib != invalid_file_attributes && (dwattrib & file_attribute_directory)); } and linux: dir* dir = opendir("mydir"); if (dir) { /* directory exists. */ closedir(dir); } else if (enoent == errno) { /* directory not exist. */ } else { /* opendir() failed other reason. */ } but need portable way of doing .. there way check if directory exists no matter os im using? maybe c standard library way? i know can use preprocessors directives , call functions on different oses thats not solution im asking for. i end this, @ least now: #include <sys/types.h> #include <sys/stat.h> #include <stdio.h> #include <stdlib.h> int direxists(const char *path) { struct stat info; if(stat( path, &info ) != 0) return 0; else if(info.st_mode ...

How to unbind mouseleave on click using jquery -

i have div when mouseenter previews image being shown - when mouseleave hides again. what i'm trying achieve when click div animates , shows, i'd unbind 'mouseleave' functionality image stays on screen isn't working - mouseleave still kicking in.... can help? here's code $('.attachment').on({ mouseenter: function (e) { tileid = (this.parentnode.id).substring(13); $('#imagecontainer-' + tileid).css('visibility', 'visible'); $('#imagecontainer-' + tileid).css('overflow-y', 'hidden'); $('#imagecontainer-' + tileid).stop().animate({ height: 40 }, { duration: 300, easing: animationeasing, queue: false }); }, mouseleave: function (e) { $('#imagecontainer-' + tileid).stop().animate({ height: 0 }, { duration: 300, easing: animation...

javascript - mering same geometry with different ambient colors -

i create custom geometry , use meshphongmaterial material. because geometry large, want merge them in 1 geometry better performance. problem want use different ambient color each child geometry. think can change color using more material , change materialindex each face, maybe not work , may costs lot of time , use more texture. there simple way archive this? i'm not sure how three.js render different material have no idea this.thanks help. the merge won't since materials stay different.