Posts

rust - How to partition Vec in place in method that doesn't own `self`? -

so, there's struct looks this: struct foo { alpha: vec<t>, beta: vec<t>, } and method should move values matches condition alpha beta . question is: clean way without owning self ? the vec::partition() method can't used because moving of self.alpha causes cannot move out of dereference of &mut-pointer compile error. ps: t have file inside doesn't implement clone . do want drop beta ? sort of thing std::mem::replace for, allowing pull out: use std::mem; impl foo { fn munge(&mut self) { let alpha = mem::replace(&mut self.alpha, vec::new()); let (alpha, beta) = alpha.partition(…); self.alpha = alpha; self.beta = beta; } } note there is new vec created there briefly, doesn’t matter; doesn’t involve allocation , cheap. (the alternative leaving uninitialised memory there , replacing again, forgetting uninitialised memory, unsafe if partition can fail run destructor on uninit...

android - Check if Spell Checker is on? -

i using spell checker in android app. if is off in language , input settings app crashes. needs on app work properly. is there way before using can place check verify spell checker on or turn on directly code? you can check instance of spellcheckersession null , accordingly decide whether spellchecker turned on or not: code snippet: final textservicesmanager tsm = (textservicesmanager) getsystemservice(context.text_services_manager_service); scs = tsm.newspellcheckersession(null, null, this, true); if (scs != null) { scs.getsuggestions(new textinfo(text.gettext().tostring()), 3); } else { // show message user toast.maketext(this, "please turn on spell checker setting", toast.length_long).show(); // can open settings page user turn on componentname componenttolaunch = new componentname("com.android.settings", "com.android.settings.settings$spellcheckerssettingsactivity"); intent intent = new in...

java - Project Tango: Export ADF to sdcard -

i'm trying export adf project tango sdcard use code sample docs , failing me. i'm able export dialog pop-up proper export path. when hit export button, failure in log 12-16 00:48:12.203 192-603/? e/tango_service_library_context﹕ bool runtimeexportareadescription(const string&, const string&, const string&): internal error occured opening file: /storage/emulated/0/c5617dae-01b0-4825-8ee1-777c17693414 12-16 00:48:12.209 8246-8246/? e/androidruntime﹕ fatal exception: main process: com.projecttango.tango, pid: 8246 com.google.atap.tangoservice.tangoinvalidexception @ com.google.atap.tango.tangointernal.throwtangoexceptionifneeded(tangointernal.java:118) @ com.google.atap.tango.tangointernal.exportareadescriptionfile(tangointernal.java:104) @ com.google.atap.tango.requestimportexportactivity.onexportaccepted(requestimportexportactivity.java:83) @ com.google.atap.tango.requestimportexportdialog$1.onclick(requestimportexportdia...

Class with Spring @Conditional is not weaved with AspectJ -

i want load spring 4.0 resources conditionally, below code can job ( how achieve conditional resource import in spring xml context? ): @configuration @conditional(myconditionalconfiguration.condition) @importresource("/com/example/context-fragment.xml") public class myconditionalconfiguration { static class condition implements configurationcondition { @override public configurationphase getconfigurationphase() { return configurationphase.parse_configuration; } @override public boolean matches(conditioncontext context, annotatedtypemetadata metadata) { // load context-fragment.xml if system property defined return system.getproperty("com.example.context-fragment") != null; } } } how ever code can not weaved aspectj, problem supposed @conditional the trace is org.aspectj.weaver.bcexception @ org.aspectj.ajdt.internal.core.builder.ajstate.recordclassfile(a...

android - How to remove ems from TextView programatically? -

having textview in layout xml ems width 8, <textview android:id="@+id/more" android:ems="8" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@color/popup_grey" android:drawableleft="@drawable/dot_small" android:text="@string/get_more" /> i need remove ems textview dynamically on condition. tried view.setems(0) , shrinks textview width 0 . is there piece of code remove it? thanks in advance. you can try this: view.setems(0) @ sametime put width of textview match_parent? way won't shrink textview hope helps gud luck

python - With Bottle, how could I just peek the head of http request instead of receiving whole http request? -

i don't know if possible bottle. website (powered bottle) allow users upload image files. limited size of 100k. use following code in web server that. uploadlimit = 100 # 100k uploadlimitinbyte = uploadlimit* 2**10 print("before call request.headers.get('content-length')") contentlen = request.headers.get('content-length') if contentlen: contentlen = int(contentlen) if contentlen > uploadlimitinbyte: return httpresponse('upload limit 100k') but when clicked upload button in web browser upload file size 2mb, seems server receiving whole 2mb http request. expect above code receive http headers instead of receiving whole http request. not prevent wasting time on receving unecessary bytes

Why the need of java unicode when decimal representation is there? -

package test; public class test { public static void main(string[] args) { char b=65; char b='\u0041'; //aren't these same? } } probably because native character set java programming language unicode , english not language in world. programs written using unicode character set. © jls §3.1 in compiled java program char b = 65 , char b = '\u0041' produce absolutely equivalent bytecode. unicode escape sequence (\uxxxx) can used anywhere in source code, not in string or character literal definition, while number representation not. short example: public class helloworld { public static void \u006d\u0061\u0069\u006e(string[] args) { system.out.println("hello, world!"); } } this absolutely correct "hello world" program main(string[] args) method. further reading: jls §3.2