Posts

c++ - A core about string -

i have function follow: #define _glibcxx_fully_dynamic_string 1 typedef struct _coordinate{ int posx; int posy; _coordinate(int x = 0,int y = 0){posx = x; posy = y;}; }coordinate; int find_way(int x, int y, int food_x, int food_y, vector <string>& grid, vector<coordinate>& co, vector<coordinate>& cur, nt& min){ if(cur.empty()){ if(!co.empty()){ return 1; } else{ return 0; } } coordinate node = cur.back(); int nx = 0; int ny = 0; if((node.posx == food_x) && (node.posy == food_y)){ if(cur.size() < min){ co.clear(); for(int = 0; < cur.size(); i++){ co.push_back(cur[i]); cout<<cur[i].posx<<" "<<cur[i].posy<<endl; } min = co.size(); } cur.pop_back(); return find_way(x, y, food_x, food_y, grid, co, cur...

python - Scrolling camera -

i've been tinkering scrolling camera follows player around , have got follow player. problem moves slower player , because of player wont stay in middle of screen. i believe problem in offset (camerax) , have tried few different values haven't found work. code: import pygame, sys, time, random, math pygame.locals import * backgroundcolor = (255, 255, 255) windoww = 800 windowh = 600 playerw = 66 playerh = 22 fps = 60 movespeed = 3 yaccel = 0.13 gravity = 2 blocksize = 30 pygame.init() screen = pygame.display.set_mode((windoww, windowh), 0, 32) mainclock = pygame.time.clock() testlevel = [ (1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,), (1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,), (1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,), (1,0,0,0,0,0,0,0,0,0,...

jsf 2 - Unable to replace div content with JavaScript in JSF -

i use javascript code below replace contents of div , it's not working. <h:head> <script type="text/javascript"> function findchange() { document.getelementbyid("mydiv").innerhtml='ravi'; } </script> </h:head> <h:body> <h:form id="form" onsubmit="findchange();"> <div id="mydiv">hello</div> <h:commandbutton value="submit" ></h:commandbutton> </h:form> </h:body> inspired @louisbros: <h:head> <script> function findchange(){ document.getelementbyid('mydiv').innerhtml = 'ravi'; return false; } </script> </h:head> <h:form onsubmit="return findchange();"> <div id="mydiv">hello</div> <h:commandbutt...

c# - Error after setting different datasources for datagridview combobox cells -

i trying display in datagridview control names , fields of database tables. in every row name of table displayed in first cell, , second column allows choose of fields of table. to that, handling 'datagridview.cellbeginedit' event , fill datasource cell names of fields. when trying edit cells, provided list displayed correctly , can b chose fine. however when try same in row, start getting dataerror events cell have edited. event arguments datarow have 'formatting|display' in context field, , have message "value not allowed in datagridviewcomboboxcell" (or close it). in debug, cell event references has correct value field, datasource null , formattedvalue empty string. , displayed text changes blank. how should resolved correctly? should derive own custom datagridview cell displays text has combobox editor? if so, how? edit: here code using: public class fielddataneededeventargs: eventargs { public list<string> fieldnames {...

android - Deliver app for beta testing -

i deploy app beta testing. however, confused on best way safely deliver beta tester devices. i understand emailing apk file not logical move. having done bit of research, found following. deploy gate - offers private over-the-air distribution. google play private channel google apps - did not quite hold of it. zubhium - new platform. has tried before? could please walk me through appropriate method? the thing beta testing always run risk of apk being leaked. there literally nothing can prevent this, rooted device can retrieve apk after installation. you should instead consider adding features timed trials apk, , have stop working after date, or after value on server has changed. additionally, beta testing matter of trust. if not trust beta testers, don't give them apk.

SQL Server identity related error -

i using query in sql server 2008.. set identity_insert abc on bulk insert abc 'f:\test.csv' ( fieldterminator = ',', rowterminator = '\n' ) go and getting error : explicit value must specified identity column in table 'abc' either when identity_insert set on or when replication user inserting not replication identity column. table structure 'abc' : id [int] identity(1,1) not null, -- primary key aa [varchar](50) null, bb [varchar](50) null, cc [datetime] null, dd [varchar](50) null, ee [varchar](50) null, ff [int] null, gg [varchar](50) null, ii [int] null, jj [int] null sample data csv file 84,0b0dbe1d,192.168.10.221,2012-07-27 16:15:41.503,0b0dbe1d_16-15-18,1.0.0,2,pra,2,null 85,111de4b6,192.168.10.221,2012-07-27 16:27:06.060,111de4b6_16-27-05,1.0.0,8,diane,5,null the error says, need specify column names while inserting. i don't think have option specify column names during bulk insert. can u...

gpgpu - how to assign a "const void*" to a "const uint64_t*" in cuda c? -

i want assign "const void*" "const uint64_t*" in cuda c. i have done this, void func(const void *buffer) { const uint64_t *words = buffer; } but i'm getting error this, error: value of type "const void *" cannot used initialize entity of type "const uint64_t *" can me in solving problem? as @sharptooth indicated, fixed me: #include <stdio.h> #include <stdint.h> void func(const void *buffer) { const uint64_t *words = (const uint64_t *) buffer; } int main(){ void *my_buf=0; func(my_buf); return 0; }

angularjs: preventing route changes -

i've tried doing following in controller: $scope.$on("$routechangestart", function (event, next, current) { if (!confirm('are sure ?')) { event.preventdefault(); } }); but doesn't work. not supposed way ? i put directive on links, should confirmed before changing route. prototyped in jsfiddle, did not test it. think, should proper way. (function (angular) { module = angular.module('confirm', []); confirmdirective = function () { return { restrict: 'a', link: function (scope, elm, attrs, ctrls) { angular.element(elm).bind('click', function (event) { alert("sure?"); event.preventdefault(); return false; //or true, depends on }); } }; }; module.directive("confirm", confirmdirective); }(angular)); http://jsfiddle.net/l6xbf/3/ check , try it. regar...

c++ - Calculating GFlops -

i'm wondering how calculate gflops program of mine like, let's say, cuda application. do need measure execution time , number of floating point operations in code? if had operation "logf", count 1 flop? the number of actual floating point operations depend on how code written (compilers can optimize in both directions - is, merging common operatoions c = (a * 4.0 + b * 4.0); can becomes c = (a + b) * 4.0 , 1 less wrote. compiler can convert more operations: c = / b; may turn into: temp = 1 / b; c = temp * a; (this because 1/x "simpler" y/x, , multiplication faster division). as mentioned in comments, floating point operations (log, sin, cos, etc) take more one, more ten, operations result. another factor take account "loads" , "stores". these can quite hard predict, highly dependant on compilers code generation, number of registers available compiler @ given point, etc, etc. whether loads , stores count or n...

regex - Regular expression matching a numerical string exactly -

i have string looks 600/-4.412/11 , 1 looks 600/11 [optional sign][float or integer]/[optional sign][float or integer]/[optional sign][float or integer] [optional sign][float or integer]/[optional sign][float or integer] example: 1) 600/-4.412/11 2) 600/11 and need find regular expression matches 1 , 1 matches 2. both expressions mustn't select/match other one. humble regex knowledge managed build expression: ([-+]?[0-9]+(\.?[0-9]+)?\/?){3} the problem expression matches 1) 2) according http://gskinner.com/regexr/ . can fix or @ least tell me why happening since hoped had change {3} {2} in order different matching. problem the problem regex allows repeated subpattern, i.e. [-+]?[0-9]+(\.?[0-9]+)?\/? match without restricting each section of numbers delimited / . for example in question: 600/11 , first repetition match 600/ , second 1 , third 1 last 1 . solution 1 wrong attempt for validation , can change make works want: ^([-+]?[0-9]+(\.[0-9]...

c# - Show only small part of picture -

i have write program consists server , client. server makes screenshot desktop, , client receives screenshot , shows on form. there problem in data transfer, see small strip. checked before sending image on server ok. however, client receives wrong image. wrong? xaml: <window x:class="testtcp.mainwindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" title="testtcp" height="350" width="525"> <grid> <image x:name="img1" margin="0"/> </grid> </window> code c#: public partial class mainwindow : window { public mainwindow() { initializecomponent(); task rec = new task(waitclientquery); rec.start(); task tk = new task(send); tk.start(); } private void send()//server part. take screen , send image { bitmap temp...

JSON get value at first index -

i stuck @ , have no idea script clear. see php code: <?php $arr = array(); $i = 0; while($i < 10) { $arr[] = $i; $i = $i + 1; } echo json_encode($arr); ?> it returned ajax function : [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] suppose stored in d javascript variable how can point first value so, stores 0 variable. if this: success: function(d) { var = d[0]; } it returns null. i don't know how explain question because not @ english. try this: success: function(d){ $.each(d, function(x,y){ var = y['field']; }); }

javascript - Validating url with http:www as optional using regex -

i trying validate url "http:www" optional, yahoo.com , http://www.yahoo.com needs valid url using following regex not take utl3 valid 1 . how can fix ?? function checkurltest(url){ var urlregex = new regexp("^(https?:\/\/www\.)?(^(https?:\/\/www\.)[0-9a-za-z]+\.+[a-z]{2,5})"); return urlregex.test(url); } url3 = "yahoo.com"; url4 = "www.yahoo.com"; alert(checkurltest(url3)); working demo http://jsfiddle.net/fy66p/ solution reside here: negative lookahead: http://www.regular-expressions.info/lookaround.html#lookahead www case , should looking for. lemme know how goes! hope fits needs :) code function checkurltest(url){ // try var urlregex = new regexp("^(?!www | www\.)[a-za-z0-9_-]+\.+[a-za-z0-9.\/%&=\?_:;-]+$") return urlregex.test(url); } url3 = "yahoo.com"; url4 = "www.yahoo.com...