Posts

Showing posts from May, 2011

android - Scrollview not flinging after onTouchListener attached -

i have scrollview has viewtreeobserver.onscrollchangedlistener not problem, once set ontouchlistener figure out when scrollview has stopped scrolling, flinging action on scrollview not happen anymore. here code: if doesnt run method have ontouch event , flinging still happens: @override public boolean ontouch(view view, motionevent event) { if (event.getaction() == motionevent.action_up) { horizontalscrollclipping((scrollview)view, view.getscrolly()); return false; //returning false instead of true } return false; } if this, method inside ontouch event fires off, flinging scrollview not happen : @override public boolean ontouch(view view, motionevent event) { if (event.getaction() == motionevent.action_up) { horizontalscrollclipping((scrollview)view, view.getscrolly()); return true; //returning true instead false } return false; } and if this, scrolling on scr

java - Where do you close a writer in TwitterStream? -

i'm working on compiling bunch of tweets information retrieval class. i'm trying using both rest api , streaming api through twitter4j. when using streaming api, use following modifications this example : final limitedfilewriter output = new limitedfilewriter("tweets","tweets"); twitterstream twitterstream = new twitterstreamfactory(cb.build()).getinstance(); statuslistener listener = new statuslistener() { @override public void onstatus(status status) { try{ output.write("@" + status.getuser().getscreenname() + " -- " + status.gettext()+"\n"); } catch(ioexception e){ e.printstacktrace(); } } } twitterstream.addlistener(listener); twitterstream.sample("en"); //output.close(); it seems can't ever close writer. writer using wraps bufferedwriter, while keeping track of file size. if file

php - Use a button to pass data to a database -

Image
i don't know if valid question site, but... i'm wondering how can use buttons add data database without use of forms? have table of "products" , want click button beside each product information add item orderlist in database. (user cart purchases) so assign value button when it's clicked match unique product_id in databse , know product being selected. if click each button mimick user adding product cart. i have 9 products in database (don't mind 1)... want click button generate action populate table within db. thanks <pre> <b>id description stock left price order id</b> </pre> <table align="left" border="1px" cellpadding="10" cellspacing="18" style="width: 450px;"> <?php $servername = "localhost"; $username = "inserter"; $password = "123456"; $dbname = "pc_master_race"; // create connection $conn = n

uitableview - iOS Swift: Refresh table view but not footer -

i have tableview custom footer view. footer view search box filtering tableview. on each keystroke table data changing , update tableview accordingly. problem if use reloaddata() lose state of search box , keyboard dismissed. tried use reloadrowsatindexpaths because table data changing , total number of rows being reduced exception when try reload row doesn't exist anymore.

java - Refresh Navigation Drawer Fragment Android? -

i have question navigation drawer fragment. know navigation drawer has multiple sections. let's 3 sections (home, profile, log out). intent when user click on log out, navigation drawer refresh (home, log in). trying play code couldn't figured out.. the files have are: mainactivity.java public class mainactivity extends actionbaractivity implements navigationdrawerfragment.navigationdrawercallbacks { /** * fragment managing behaviors, interactions , presentation of navigation drawer. */ private navigationdrawerfragment mnavigationdrawerfragment; /** * used store last screen title. use in {@link #restoreactionbar()}. */ private charsequence mtitle; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); mnavigationdrawerfragment = (navigationdrawerfragment) getsupportfragmentmanager().findfrag

node.js - Install of NodeJs failed without an explanation. Here's the log -

i executed msiexec.exe on windows 7 64-bit machine option log file: c:\windows\winsxs\amd64_microsoft-windows-installer- executable_31bf3856ad364e35_6.1.7601.17514_none_a7a77a3b9cb96ce6\msiexec.exe /log installer.log /i "d:\users\chad\downloads\node-v0.12.2-x64.msi" and got message install failed , rolled back. the log long include in message, posted here on 1 drive. here's truncated log, reduced in size posting. didn't remove might reveal issue. === logging started: 4/22/2015 20:54:54 === action 20:54:54: install. action start 20:54:54: install. action 20:54:54: findrelatedproducts. searching related applications action start 20:54:54: findrelatedproducts. action ended 20:54:54: findrelatedproducts. return value 1. action 20:54:54: preparedlg. action start 20:54:54: preparedlg. info 2898.for wixui_font_normal textstyle, system created 'tahoma' font, in 0 character set, of 13 pixels height. info 2898.for wixui_font_bigger textstyle, system

java - alphabetically sort elements in a List -

this question has answer here: sorting arraylist of objects object attribute 2 answers i have shape class , in class there method called getrepr() can char representation of shape. example, shapea.getrepr() ->'a' shapeb.getrepr() ->'b' shapec.getrepr() ->'c' now have arraylist stores several shapes including shapee , shapea , shaped , shapec , , shapeb . the question how can use collections.sort() alphabetically rearrange these shapes in arraylist according char representations? the expected result in arraylist after sorting should shapea , shapeb , shapec , shaped , shapee . or there way reach purpose without collections.sort() ? you need implement comparable interface in superclass public class myclasssuperclass implements comparable<myclasssuperclass>{ @override public int compareto(myc

C++ function cout redirect to file -

say have simple function named print , loop uses cout print, say, 1-5, console. is there way can like: file << print (); to output of print saved file? assuming open file ofstream properly, , everything. assuming print void function output hard-coded cout , there nothing can do: output controlled execution environment's assignment of output stream (console default or file redirect >myoutput.txt ). if program control output goes, pass ostream& print function, , use output: void print(ostream& ostr) { // use ostr instead of cout ostr << "hello, world!" << endl; } if want print output console or default output, call print(cout); if want write file, make ofstream , , pass print : ofstream file("hello.txt"); print(file);

Labelling groups of two columns in SQL (BigQuery SQL if possible) -

given table name ip = |a 1 | |b 1 | |c 1 | |b 2 | |c 2 | |d 3 | |e 2 | if 2 names share same ip belong in same group. ip same name belong in same group. if find names ip 1, {a, b, c}, should include ips associated {a,b,c} in same group {1,2} , again names ips aren't include {e} , forth. in particular example, in {a,b,c,e} x {1, 2} in same group. results above table be name ip group = |a 1 1 | |b 1 1 | |c 1 1 | |b 2 1 | |c 2 1 | |d 3 2 | |e 2 1 | just clear: if names a, b, , c ip 1 grouped , should have a, 1 = group1 b, 1 = group1 c, 1 = group1 if names a, b share ip 2, should not make new group instead should should in same group this: a, 1 = group1 b, 1 = group1 c, 1 = group1 a, 2 = group1 b, 2 = group1 the goal solve in google bigquery sql. so far have select ip, row_number() on () g

python - Defining a function with exec from inside a function in global environment -

i have function that, when called, should define function use of exec , make new function available main program. mwe following. main program: #!/usr/bin/python ext import makef makef() saya() external module: def makef(): script="def saya():\n\tprint 'aah'" exec(script) saya() return what want able call inner function saya() main program, in example output should aah aah but instead returns aah traceback (most recent call last): file "mwe.py", line 5, in <module> saya() nameerror: name 'saya' not defined which kind of expected, replace exec(script) line exec(script,globals) , according docs , instead get traceback (most recent call last): file "mwe.py", line 4, in <module> makef() file "/home/tomas/tests/ext.py", line 3, in makef exec(script,globals,locals) typeerror: exec: arg 2 must dictionary or none i have feeling i'm missing pretty obvious here c

Android Update Mainactivity List View after popup Dialog updates database -

i have listview on mainactivity showing items database. have add button in action bar. when add button clicked on dialog pops , user fills out fields new item , click "add" , adds item database. problem listview on mainactivity doesn't update show new item. can close app , reopen , see new item. doesn't update immediatly. (same problem deleting item, delete happens onlongpress) mainactivity.java package blah.blah.blah import android.app.alertdialog; import android.app.dialog; import android.app.dialogfragment; import android.content.contentvalues; import android.content.dialoginterface; import android.database.cursor; import android.database.sqlite.sqlitedatabase; import android.os.bundle; import android.support.v4.app.fragment; import android.support.v4.app.fragmentactivity; import android.support.v4.app.fragmentmanager; import android.support.v4.app.fragmentpageradapter; import android.support.v4.view.viewpager; import android.util.log; import android.view.

python - how to save a column vector in an iteration process to a text file -

i need save column vector obtained in iteration text file using python. this have been using till now savetxt('displacement{0}.out'.format(globdat.cycle), a, delimiter=',', fmt='%10.4e',) globdat.cycle used count in each iteration separate file made. requirement - not require separate files single file contains vectors corresponding each iteration. eg - iteration 1 values = [ 1 2 3 4 5 6 ]' , iteration 2 values = [ c v b f h ]' my text file should similar to 1,a 2,c 3,v 4,b 5,f 6,h i appreciate help. thanks

Does a for loop in JavaScript try to run all iterations in the same frame, or does it wait till previous iteration finishes? -

say have for loop in javascript: for(var i=0; i<100000; i++){ // ... } if run heavy code within loop, attempt cram 100,000 iterations single frame, or extend operation on multiple milliseconds if needed? i believe question you're answered going best answered reading documentation javascript concurrency model . in brief, however: no other javascript preempt loop while executing.

javascript - typeError when passing in objects to require() for passport -

i typeerror: object not function when run: node server.js for following line of code require('./app/routes.js')(app, passport); from following code server.js file: // server.js // set ====================================================================== // tools need var express = require('express'); var app = express(); var port = process.env.port || 8080; var mongoose = require('mongoose'); var passport = require('passport'); var flash = require('connect-flash'); var morgan = require('morgan'); var cookieparser = require('cookie-parser'); var bodyparser = require('body-parser'); var session = require('express-session'); var configdb = require('./config/database.js'); // configuration ================================================================ mongoose.connect(configdb.url); // connect our database // require('./config/passport')(passport); // pass passport configuration

angularjs - Angular: prevent default not working when clicking on div -

in plunk have 2 divs. first div (orange color) contains second div (blue color). objective show alert when click on div. if click on orange div (directive dir1), you'll see alert. if click on blue div (directive dir2), see two alerts, because prevent default e.preventdefault() not stopping chain of events. how make work? html: <div dir1 style="width:200px;height:200px;background-color:orange"> <div dir2 style="width:100px;height:100px;background-color:blue"> </div> </div> javascript: app.directive('dir1', function() { var directive = {}; directive.restrict = 'ea'; directive.link = function(scope, element, attrs) { element.bind('click', function() { alert('clicked on dir1'); }); } return directive; }); app.directive('dir2', function() { var directive = {}; directive.restrict = 'ea'; directive.link

What is happening in Python 3 when I call list() on an iterator? -

for example, want print out board tic tac toe initially board = [[0]*3]*3 i want use map apply print() each row, output is [0, 0, 0] [0, 0, 0] [0, 0, 0] in python 3, map returns iterator instead of list, example of adapting found list(map(print, board)) which gives correct output. don't know what's going on here - can explain happening when do list(iterator) ? the built-in list constructor common way of forcing iterators , generators iterate in python. when call map, returns map object instead of evaluating mapping, not desired author of code snippet. however, using map print items of iterable on separate lines inelegant when consider power print function holds in python 3: >>> board = [[0]*3]*3 >>> board[0] board[1] true >>> "uh oh, don't want that!" "uh oh, don't want that!" >>> board = [[0]*3 _ in range(3)] >>> board[0] board[1] false >>> "that's lot

java - ColdFusion cfhttp looses metadata in uploading docx file -

i having problem uploading docx file. looses 2 bytes after upload , save server. here code. <cffunction name="akamaiupload" access="private" output="false"> <cfargument name="filename" type="string" required="true"> <cfargument name="localpath" type="string" required="true"> <cftry> <cfhttp url="http://sample.com/#arguments.filename#" method="post"> <cfhttpparam type="file" name="user_file" file="#arguments.localpath#" /> </cfhttp> <!--- catch error, return error message ---> <cfcatch type="any"> <cfreturn #cfcatch.message#> </cfcatch> </cftry> </cffunction> i've found code same issue , tried apply solution still didn't work. here code. <cffunction name="akamaiupload&qu

Standard Deviation Loop in R -

i want create loop takes standard deviation of positions 1 through 3 in "y" takes standard deviation of positions 4 through 6 etc. here code came far stuck since new vector "i" increasing same values. here hypothetical dataset. x <-rep(1:10, each =3) y <- rnorm(30, mean=4,sd=1) data <- cbind(x,y) sd.v = null (i in c(1,4,7,10)){ sd.v[i] <- sd(y[c(i,i+1,i+2)]) } i more interested in creating loop rather using apply , sapply , tapply or else. if want loop, here approach: set.seed(42) y <- rnorm(30, mean=4,sd=1) sd.y <- as.numeric() for(i in 1:10){ sd.y[i] <- sd(y[(1+(i-1)*3):(3+(i-1)*3)]) } sd.y # [1] 0.9681038 0.3783425 1.1031686 1.1799477 0.6867556 1.6987277 # [7] 1.8859794 1.4993717 1.2956209 1.1116502

How do I send exception to callback in Android? -

i have class (named c) check structure of json , if structure wrong, throws exception. class called class b. can use try catch in class b. actually, class b called class a, provide callback class b. how send exception class c called class b callback ( onfinishlistener ) in class a? want provide try catch in callback declaration in class a, not class b. public class { b b = new b(); b.getresponsefromserver(new b.onfinishlistener { @override public void onfinish(object response) { }); } public class b { public static interface onfinishlistener { void onfinish(object response); } //other code public void getresponsefromserver(onfinishlistener onfinishlistener) { response.listener<jsonobject> listener = new response.listener<>() { @override public void onresponse(jsonobject response) { try { onfinishlistener.onfinish(c.somemethod(response);

Object reference not set to an instance of an object while initializing WebView Xamarin Android -

i have following code:- protected override void oncreate(bundle bundle) { base.oncreate(bundle); setcontentview(resource.layout.layoutinformation); webview body = findviewbyid<webview>(resource.id.bodycontentwv);-- error here // create application here } layoutinformation.xml <?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:minwidth="25px" android:minheight="25px"> <android.webkit.webview android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/bodycontentwv" /> </linearlayout> i following error while initializing webview. can point out iam doing wrong? system.nullr

jmeter - Performance test - approach -

i have user registration , flight search , book tickets modules in application. have created jmeter test & have different thread groups each module in test. verified & works well. thread group 1: xx number of users - access site - click on regression , enter details & register . (bold -> loop- happening again , again) thread group 2: xx number of users - access site - login, - search flights - (bold -> loop - happening again , again) thread group 3: xx number of users - access site - login, book ticket - (bold -> loop - happening again , again) issue: my manager says need run modules (all thread groups) appropriate users how going in production. though can run them together, - in case of issues - not know feature of application caused issue. my aim run each module separately & find performance. think doing module wise correct approach response time, resource utilization etc. clarify: i not have experience in performance testing. cor

java - Accessing functions of an object's (dynamically chosen) subclass -

i trying implement simple binary heap class in user can choose whether want min or max heap. i made super class abstract: abstract class heap { size() { ... } peek() { ... } } the main method chooses instantiate either maxheap or minheap subclass. public static void main(string[] args) { heap myheap = new minheap(); if ( /* condition */ ) myheap = new maxheap(); } myheap.insert(/* value */); the insert function implemented differently in min , max heap classes: class minheap extends heap { public void insert() { ... } } class maxheap extends heap { public void insert() { ... } } of course, calling insert() main throws error, since there no such method in heap class. best way programmatically choose between similar min , max heap implementations? insert appears have same signature in both cases, can pull superclass. doesn't matter if they're implemented differently long signatures same. your heap class become

html - Why inline-block is not working to align two divs inside of a parent container div horizontally side by side? -

i have simple html template <!doctype html> <html lang="en" xmlns="http://www.w3.org/1999/xhtml"> <head> <meta charset="utf-8" /> <title></title> <style> *{ margin:0px; padding:0px; } <!--resetter rules browsers--> #bodycontainer { border:green 2px solid; } body { border:black 2px solid; background-color : grey; padding:5px; } #header { background-color : red; width:70%; height:80px; border:black 2px solid; padding:5px; } #header1 { display:inline-block; width:50%; border:green 2px solid; } #header2 { display:inline-block; width:50%; border:green 2px solid; } </style> </head> <body> <div id="bodycontainer"> <div id="header"> <div id="header1"