Posts

Showing posts from February, 2010

java - I need the length of an array element, and then print the last character -

so, today, given school project, , need help. i need find first , last letter of each element in array, , print it. of java people out there, please tell me function, method, or bit of code need in order this? one of issues comes when compile , run says charat(a);, tells me cannot take character there, whatever reason. so, if me work out, i'll grateful, due tonight, , cannot figure out. thanks much. /** * write description of class pokemon here. * * @author (your name) * @version (a version number or date) */ import java.util.scanner; public class pokemon { public static void main (string [ ] args) { scanner scan = new scanner(system.in); string array [ ] = new string [ 10 ]; array [ 0 ] = "charizard"; array [ 1 ] = "pikachu"; array [ 2 ] = "jigglypuff"; array [ 3 ] = "timburr"; array [ 4 ] = "conkeldurr"; array [ 5 ] = "gurdurr"; system.out.println("-----

c++ - Why does Windows 10 start extra threads in my program? -

with visual studio 2015, in new, empty c++ project, build following console application: int main() { return 0; } set break point on return , launch program in debugger. on windows 7, of break point, program has 1 thread. on windows 10, has five(!) threads: main thread , 4 "worker threads" waiting on synchronization object. who's starting thread pool (or how find out)? crystal ball says debug > windows > threads window shows these threads @ ntdll.dll!tppworkerthread . sure enable microsoft symbol server see yourself, use tools > options > debugging > symbols. this happens in vs2013 not caused new vs2015 diagnostic features, @adam's guess cannot correct. tppworkerthread() entrypoint thread-pool thread. when set breakpoint debug > new breakpoint > function breakpoint on function. got lucky capture stack trace 1st threadpool thread when 2nd threadpool thread started executing: ntdll.dll!_ntopenfile@24() unknown

php - Not able to get saved value from db mysql as selected value in dropdown. I trying to update the form which user has already filled -

i trying data database values reflecting saved value dropdown not coming selected. <div class="col-md-4"> <select name="officename" id="officename" class="form-control" onchange="gettext(this)" required> <?php while($data = dbfetchassoc($result)){ ?> <option value=''><?php echo $data['off_name']; ?></option> <?php }//while ?> </select> </div> this common issue. let's have select statement populated key value pairs database: <select name="sel"> <?php foreach ($options $value => $label) : ?> <option value="<?= $value ?>"><?= htmlentities($label) ?></option> <?php endforeach ?> when form submitted, you'll value of sel in $_get or $_post (or $_request).

c - Gstreamer: capturing still frames from webcam with appsink? -

i have working c program streams continuous frames webcam appsink. however, i'm interested in capturing single frames when user presses key. in other words: when idle, appsink receives no frames, when key pressed, appsink should pull single new frame camera source. i've tried using output_selector "valve" switch frames between fakesink , appsink . when app idle, pipeline running, , looks like v4l2src -> output_selector -> fakesink and when want capture frame, change output_selector 's active pad pipeline looks this: v4l2src -> output_selector -> jpegenc -> appsink then gst_app_sink_pull_sample() , switch active pad fakesink . issue (usually every other capture) duplicate frame that's same last one. how can resolve issue? there way achieve desired behavior?

java - composite inheritance: how to assign a final field at sub-class constructor which depends on 'this' value (backward reference)? -

i use composite classes group functionalities. but, class (with composite a1), got inherited b (with composite b1), , behavior existent @ a1 going adapted @ b1, final a1 must b1 instance work. obs.: have ways make sure composite instantiation happens (only composite partner). unable assign b1 object a1 final field: class finalfieldtestfails{ class a1{ a1(a a){} } class a{ protected final a1 a1; a(){ this.a1 = new a1(this); } a(a1 a1){ this.a1 = a1; } } class b1 extends a1{ b1(b b){ super(b); } } class b extends a{ //b(){ super.a1=new b1(this); } //fail: cant change final value //b(){super(new b1(this));} //fail: cant use 'this' or 'super' } } ps.: answer shall not involve reflection security tricks if possible. b(){ super.a1=new b1(this); } //fail: cant change final value you can not assign values assigned final variab

ruby - One-liner to generate Powerball picks in Swift? -

with u.s.'s large $1.5 billion lottery week, wrote function in ruby make powerball picks. in powerball , choose 5 numbers range 1..69 (with no duplicates) , 1 number range 1..26 . this came with: def pball array(1..69).shuffle[0..4].sort + [rand(1..26)] end it works creating array of integers 1 69, shuffling array, choosing first 5 numbers, sorting those, , adding on number 1 26. to in swift takes bit more work since swift doesn't have built-in shuffle method on array . this attempt: func pball() -> [int] { let arr = array(1...69).map{($0, drand48())}.sort{$0.1 < $1.1}.map{$0.0}[0...4].sort() return arr + [int(arc4random_uniform(26) + 1)] } since there no shuffle method, works creating [int] values in range 1...69 . uses map create [(int, double)] , array of tuple pairs contain numbers , random double in range 0.0 ..< 1.0 . sorts array using double values , uses second map return [int] , uses slice [0...4] extract first 5 numb

node.js - Strange closure issue in javascript -

how come in case getting ['undefined1','undefined2'] value array? pushed in same scope. router.post('/add', function(req, res) { var imagearr = []; for(var = 1; <= 4; i++) { if (req.body["photo" + i]) { imagearr.push(req.body.photo + '' + i); } } console.log(imagearr) // working fine here, returning correct values ['something','something'] if (req.body.is_update) { console.log(imagearr) // working fine here too, returning correct values } else { console.log(imagearr) // not working fine here, returning undefined1, undefined2.. } } is because of async, possibly? i thought turn comment formal answer question won't hang unanswered. you need replace part of script imagearr.push(req.body.photo+''+i); imagearr.push(req.body["photo"+i]); . examples of console outputs both cases can seen in fiddle.

Mysql Ranking Query on 2 columns -

table id user_id rank_solo lp 1 1 15 45 2 2 7 79 3 3 17 15 how can sort out ranking query sorts on rank_solo ( ranges 0 28) , if rank_solo = rank_solo , uses lp ( 0-100) further determine ranking? (if lp = lp, add ranking no tie rankings) the query should give me ranking random user_id. how performance wise on 5m+ rows? so user_id 1 have ranking 2 user_id 2 have ranking 3 user_id 3 have ranking 1 you can ranking using variablesl select t.*, (@rn := @rn + 1) ranking t cross join (select @rn := 0) params order rank_solo desc, lp;

angularjs - twig's dump ouput loaded via $http cannot be collapsed or expanded -

Image
i have simple action(in symfony 2.8 using twig 1.23.1), renders string: /** * @route("/test", name="my_test_route") * * @return \symfony\component\httpfoundation\response */ public function testaction() { $returncontent = array( 'message'=>'my message', 'test' => array( 'one' => 'one', 'two' => 'two', 'three' => 'three', 'four' => 'four', 'five' => 'five', 'six' => 'six', ) ); return $this->render('mybundle:message.html.twig', $returncontent); } the template outputs message , dumps test array: {% extends 'mybundle::layout.html.twig' %} {% block body %} {{ dump(test) }} {{ message }} {% endblock %} the above scenario working , expected dump output. however when output a

magento2 - How to get prefix table in magento 2 -

i need prefix table in magento 2 join table. try find on internet don't see how prefix table in magento 2. can me it seems there have been code changes in magento. referring @manashvi birla answer, need replace : $connection->gettablename('customer_entity'); by : $this->_resource->gettablename('customer_entity'); to able table prefix.

Apache rewrite rules in both config and .htaccess -

i have cakephp application hosted in virtual host (apache 2.4) works ok. in internal network virtual host name cannot routed have use web server ip. , since server hosts multiple applications have set alias in config file: alias /abc "/var/www/cake/audio/webroot" <directory "/var/www/cake/audio"> options +followsymlinks -multiviews require granted allowoverride rewritebase /abc </directory> the problem specifying allowoverride all, rewritebase in .htaccess defaults / overrides config file. how can make rewritebase equal / when accessed using virtual host , rewritebase equal /abc when access using ip?

r - Average of last lowest N prior values by group -

basically want rolling average of lowest n values. i have tried using mydata$lowest_n = rollapply(values, 5, mean(sort[1:5]), align=c('right')) but cannot work. again needs rolling time series data set. above code know has obvious error, don't have attempted methods in front of me. advice appreciated!!!! if matters, have scenario many different groups, grouped using ddply() my data = structure(list(date = structure(c(13586, 13587, 13594, 13635, 13656, 13657, 13686, 13710, 13712, 13718, 13726, 13753, 13783, 13791, 13874, 13895, 13910, 13917, 13923, 13930, 13958, 13970, 13977, 13978, 13991, 14018, 14021, 14066, 14070, 14073, 14104, 14112, 14118, 14138, 14220, 14269, 14293, 14473, 14631, 13566, 13692, 13916, 14084, 12677, 12984, 13035, 13222, 13406, 13417, 13483, 13539, 13580, 13607, 13644, 13693, 13698, 13713, 13714, 13726, 13727, 13750, 13754, 13777, 13809, 13810, 13812, 13819, 13832, 13853, 13893, 13944, 13954, 14015, 14021, 1

c# - The type 'IEnumerable<>' is defined in an assembly that is not referenced. System.Runtime -

i have asp.net 5 web application references class library. that class library use entity framework 7 perform query. public ienumerable<member> getmemberybyfirstname(string firstname) { var members = _context.members.where(m => m.firstname.contains(firstname)); return memebers; } but compile error the type 'ienumerable<>' defined in assembly not referenced. must add reference assembly 'system.runtime, version=4.0.0.0, culture=neutral, publickeytoken=b03f5f7f11d50a3a'. * i figured out how wanted info available. it's quite complicated , revolves around project.json. the short answer changed project.json in class library { "version": "1.0.0-*", "description": "member.business class library", "authors": [ "bryan" ], "tags": [ "" ], "projecturl": "", "licenseurl": "",

jsf - How to find out client ID of component for ajax update/render? Cannot find component with expression "foo" referenced from "bar" -

the following code inspired primefaces datagrid + datatable tutorials , put <p:tab> of <p:tabview> residing in <p:layoutunit> of <p:layout> . here inner part of code (starting p:tab component); outer part trivial. <p:tabview id="tabs"> <p:tab id="search" title="search"> <h:form id="instable"> <p:datatable id="table" var="lndinstrument" value="#{instrumentbean.instruments}"> <p:column> <p:commandlink id="select" update="instable:display" oncomplete="dlg.show()"> <f:setpropertyactionlistener value="#{lndinstrument}" target="#{instrumentbean.selectedinstrument}" /> <h:outputtext value="#{lndinstrument.name}" />

c++ - Are the column count and column decltypes invariant for the duration of the execution of a SQLite prepared statement? -

when @ code other folks have written using sqlite3 c api, find sqlite3_column_decltype , sqlite3_column_count called inner loop (once per result row). my understanding of database these values never change if statement re-compiled (see the bit sqlite3_prepare_v2 ). so should able call these once , cache them after call sqlite3_prepare . the columns' declared types can change, if use same statement in 2 transactions , database schema changed between them. in same situation, column count can change, if query using select * . however, single query execution inside transaction ( either manual or automatic one ). if cache values after call sqlite3_prepare_v2() , use them until next call sqlite3_reset() / sqlite3_finalize() , fine. can cache them longer if ensure uses inside same transaction.

java - Is this correct way to use Sqlite database in Android -

this question has answer here: unfortunately myapp has stopped. how can solve this? 14 answers i beginner android. start learning it. creating register form integrated sqlite database. throwing error when click register button. please me. correct ? wrong code. how can debug application in android. using gennymotion emulator. this database helper class : databasehelper.java public class databasehelper extends sqliteopenhelper { private static final int database_version = 1; private static final string database_name = "contacts.db"; private static final string table_name = "contacts"; private static final string column_id = "id"; private static final string column_name = "name"; private static final string column_password = "password"; sqlitedatabase db; private static final stri

php - Redirecting out of modal box in joomla -

i have component in joomla contains form,this form in modal sbox...when form submitted redirects user successfull message page again in modal box,my problem want redirect normal page not in modal...how can that? this redirect code component... $url = jroute::_('index.php?option=com_jxtcappbook'.(jrequest::getint( 'pop', 0) ? '&view=complete&tmpl=component' : '')); $this->setredirect($url,jtext::_( 'you appointment booked succesfully.'.$pop )); you can user below code if using joomla 2.5 $app = jfactory::getapplication(); $app->redirect('index.php'); and if using joomla1.5 than global $mainframe; $mainframe->redirect('index.php'); vote me if helpful you thanks!

hdfs - No such file or directory error when using Hadoop fs --copyFromLocal command -

i have local vm has hortonworks hadoop , hdfs installed on it. ssh'ed vm machine , trying copy file local filesystem hdfs through following set of commands: [root@sandbox ~]# sudo -u hdfs hadoop fs -mkdir /folder1/ [root@sandbox ~]# sudo -u hdfs hadoop fs -copyfromlocal /root/folder1/file1.txt /hdfs_folder1/ when execute following error - copyfromlocal:/root/folder1/file1.txt': no such file or directory i can see file right in /root/folder1/ directory hdfs command throwing above error. tried cd /root/folder1/ , execute command same error comes. why file not getting found when right there? by running sudo -u hdfs hadoop fs... , tries read file /root/folder1/file.txt hdfs. you can this. run chmod 755 -r /root . change permissions on directory , file recursively. not recommended open permission on root home directory. then can run copyfromlocal sudo -u hdfs copy file local file system hdfs. better practice create user space root , copy files di

Change the position of a table in page using CSS -

i have table , @ end of page: <table class="fes-display-field-table fes-submission-form-display-field-table"> </table> now want move table between: <h2 class="section-title"><span>giới thiệu về dịch vụ</span></h2> table here <article id="post-8306" class="post-8306 type-download status-publish format-standard hentry...> is there way css? here css file: https://jsfiddle.net/wcq1ft3k/ this want. have give position property table style.i concerned position table. try code. change values of left , top . think table class name mytable <html> <head> <title></title> </head> <style type="text/css"> .mytable{ border: 1px solid black; position: absolute; top: 200px; left: 300px; } </style> <body> <table class="mytable"> <tbody> <tr> <th style="width:200px; border-r

python - How do I rotate an isometric camera around the screen center? -

Image
i have tile-based project game, got nice pseudo-3d effect using multiple tile layers, able rotate camera (essentially, rotating sprites). but, rotating sprites isn't equal rotating world, right? by that, got to: x = (x - y) * (tile_width/2); y = (x + y) * (tile_width/2); but, see? works 45 degree rotated tiles! how can modify angle used in formulas (or maybe better, more appropriate one)? rotating sprites part of rotating world/camera. to rotate world/camera, each tile needs moved along arc, , rotated @ same time. need use polar coordinates. compute distance , angle center-of-rotation center of each tile. add desired angle-of-rotation polar angle each tile. compute new x , y values center of tile converting cartesian coordinates. here's code might like, assuming each tile represented struct, , struct has original x , y coordinates of center of tile (i.e. coordinates of center of tile when world not rotated). // compute distance center of ti

c++ - Is there any checklist to avoid crashes when using OpenCV SVM? -

i' stepping through svm in opencv 2.4 slowly. 1 crash there list of suggestions, how check data befode feeding train , predict functions? currently have crashes when calling predict , can't figure out why. this section of code should relevant: row = cv::mat::zeros(1, 256, cv_32fc1); ( std::map<int, int>::iterator fit = tmp.begin(); fit != tmp.end(); fit ++ ) { row.at<float>(0, fit->first) = fit->second; } float result = svm.predict(row); seems not documented stumbling block. when create cvsvm - instance on heap, doesn't crash more. i used create global instance ov cvsvm in test code, , assign actual data later: cvsvm _svm; //... code , scopes //training _svm = cvsvm (trainingdata, trainingclasses, cv::mat(), cv::mat(), param); //... code , scopes //testing float l = _svm.predict(testdata) it crashed in predict, because labels mat vas not i

c++11 - C++ Terminal applications in spanish -

this code: void ascii_es() { std::vector<int> list; std::wstring a; list.push_back( 160 ); list.push_back( 181 ); list.push_back( 130 ); list.push_back( 144 ); list.push_back( 161 ); list.push_back( 214 ); list.push_back( 162 ); list.push_back( 224 ); list.push_back( 168 ); list.push_back( 164 ); list.push_back( 165 ); list.push_back( 163 ); list.push_back( 233 ); for(auto : list) { = i; wcout << l"alt + " << << l": " << << std::endl; } } nicely displays spanish letters on win10 console, code void displayes() { std::locale myloc; std::locale es("es"); std::locale::global(es); std::wcout.imbue(es); std::wcout << l"has escogido espa" << static_cast<char>(164) << "ol" << std::endl; std::locale::global(myloc); std::wcout.imbue(myloc); } does not disp

java - Spring Boot Actuator application won't start on Ubuntu VPS -

i have java backend uses spring boot actuator won't start on digitalocean ubuntu vps. same application runs on mac , on other ubuntu pc. szabolcs@smartupprod:~/smartup$ java -xmx1536m -jar build/libs/smartup-backend-0.1.0.jar it starts initialisation stops @ same point every time (no exception, hangs). if try stop @ point ^c won't bring shell back. this outoput: . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: spring boot :: (v1.1.5.release) 2014-09-04 04:19:27.697 info 1724 --- [ main] com.smartup.smartupconfiguration : starting smartupconfiguration on smartupprod pid 1724 (/home/szabolcs/smartup/build/libs/smartup-backend-0.1.0.jar started szabolcs in /home/szabolcs/smartup) 2014-09-04 04:19:27.783 info 1724 --- [

java - How can I get the values from Map<String List<Object>> -

i have model class employeebasedata.java looks (this example): public class employeebasedata { public employeebasedata(string sid){ this.sid = sid; } private string sid; private int actualhours = 10; private int regularhours = 9; private int overtime = 1; public string getsid() { return sid; } public void setsid(string sid) { this.sid = sid; } public int getactualhours() { return actualhours; } public void setactualhours(int actualhours) { this.actualhours = actualhours; } public int getregularhours() { return regularhours; } public void setregularhours(int regularhours) { this.regularhours = regularhours; } public int getovertime() { return overtime; } public void setovertime(int overtime) { this.overtime = overtime; } this controller: public class inputcontroller { public static void main(string[] args) { try { map<string, list<object>> employeemap = new hashmap<string, list<object>>(); emp

how to get value from array in php -

this php array in object have fetch contact value standard array of php. contact value not name value how can value of contact object. want contact value contact key. stdclass object ( [contactlist] => array ( [0] => { contact = 4155553695; name = "kate bell"; } [1] => { contact = 4085553514; name = "daniel higgins"; } [2] => { contact = 8885551212; name = "john appleseed"; } [3] => { contact = 5555228243; name = "anna haro"; } [4] => { contact = 7075551854; name = "hank zakroff"; } [5] => { contact = 5556106679; name = "david taylor"; } [6] => { contact = 542222222222; name = deepak; } ) ) you can try use updated solution $result = array(); foreach ($object->contactlist $k=>$v){ preg_match('/(\d+)/s', $v, $cont

android - Thumbnail not found -

i'm using universal image loader display sd card images in grid, i'm using below code. this.imageurls = new arraylist<string>(); //int datacolumnindex = imagecursor.getcolumnindex(mediastore.images.media.data); int image_column_index = imagecursor.getcolumnindex(mediastore.images.thumbnails._id); (int = 0; < imagecursor.getcount(); i++) { imagecursor.movetoposition(i); cursor cursor = mediastore.images.thumbnails.queryminithumbnail( getcontentresolver(), long.valueof(imagecursor.getstring(image_column_index)), mediastore.images.thumbnails.mini_kind, null ); if( cursor != null && cursor.getcount() > 0 ) { cursor.movetofirst();//**edit** string uri = cursor.getstring(cursor.getcolumnindex(mediastore.images.thumbnails.data)); imageurls.add(uri); } } its not load

c# - An entity object cannot be referenced by multiple instances of IEntityChangeTracker EF 6 -

i developing application in mvc 5 , ef 6. using generic method update entity , extension method detect changed values , properties. when try insert updated record, got error, an entity object cannot referenced multiple instances of ientitychangetracker my code update is: public void update(t data) { var originalentity = db.set<t>().asnotracking().firstordefault(e => e.id == data.id); var modifiedvalues = originalentity.modifiedvalues<t>(data).tolist(); (int = 0; < modifiedvalues.count; i++) { string modifiedfield = modifiedvalues.elementat(i).key; string modifiedvalue = modifiedvalues.elementat(i).value.tostring(); propertyinfo prop = data.gettype().getproperty(modifiedfield, bindingflags.public | bindingflags.instance); string s = prop.propertytype.generictypearguments.select(x => x.fullname).singleordefault(); switch (s) { case ("system.datetime"): {

doctrine2 - zf2 + Doctrine a different database for each member -

each connected member of site has database. here doctrine config "user_1": return array( 'doctrine' => array( 'connection' => array( 'orm_default' => array( 'driverclass' => 'doctrine\dbal\driver\pdomysql\driver', 'params' => array( 'host' => 'localhost', 'port' => '3306', 'user' => 'user_1', 'password' => 'psswd_user_1', 'dbname' => 'database_user_1', 'charset' => 'utf8', 'driveroptions' => array (1002 => 'set names utf8'), )),),),); is there way replace : 'user_1', 'psswd_user_1' , 'database_user_1' 'user_x', 'psswd_user_x' , 'database_user_x' user_x

javascript - Node.js JSON headers -

i'm toying node.js server-app has routes both homemade rest api , serving static pages. when serves static pages no errors, when serves stuff api, following in console: error: can't set headers after sent. @ sendstream.headersalreadysent (c:\path_to_node_folder\node_modules\send\lib\send.js:302:13) @ sendstream.send (c:\path_to_node_folder\node_modules\express\node_modules\send\lib\send.js:490:17) @ c:\path_to_node_folder\node_modules\express\node_modules\send\lib\send.js:467:10 @ fsreqwrap.oncomplete (fs.js:82:15) my routes: module.exports = function(app) { "use strict"; app.get('/api', function(req, res, next) { res.json({ message : 'welcome angular blog restful api' }); next(); }); app.get('/api/article/:permalink', function(req, res, next) { res.json({ message : "article retrieved", permalink : req.params.permalink }); next(); }); app.post(&

android - How to open camera directly in panorama/photosphere mode? -

i stuck in problem in android 4.2 jelly bean. how can open camera application, default in panorama/360 photosphere mode? i have searched lot in grepcode , camera.parameters , nothing seems help. have clues open camera in panorama mode apart video , image? there no standard way it. afaik panorama, photoshere proprietary features of gallery3d (provided google) package com.google.android.gallery3d. it's depends on firmware of device. in applicationmanifest.xml <activity cleartaskonlaunch="true" screenorientation="0" name="com.google.android.apps.lightcycle.protectedpanoramacaptureactivity" theme="resource_id:0x1030007" configchanges="1184" label="resource_id:0x7f0a00b2" windowsoftinputmode="35" taskaffinity="com.google.android.camera"> <intent-filter> <action name="android.intent.action.main"> </action> </intent-filter> </activity> i

c++ - Static variable in template function fail -

header file (test.h): #ifndef _test_h_ #define _test_h_ #include <string> #include <sstream> #include <map> typedef std::map<int, std::string> mis; //-----1----- template<typename t> const std::pair<int, std::string> mkpair1(t t) { static int i=0; std::stringstream ss; ss << t; return std::pair<int, std::string>(++i, ss.str()); } template<typename...any> void mkmap1(mis &m, any...any) { m = { mkpair1(any)... }; }; //-----2----- template<typename t> const std::pair<int, std::string> mkpair2(int i, t t) { std::stringstream ss; ss << t; return std::pair<int, std::string>(i, ss.str()); } template<typename...any> void mkmap2(mis &m, any...any) { static int i=0; m = { mkpair2(++i, any)... }; }; //-----3----- template<typename t> const std::pair<int, std::string> mkpair3(int &i, t t) { std::stringstream ss; ss << t;