Posts

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...

Python 2 to 3 conversion: iterating over lines in subprocess stdout -

i have following python 2 example code want make compatible python 3: call = 'for in {1..5}; sleep 1; echo "hello $i"; done' p = subprocess.popen(call, stdout=subprocess.pipe, shell=true) line in iter(p.stdout.readline, ''): print(line, end='') this works in python 2 in python 3 p.stdout not allow me specify encoding , reading return byte strings, rather unicode, comparison '' return false , iter won't stop. this issue seems imply in python 3.6 there'll way define encoding. for now, have changed iter call stop when finds empty bytes string iter(p.stdout.readline, b'') , seems work in 2 , 3. questions are: safe in both 2 , 3? there better way of ensuring compatibility? note: i'm not using for line in p.stdout: because need each line printed it's generated , according this answer p.stdout has large buffer. you can add unversal_newlines=true . p = subprocess.popen(call, stdout=subprocess.p...

ms access - sql query return the rows without common attributes -

i'm new sql ans ms-access. so, have table tab1, columns id, decscription, number want make query returns id of rows without common description , number. desirable output this i have tried select id tab1 group id, description, number having count(*)=1; but returns logical error. if want return rows unique, can do: select * tab1 not exists (select 1 tab1 t tab1.description = t.description , tab1.number = t.number , tab1.id <> t.id ); you can using aggregation. id : select max(id) tab1 group description, number having min(id) = max(id);

javascript - Mimicking old Gmail compose window with addon or userscript? -

gmail has forced users use crappy compose. links: official notice thenextweb comments mark shields comments there must way mimic old compose, either addon or userscript. know how create one?

wpf - C# MVVM: Binding a RadioButton to a boolean Property -

i quiet new programming , learning c# , mvvm pattern. i need code database tool chiliplants university. there should able add new object observablecollection. to add new item observablecollection new window opens. looks this: window add i want 2 radioboxes bound property called "hybridseed". defined in viewmodel: //public property hybridseed public bool hybridseed { { return chilimodel.hybridseed; } set { if (chilimodel.hybridseed == value) return; chilimodel.hybridseed = value; onpropertychanged("hybridseed"); } } the radiobox part of view looks this: <radiobutton grid.row="5" content="ja" grid.column="1" horizontalalignment="left" margin="10,10,0,0" verticalalignment="top"/> <radiobutton grid.row="5" content="nein" grid.column="1" horizontalalignment=...

c# - Test to ensure the user input is a double and is greater than zero? -

in c# trying have user input number. want check that they have entered string can converted double and they have entered value greater zero the method have created string invalue; double outcome; console.writeline("enter amount: "); invalue = console.readline(); while (double.tryparse(invalue, out outcome) == false) { console.writeline("initial value must of type double"); console.writeline("\nplease enter number again: "); invalue = console.readline(); } outcome = double.parse(invalue); while (outcome < 0) { console.writeline("initial value must of @ least value of zero"); console.writeline("\nplease enter number again: "); invalue = console.readline(); outcome = double.parse(invalue); } return outcome; the problem if user entered "-10" , "f" exception occur. because program move past first check (that checks double) value of -10 when "f" entered throws except...

soap - python suds UsernameToken -

code: security = security() token = usernametoken('b77a5c561934e089', 'kmfhknzyn1u/pgaiy3+h0bohdki=') security.tokens.append(token) client.set_options(wsse=security) my problem one: when including usernametoken, receive kind of header: <soap-env:header> <wsse:security mustunderstand="true"> <wsse:usernametoken> <wsse:username>b77a5c561934e089</wsse:username> <wsse:password>kmfhknzyn1u/pgaiy3+h0bohdki=</wsse:password> </wsse:usernametoken> </wsse:security> </soap-env:header> but need response requirement on web service: <sp:signedsupportingtokens xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy"> <wsp:policy> <sp:usernametoken sp:includetoken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/includetoken/alwaystorecipient"> <wsp:policy> <sp:wssus...

javascript - I am taking user input and splitting it - how to best check types for each and also remove spaces? -

i'm not sure if there's better way this. basically, taking user inputs example - hair salon, 1, 4 when split , ['hair salon',' 1',' 4'] . doing error check make sure 3 values passed max, how can remove spaces ( ' 4' ) , check 'hair salon' string, , other 2 numbers? thanks suppose have user input hair salon, 1, 4 now split(','), array var arr = ['hair salon', '1','4'] you every input string for(i=0;i<arr.length;i++) { arr[i] = arr[i].trim() // remove space & front } in case needed data type of inputs, can check using typeof (arr[i])) - in loop hope, suffice need

AngularJS + OAuth -

i'm trying write login solution angular app, means allow user connect via facebok/google/twitter or register normally. found angular-oauth useful, didn't seem work facebook (or twitter). anyone knows of all-inclusive solution this? take @ oauth.io easy implementation in javascript 80+ oauth providers fast & secure

mysql - Exception "Parameter index out of range (1 > number of parameters, which is 0)." -

query="insert paint_inventory(id,name,type,gallons,quarters) values(?,?,?,?,?)"; con.preparestatement(query); pstm.setint(1,integer.parseint(itemid_newitem_field.gettext())); pstm.setstring(2,name_newitem_field.gettext()); pstm.setstring(3,type_newitem_field.gettext()); pstm.setint(4,integer.parseint(gallons_quantity_newitem_field.gettext())); pstm.setint(5,integer.parseint(quarters_quantity_newitem_field.gettext())); pstm.execute(); joptionpane.showmessagedialog(rootpane,"item has been registered"); pstm defined in code? hope need assign preparestatement pstm can set parameter values. also ensure pstm not used preparestatement in same method or other methods. each preparestatement should have separate variable name set parameter values. query="insert paint_inventory(id,name,type,gallons,quarters) values(?,?,?,?,?)"; pstm = con.preparestatement(query); -- assign pstm set values ... ...