Posts

Showing posts from March, 2015

How to scroll an android listview, with 2 items -

hi i'm using following circular list view has 3 items not fill_parent, how force scrolling last item ends @ bottom of screen , first item in middle , on. have tried capture de event by @override public boolean onintercepttouchevent(motionevent ev) { return super.onintercepttouchevent(ev); } but not work thank best regards

Swift: Converting a string into a variable name -

i have variables incremented numbers within, such row0text, row1text, row2text, etc. i've figured out how dynamically create string versions of variable names, once have strings, how can use them actual variable names rather strings in code? example: var row3text = "this value need!" var firstpart = "row" var rownumber = 3 var secondpart = "text" var = (firstpart+string(rownumber)+secondpart) // below gives me concatenated string of 3 variables, i'm looking way have return value set @ top. println (together) once know how this, i'll able iterate through variables using loop; it's @ moment i'm unsure of how use string variable name in code. thanks! short answer: there no way for reason . use arrays instead. long answer: looking way define unknown number of variables linked common format. looking define ordered set of elements of variable length. why not use array? arrays containers allow store ordered set

flex itemrenderer prevents datagrid item select -

i'm new flex , have encountered problem itemrenderer can't find solution to. i've asked coworker plenty of flex experience, , i've tried searching internet no luck. problem have datagrid in each column uses itemrenderer display information, , reason causes user unable select of datagrid rows. think must have itemrenderer, because when added dummy column without itemrenderer, able highlight , select row clicking on dummy column, others still did not work. i've tried comparing code code other datagrids itemrenderers work, haven't been able find differences cause problem mine giving me. know why happen? thank you! my datagrid (i tried include think should relevant keep things concise. if thinks more information needed, please let me know!): <mx:datagrid id="servicegridui" left="10" right="10" top="10" bottom="85" selectable="true" stylename="formdatagrid" varia

google app engine - How to manually delete local gcloud Dart DB? -

i running simple code db.query(sampletype).run().tolist(); and getting error. when query types don't error, other do. seems i've populated db , updated types , query won't decode. haven't tried using filter, if use lookup known entity work, using command erase sampletype s db, stuck undesired damaged entities. how manually erase db? starters, local db reside? here actuall error bad state: error while decoding entity (illegal argument(s): type argument must not null., #0 key.key (package:gcloud/src/db/models.dart:22:7) #1 key.append (package:gcloud/src/db/models.dart:55:16) #2 modeldbimpl.fromdatastorekey (package:gcloud/src/db/model_db_impl.dart:65:23) #3 modelkeyproperty.decodeprimitivevalue (package:gcloud/src/db/annotations.dart:179:31) #4 listproperty.decodeprimitivevalue (package:gcloud/src/db/annotations.dart:268:65) #5 _modeldescription._decodeproperty (package:gcloud/src/db/model_db_impl.dart:427:42) #6 _modeldesc

excel - Max of DateTime (custom) field not recognized in PivotTable -

Image
i have simple raw data format of column lastusagetime custom (yyyy-mm-dd hh:mm:ss): and pivottable: . the lastusagetime column max function (i want display dates, not count them). problem excel doesn't understand custom datetime format of raw data lastusagetime reason. puts 1900-01-00 everywhere. however, if copy text of lastusagetime , paste notepad, copy/paste excel, works fine! however, raw data sourced external xml file, when click refresh, gets messed again. how can fix this? i think need convert raw data lastusagetime string date/time value (as excel coercion copy/paste). perhaps: =datevalue(e2)+timevalue(e2)

Git Error. When I run my code I get errors that shouldn't be there -

spontaneously when started working on project earlier today function working fine earlier failed. curious because last time working on it, working fine. all left revert earlier stage of project in know fact function working. i reverted several previous stages , function still not functioning. other people when cloned work found functioning fine. when try access it doesn't work. the lead have git not functioning earlier. think file corrupted , fixed resetting working repository , copying on work. everything seemed fine after fix.my function working when pushed github. other people when cloned work found functioning fine the first workaround check clone repo in new location, , see if corruption persists there.

javascript - Android webview wont consistently open to last-scroll location -

i have android app uses kitkat-level webview display documents (primarily e-reader consumes html files). when user opens document within app (and webview newly instantiated document) want scroll last known cursor location within document, user can pick reading left off. retain , persist cursor location indepedently of webview allow such scrolling when first open document. problem: when document first opens, can see initial highlighting of last known location (cursor) in javascript document, in perhaps 50% of cases i've seen document somehow scrolls top , cursor location no longer shown. how , why scrolls top in these cases mystery me (i dont believe programatically make scroll top in way). notes: achieve scrolling within webview i'm using javascript function invoked webview fragment (via webview.loadurl) once webview has signalled has loaded , ready use. callback document view fragment webview: @targetapi(build.version_codes.kitkat) @suppresslint("clickablev

ruby - Custom Matcher for "calls method on object" -

given method like: class myclass def method_that_calls_stuff method2("some value") end end i'd define expectation like: my_object = myclass.new expect{ my_object.method_that_calls_stuff }.to call(:method2).on(my_object).with("some value") i know can achieve same thing using rspec-mocks , don't syntax well. how define matcher (or better, has written one)? with new syntax though can get instance = myclass.new expect(instance).to receive(:method2).with("some value") instance.method_that_calls_stuff but if want matcher, can do rspec::matchers.define(:call) |method| match |actual| expectation = expect(@obj).to receive(method) if @args expectation.with(@args) end actual.call true end chain(:on) |obj| @obj = obj end chain(:with) |args| @args = args end def supports_block_expectations? true end end notice with optional may want call method without args. you

.net - C# How to open a FolderBrowserDialog in the middle of the code? -

i trying use folderbrowserdialog mentioned here: var dialog = new system.windows.forms.folderbrowserdialog(); system.windows.forms.dialogresult result = dialog.showdialog(); if call dialog when button pressed, works fine. want open dialog in middle of code (there incoming file through socket, between receiving , saving try path save to), , won't happen. here part of code called: byte[] clientdata = new byte[1024 * 5000]; int receivedbyteslen = clientsocket.receive(clientdata); var dialog = new system.windows.forms.folderbrowserdialog(); system.windows.forms.dialogresult result = dialog.showdialog(); string filepath = dialog.selectedpath; int filenamelen = bitconverter.toint32(clientdata, 0); string filename = encoding.ascii.getstring(clientdata, 4, filenamelen); binarywriter bwrite = new binarywriter(file.open(filepath + "/" + filename, filemode.append)); ; bwrite.write(clientdata, 4 + filenamelen, receivedbyteslen - 4 - filenamelen); bwrite.close(

excel - How are `IF` and `AND` statements evaluated in VBA? -

this question has answer here: does vba “and” operator evaluate second argument when first false? 6 answers excel vba boolean expression - order of operations 1 answer in java or c#, and statements evaluated left right. if first condition not true, second condition not evaluated. useful if second condition cause java.lang.arrayindexoutofboundsexception . i have similar case in excel-vba application. have if statement such: if condition1 = false , cellelement - 1 <> "" then ... it throws vba - run time error 1004 'application defined or object defined error' , if condition1 false. my question is, vba evaluate second condition in , statement, if first condition false? my current work around ugly, works: dim b boolean if condition1 = false

java - Why doesn't my error check work? -

what did made error check loops through everytime invalid filename entered user: public static scanner readfile(string filename){ scanner stdin = new scanner(system.in); file input = new file(filename); scanner sc = null; { try { sc = new scanner(input); } catch(filenotfoundexception e) { system.out.println("filename not valid. please try again:"); filename = stdin.nextline(); } } while (!new file(filename).exists()); return sc; } i have enough method reads file , puts data array: public static co2data[] readdata(string filename){ file input = new file(filename); scanner sc = null; try{ sc = new scanner(input); } catch(filenotfoundexception e){ system.out.println("filename not valid"); system.exit(-1); } string info = sc.nextline(); int total = sc.nextint(); co2data[] arr = new co2data[total]; for(int i=0; i<10;i++

Regex validation for ZIP codes for each state -

i'm quite new regex , trying write regular expression matches zip codes in each state, having hard time. example, alaska has zip codes between 99501 , 99950, doesn't work: 99(5|6|7|8|9)(0|1|2|3|4|5|6|7|8|9)(0|1|2|3|4|5|6|7|8|9) because matches 99951. done already, or mind helping me out @ least pattern this? here zip code ranges each state: http://www.structnet.com/instructions/zip_min_max_by_state.html regexp poor choice problem think 1 might job done: 99(5(0[1-9]|[1-9]\d)|[6-8]\d\d|9([0-4]\d|50)) http://rubular.com/r/fs9btpggtt

javascript - How copy mains file to specific folder with Grunt -

my .bowerrc this: { "directory": "components", "strict-ssl": true } in bower.json have: "dependencies": { "jquery": "~2.1.1", "bootstrap": "~3.3.1" } when run bower install , downloads jquery , bootstrap components folder. i'm trying using grunt generate structure below, but, i'm not find plugin this. build / js/jquery.min.js js/bootstrap.min.js css/bootstrap.min.css fonts/glyphicons-halflings-regular.eot fonts/glyphicons-halflings-regular.svg fonts/glyphicons-halflings-regular.ttf fonts/glyphicons-halflings-regular.woff after copy these files, want zip (i know how step) content inside build folder. you can use grunt-bower-taks achieve this. task take care of downloading files using bower , placing them in structure require. need specify custom layout match folder structure require. done adding custom layout function p

how can I get same random number after restart application in c# -

i same random number after restart code. İs possible because system clock changing while restart application. 1-start application 2-result of random number( example array size 10 , every numbers same) 3-close application 4-don't change code 5-start application again 6-result of random number( example array size 10 , every numbers same) in second , sixth step ı same number? how can ı it. possible?

c# - Why did Membership.GetUser().Email return the wrong value? -

i have mvc web application form posted ajax controller method starts out this: [handleerror] [acceptverbs(httpverbs.post)] [authorize] public jsonresult formsubmitmethod (formcollection formcol) { membershipuser myobject = membership.getuser(); guid currentuserid = (guid)myobject.provideruserkey; // correct guid string emailaddress = myobject.email; // incorrect email returned 1 time ...and on i use guid provideruserkey data user , perform of regular updates etc. email address returned myobject.email used recipient address in confirmation email sent @ successful conclusion of regular transaction processing in controller method. i understand perhaps should instead doing: membershipuser myobject = membership.getuser(user.identity.name); and maybe problem. this code has been running in production couple of years no reported problems , thousands of successful email confirmations sent. there no recent changes code. this week had report received emai

html - Why is my body wider then the content? -

i out of ideas... can't post images yet, sorry. so, making site , reason body keeps being wider content. can't seem find reason. when check in chrome dome doesn't marked actual body. html { height:100%; width:100%; } body { background: black; margin:0; padding:0; position: relative; height: auto; min-height: 100% !important; font-size: 95%; display:block; width: 100%; overflow:auto; } .nav { background: #6192ec; height: 50px; width: 100%; text-align: center; } .nav nav{ width: 100%; line-height: 2.2; margin: 0 auto; margin-left: 4%; vertical-align: top; display: inline-block; } .nav nav { font-family: oxygen; font-size: 140%; list-style: none; color: #283040; text-decoration: none; padding: 0 60px 0 0; } .nav ul { position: relative; display: inline; padding: 0; } .nav nav ul li { display: inline-block; } this entire code. if find anything...

ios - After renaming project i get <XCTest/XCTest.h> not found. -

Image
i first duplicated project before renamed it. after rename i'm getting lexical or preprocessor issue <xctest/xctest.h> not found. the error directs me myapptests.m file calls #import <xctest/xctest.h> also next line @interface spyshottests : xctestcase the "xctestcase" not hi-lighted in purple. any tutorial i've seen has directed me framework search paths in build settings - framework search path same initial file , file builds no issues. i came across similar , i'm wondering if solution might helpful. you may want check file throwing error included in appropriate target source's "compile sources". it's possible file might not have been included. in case had been included project target , not test target. since xctest accessible test target, wouldn't compile me generating error "xctest/xctest.h file not found". project targets >> build phases >> compile sources: you can fix

java - Swing: Add help [?] button to window titlebar -

Image
i want add new button icon of question mark left of buttons "maximize", "hide" , "close". how make (like in pic)? you need create custom rootpane/titlebar. this means need set jframe undecorated , set custom instance of extends rootpane jframe

HTTP server in Java with long time reposnse -

i want write http server long time response. prepared loop: serversocketchannel = serversocketchannel.open(); serversocketchannel.socket().bind(new inetsocketaddress(inetaddress.getbyname("127.0.0.1"), 8000)); while (serversocketchannel.isopen()) { try { system.out.println("waiting..."); socketchannel socketchannel = serversocketchannel.accept(); system.out.println("the new connection open ;)"); } catch (ioexception ex) { system.out.println(ex.getmessage()); logger.getlogger(serverhttp.class.getname()).log(level.severe, null, ex); } } i want catch new connection user's browser, put list, , thread take , parse it. have problem on beginning: code above freezing in method serversocketchannel.accept() . when add socketchannel.close() working correctly, don't want close connection in place, because need long time response. look @ java

java - Two JFrame (A, B) -

i have 2 jframe , a , b . a main jframe, b secondary , invoked via button. wish call b, no longer clickable until end of operations b (b must remain above until end). how should do? just quick draft: add buttons frames , b (for example "done"-button both) , add actionlisteners buttons (to hide current frame , show other frame example and/or process actions made) set frame's visibility (in case a) false if should "no longer clickable" (again actionlisteners) , visibility of b true. if you're done b click "done" button of b , set visibility of b false , visibility of true.

c++ - How can I transform a user-defined string into an integer -

i ask user input string, let's input "abc" or"def" then, want set integer = 1 if abc entered , 2 if def entered. if else entered, want invalid value. so @ end, i'll have integer assigned 1 or 2 if valid value entered. #include<iostream> #include<string> #include<sstream> using namespace std; int main() { string input = ""; // how string/sentence spaces cout << "please enter valid sentence (with spaces):\n>"; getline(cin, input); cout << ".\n" << "you entered: " << input << endl << endl; int m if(input = abc) return 0; } #include <iostream> #include <map> #include <string> #include <initializer_list> using namespace std; int main() { const std::map<std::string, int> lookuptable = { {"abc", 1}, {"def", 2} }; string input = ""; int m; while(true) {

mysql - Creating a php file for translating the content dynamically -

Image
i have database has around 700 terms. write single php file called internationalize check mysql database , return proper translation. php variables have been setup , there view contains translation of languages. there 11 languages. have looked in lot of places, there isn't 1 fits situation. suggestions appreciated. if (!isset($_session)) { session_start(); } if (isset($setup)) { $lang=$_session['setuplang']; } elseif (isset($_session['lang'])) { $lang=$_session['lang']; } else { require("fetchmainconfig.php"); } $lang_code = $lang; //file_dir contains language codes example: il,fr,pt,ge , on $sql = "select file_dir `hydroserver_translation`.`language_file_dir`"; if($lang_code = $sql){ // should go in here??? best way // dynamically translate database? } i attaching copy of database view. plan write code such way if there no language translation default translation in english. this have done , work

Assistance needed Understanding Android fragment addition during onCreate -

i need cleaning information doesn't make sense me, use cases if possible. what understand: with fragments in android, understand if plan on replacing them need have container view, preferably framelayout, , add initial fragment container during activities oncreate method. there 1 thing continues not make sense me. what don't understand , need with: what rules there regarding where/how container view set up, if there any. android developers site makes container view needs it's own xml layout file, doesn't , have seen examples on here framelayouts nested inside of typical layout files, specific uses , need understand rules of setting container up. there no rules. need viewgroup -- position , size want. when add fragment it, behave if you'd created fragment 's view manually, , called yourviewgroup.addview(fragmentview) . framelayout typically used because makes container no real behavior (you give size , position , let fragment fill con

return statement not returning control to caller in java -

i trying practice binary trees in java , tried write "ispresent" function. function isn't working if argument ( testint ) isn't root node value. entering infinite loop. i'm missing silly thing i'm sure. public class node { // attributes int value; node leftchild; node rightchild; // constructor node (int value) { this.value = value; } // getter int getvalue() { return value; } boolean ispresent(int testint) { node presentnode = this; while (presentnode != null) { if (presentnode.getvalue() == testint) { return true; } else if (testint < presentnode.getvalue()) { presentnode.leftchild.ispresent(testint); } else { presentnode.rightchild.ispresent(testint); } } return false; } } public static void main(string args[]) { int[] integers = new int[size]; arr

Enum or a properties file for URLs? -

i looking suggestions on best practice declaring urls. property files or enum? edit : use java programming language. use hardwired constants in java code when don't want users / deployers / testers / tests changing them. use properties file when want possibility. the point changing hard-wired constant in application's source code entails editing source code, rebuilding , redeploying. contrast, changing properties file may simple firing notepad. constants - when don't mind re-compiling application each time change value. sort of irony here. why change if has been called constant :) properties file - when want luxury of changing value , maybe restarting application pick change.

What happens if you interrupt a Git push? -

i ran following command: git push -u origin master the "push" big, many files, taking time upload. halfway through noticed forgot add couple of files. did "ctrl + c" in terminal (interrupting git), , after doing git add . , committed again, , pushed again. will git know first 1 didn't go through ? takes long time push (so can't test easily. have wait push finish take while). edit: hooray! nothing seems have gone terribly wrong. did push again, , works. :{ the upstream git repository oblivious attempted push, , no change occur upstream. unfortunately however, doesn't half-pushed files, doesn't store , expect continuation of push later on either. it's either push or don't push, there no try;)

c# - Error while accessing array -

i'm getting error wrong number of indices inside []; expected 2 near bottom of code. i'm not sure why. i'm trying build set of arrays manipulate i'm getting hung @ point. public static void main (string[] args) { initialize (); while (true) { systemevents.checkevents (); update (); render (); } } public static void initialize () { // set graphics system graphics = new graphicscontext (); gen = new random (); texture2d ptex= new texture2d("application/assets/plane.png",false); player= new sprite(graphics,ptex); player.position.x = graphics.screen.rectangle.width / 2 - player.width / 2; player.position.y = graphics.screen.rectangle.height / 2 - player.height / 2; xpos = 0; ypos = 0; pieces = new texture2d[6]; bg = new sprite[9,12]; pattern = new int[9,12]; (int i=0; i<6; i++) pieces [i] = new texture2d ("application/assets/island"

java - Extending HandlerThread and when to call getLooper() -

i have simple activity button on it. upon button's onclick method, want run code in thread, getting handlerthread's looper object , posting runnable handler associated it. objective call thread's method thread (and run own thread) using handlers (probably bad idea, wanted learn instead of abusing static methods) decided extend handlerthread. new class not much. public class epicthread extends handlerthread { public epicthread(string name) { super(name); } } the activity not either. did testing. public class mainactivity extends activity { epicthread et; looper l; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); epicthread et = new epicthread("the epic thread"); et.start(); } public void click(view v) { l = et.getlooper(); handler h = new handler(l); h.post(new runnab

python - Parsing with multiple identifiers -

i trying implement block of code generator not working split string particular identifier . python 2 found 2 bugs in can’t seem fix. input: @m120204 ctct + ~@@! @this_one_has_an_at_sign ctctct + @jfik9 @thisoneisempty + #empty line after + , empty line end file (2 empty lines) the 2 bugs are: (i) when there @ starts line of code after ‘+’ line such 2nd entry (@this_one_has_an_at_sign) (ii) when there line following @identification_line or line following ‘+’ lines empty in 3rd entry (@thisoneisempty) i output same post referenced: yield (name, body, extra) in case of @this_one_has_an_at_sign name= this_one_has_an_at_sign body= ctctct quality= @jfik9 in case of @thisoneisempty name= thisoneisempty body= '' quality= '' i tried using flags can’t seem fix issue. know how without using generator i’m going using big files don’t want go down path. current code is: def organize(input_file): name = none body = '' = '&#

c++ - QT Widget using OpenCV error deploying to Android -

this question has answer here: how integrate opencv qt creator android project 1 answer i create qt widget (c++) , use opencv library (c++) , deploy android. i have installed qt android , necessary files mentioned in http://qt-project.org/doc/qt-5/androidgs.html such ndk,sdk etc. mingw compiler included in qt android didnt have install again. i have no problem deploying qt widget android. problem using opencv library in qt widget , deploying it. i have tried 2 options use opencv in qt project: as qt android comes mingw compiler have compiled opencv library source using cmake , mingw compiler. have included header files , linked libraries in project file of qt . option not work . used method of including , use other libraries such boost , eigen in same way. i have downloaded opencv android sdk , included it's header files , linked it's libraries in

javascript - Calculate normal vector of a polygon - Newells Method -

i'm trying calculate surface normal of 2d polygon. using newell's method opengl wiki calculate surface normal. https://www.opengl.org/wiki/calculating_a_surface_normal understanding normal should in y direction returns [0, 0, 0]. y value gets changed -1 on second iteration , 0 on fourth iteration. p = [[0, 0, 0] [1, 0, 0] [0, 0, 1] [1, 0, 1]] function calcnormal(p) { var normal = [0, 0, 0]; for(var = 0; < p.length; i++) { var j = (i + 1) % (p.length); normal[0] += (p[i][1] - p[j][1]) * (p[i][2] + p[j][2]); normal[1] += (p[i][2] - p[j][2]) * (p[i][0] + p[j][0]); normal[2] += (p[i][0] - p[j][0]) * (p[i][1] + p[j][1]); } return normal; } you're using degenerate polygon testing. if draw in xz-plane, vertices numbered 0 3, looks this: 2 ---- 3 \ / \ / \/ /\ / \ / \ 0 ---- 1 this polygon not have defined normal, since changes orientation in middle, , folds on itself. i

ios - Have one button go to a different view and enable button -

i working on app have multiple buttons on 1 page click on go different view. thing user click on them in specific order. basically, have buttons locked except 1 , each time click on button enabled, unlocks new one. thanks. you can via tag when creating view @ time put firstbutton in enabled mode. onclick event on every uibutton can enabled next one. for example i created view 4 uibutton , given tag 1,2,3,4 @ viewload uibutton tag 1 enabled for 4 uibutton have created common action method follow enabled next uibutton next tag -(void)viewwillappear:(bool)animated { [super viewwillappear:animated]; if([[nsuserdefaults standarduserdefaults] valueforkey:@"lastenablebutton"]){ uibutton * btntemp = (uibutton *) [self.view viewwithtag:[[[nsuserdefaults standarduserdefaults]valueforkey:@"lastenablebutton"] intvalue]]; [btntemp setenabled:yes]; nslog(@"if want enable button enabled make loop nsu