Posts

Featured post

mysql - Django database model for my website -

i building aviation website need store aircraft manufacturer, type , version of particular aircraft....boeing 777 300 example. here boeing manufact., 777 version , 300 model. model use is: class manufa(mod...): name=charfield .... manufact=models.foreignkey(manufact) type=models.foreignkey(type) version=models.foreignkey(version) this allows easy search problem every time have display item in search, have make 3 separate queries full name of aircraft form foreign key id....for search page 100 items...thats unimaginable number of queries.. if store these names if change version name or have edit each of rows...how solve can aircraft name same row...no second query.. you have read more of great django docs ;) https://docs.djangoproject.com/en/dev/ref/models/querysets/#select-related btw. should post full model definition

javascript - Will an object referenced within an object get garbage collected? -

var = { b: "this"; }; = null; when removing reference object literal 'a' referencing in beginning, reference "this" removed well, or cause memory leak? do have change code this: delete a.b; = null; ? this not cause memory leak. garbage collector typically works walking set of live references, marking set of objects finds , collecting didn't see. in case neither value assigned a or literal "this" found , both eligible collection

ios - How to run a segue on itself OR another viewController -

Image
i have main tableviewcontroller. when user tap on cell in tableview, if condition statement true, show main tableviewcontroller again(but show data on screen), , if condition false, show viewcontroller. in prepareforsegue method have this: if segue.identifier == "identifier1" { let destination = segue.destinationviewcontroller as? mainviewcontroller // destination!.x = // x variable in view controller } else if segue.identifier == "identifier2" { let destination = segue.destinationviewcontroller as? viewcontroller2 destination!.y = } also, run segue after tap on cells in tableview added this: override func tableview(tableview: uitableview, didselectrowatindexpath indexpath: nsindexpath) { tableview.deselectrowatindexpath(indexpath, animated: true) if condition true { self.performseguewithidentifier("identifier1", sender: self) } else{ self.performseguewithidentifier("identifier2", sender

python - How can I write on new lines in a text file while preserving old ones -

when open text file , write in , @ end of program close it, lines stay in text file. when reopen program, rather writing on new set of lines, overwrites there. want keep both pieces of text, data logging. ideas on how fix this. you should use a mode, this: with open("file","a") f: f.write("something") this append file instead of overwriting it.

c++ - SDL2 not recieving any events at all -

in sdl2 project, sdl_pollevents( sdl_event* e ) doesn't send events, , allways returns 0 , can't process events. event processing loop looks fine : sdl_event e; while( sdl_pollevent( &e ) > 0 ) { //this never reached ! printf( "recieved event %d\n", e.type ); switch(e.type) { case sdl_quit: quit = true; } } on other hand, compiles fine, drawing works, , i'm sure it's not stuck in infinite loop ( made print out message @ each frame ). i link against sdl2 , other dependencies, make gcc/g++ call sdl-config --cflags . how can fixed ? you shouldn't call sdl-config --cflags . sdl ( first version of library ), not sdl2 . somehow conflicts , stops events reaching sdl_pollevents() . remove , should work !

winforms - How to replace multiple texts in a file in c#? -

i automating process using c#. script below, update table set param_val = replace(param_val,'proxy430/','proxy440/') param_key = 'proxy_url'; update table set param_val = replace (param_val, '.420/', '.430/') param_val '%.420/%'; for every month, upgrade version 44 in place of 43 , 43 in place of 42 , run script. automate, i've written c# code , used below code string text = file.readalltext(filepath); text.replace(oldvale, newvalue); file.writealltext(filepath, text); but, issue can replace 1 word only. how replace 2 texts in file. in case, proxy430 should replaced proxy440 , proxy440 proxy450 in single shot. how achieve this? if call replace in right order can accomplish 2 replacements on single line. string teststring = @"update table set param_val = replace(param_val, 'proxy430/', 'proxy440/') param_key = 'proxy_url'; update table set param_v

c# - Rounding to 3 decimal places in a distance formula -

i have double need rounded 3 decimal places. i'm not sure how accurately implement math.round. have far: double distance= math.sqrt(deltax + deltay); math.round((decimal)distance, 3); console.writeline("distance :" + distance); use return value of math.round (already noted uwe keim ) , remove decimal cast. double distance = math.sqrt(10.438295 + 10.4384534295); console.writeline("distance :" + math.round(distance, 3));

sql - Query attributes, where one attribute is missing -

i have question regarding query. there 2 tables: objects table: ============== object id date 1 2016-03-15 2 2016-01-20 attributes table: ================= parent id attribute attributedata 1 size xl 2 size s 2 price 20 query join data this: ========================================== objet id size price 1 xl null 2 s 20 this: ========================================== objet id size price 2 s 20 a left join doesn't - because there no entry in attribute table price id1. i sorry beein such newbie on this. glad help. steffen i think conditional aggregation want: select parentid, max(case when attribute = 'size' attributedata end) size, max(case when attribute = 'price' attributedata end) price attributes group parentid; using left join do: select o.*, s.attributedata size, p.attributedata price objects o left join attributes s

java - Disabling broadcast in SimpMessageTemplate.sentToUser(...) in Spring 4.2.4 -

i trying connect in 2 sessions same spring security user , subscribe same queue using spring 4.2.4. separate messages each session. it's easy using @sendtouser , seems it's not trivial when using simpmessagingtemplate.sendtouser(...) - every session receives messages specific other session. example @sendtouser : @controller public class testcontroller { @messagemapping("/queue/hello") @sendtouser(value = "/queue/hello", broadcast = false) public string test() { return integer.tostring(new random().nextint()); } } example simpmessagingtemplate : template.convertandsendtouser("sessionuser{id=123}", "/queue/hello", "test"); i've tried adding sessionid in headers suggested example in thread: sending-error-message-in-spring-websockets unfortunately not in version of spring. have ideas? seems setting session id in headers still works, has simpsessionid, not sessionid. assumptions

Android Conflict with dependency appcompat -

i trying add espresso-contrib library project. here build.gradle file : apply plugin: 'com.android.application' android { compilesdkversion 23 buildtoolsversion "23.0.2" defaultconfig { applicationid "example.com.littlebox_hari" minsdkversion 19 targetsdkversion 23 versioncode 1 versionname "1.0" testinstrumentationrunner "android.support.test.runner.androidjunitrunner" } buildtypes { release { minifyenabled false proguardfiles getdefaultproguardfile('proguard-android.txt'), 'proguard-rules.pro' } } /*configurations.all { resolutionstrategy { force 'com.android.support:appcompat-v7:23.4.0' } }*/ } dependencies { compile filetree(dir: 'libs', include: ['*.jar']) testcompile 'junit:junit:4.12' compile 'com.android.support:

google maps - How to cluster latitude-longitude data based on fixed radius from centroid as the only constraint? -

Image
i have around 200k latitude & longitude data points. how can cluster them each clusters have latitude & longitude points strictly within radius = 1 km centroid only? i tried leadercluster algorithm/package in r eventhough specify radius =1 km not strictly enforcing i.e. give clusters lot of point 5 - 10 kms cluster centroid within same cluster. not meeting requirement. number of points in cluster can vary & not problem. is there way enforce strict radius constraint in heirarchical or clustering algorithm? looking steps & implementation in r/python. tried searching in stackoverflow couldn't find solution in r/python. how visualize cluster centroids in google maps after clustering in done? edit parameters using in elki. please verify this not clustering, set cover type of problem. @ least if looking good cover. clustering algorithm finding structure in data; looking forced quantization. anyway, here 2 strategies can try e.g. in elki: c