Posts

Showing posts from August, 2015

c++ - (char *) (msg +1) where does this +1 takes us to? -

i seeing code, in have statement (char *)(emsg+1) given, i guess (char *) emsg might have been string, + 1 here? emsg pointer type (e.g. int ). emsg + 1 increments pointer 1, i.e. points initial address + sizeof(int) . then, (char*) (emsg + 1) cast, i.e. end result casted char* pointer, end pointer-to-char points initial address + sizeof(int) . in general, char* pointers characters, i.e. c -like 0 terminated strings, not case. convert pointer char* when want "extract" smallest unit of addressable memory, on machines char* pointer underlying type of 1 byte ( char ).

plsql - Oracle: Deferring a constraint in a begin/end block? -

how defer constraint inside begin/end block? this works: sql> set constraint t_pk deferred; constraint set. but identical statement fails in begin/end block: sql> begin 2 set constraint t_pk deferred; 3 end; 4 / set constraint t_pk deferred; * error @ line 2: ora-06550: line 2, column 5: pl/sql: ora-00922: missing or invalid option ora-06550: line 2, column 1: pl/sql: sql statement ignored you need use execute immediate : begin execute immediate 'set constraint t_pk deferred'; end;

JQuery Ajax function error when indeed there is a success -

my code calls error function, when hits action url supposed to. here jquery ajax code: function contactdialog(action, controller) { var url = '/' + action + '/' + controller; $("#contactdialog").dialog({ autoopen: true, hide: "fade", show: "bounce", height: $(window).height() / 2, width: $(window).width() / 2, title: "send email", buttons: [{ text: "send", click: function () { $.ajax({ url: url, data: $("form").serialize(), context: this, contenttype: 'application/html; charset=utf-8', datatype: "json", //xml, json, script , html success: function () { $(this).dialog("close"); sendconfirmmessage('msgsent'); ...

c++ - Template template parameters - extension to std::array -

i have question template template parameters: let's consider following class: template<typename t, template<class, class=std::allocator<t> > class underlyingcontainertype = std::vector> class mycontainer { public: t value1; t value2; underlyingcontainertype<t> container; mycontainer() {} /* methods implementation goes here */ }; in example, mycontainer container chat uses underlying stl-compatible container whatever stuff. declaring underlying container type template template parameters, instead of regular template argument, allows handy usage of class mycontainer, such as: mycontainer<int> mcv; //implicitly using vector mycontainer<int, std::list> mcl; //no need write std::list<int> //template template parameters now, while work of stl-container, such std::vector, std::deque, std::list, , forth, not work, example, std::array provided in c++11. the reason ...

alignment - How to right align my answers in python? -

how right align answers when input first, second , last number, sum , average. #create function def list_sum(num_list): #calculate , print out sum of numbers the_sum = 0 in num_list: the_sum = the_sum + return the_sum #accept 3 numbers , store them in variables input_1 = float(raw_input("input number: ")) input_2 = float(raw_input("input second number: ")) input_3 = float(raw_input("input last number: ")) #take list of inputs list_of_inputs = [input_1, input_2, input_3] #calculate , print out sum of numbers sum_of_input = list_sum(list_of_inputs) print("the sum: {:.2f}".format(sum_of_input)) #calculate , print out average of numbers the_average = (sum_of_input)/(len(list_of_inputs)) print("the average: {:.2f}".format(the_average)) #calculate , print out percent of total each number represents input_in_list in list_of_inputs: percent_total = input_in_list/sum_of_input print("the percen...

php - Should I keep a similar tests for Unit Testing and DBUnit testing in a Data Mapper? -

i've been practicing , reading test driven development. i've been doing far since of straightforward have questions test classes such 1 below. public function testpersonenrollmentdateisset() { //for sake of simplicity i've abstracted pdo/connection mocking $pdo = $this->getpdomock(); $pdostatement = $this->getpdostatementmock(); $pdo->method('prepare')->willreturn($pdostatement); $pdostatement->method('fetch')->willreturn('2000-01-01'); $accountmapper = $this->mapperfactory->build( 'accountmapper', array($pdo) ); $person = $this->entityfactory->build('person'); $account = $this->entityfactory->build('account'); $person->setaccount($account); $accountmapper->getaccountenrollmentdate($person); $this->assertequals( '2001-01-01', ...

google maps api 3 - how to get cityname from address php, googlemaps -

i need find cityname address, have take input(single textbox streetname, cityname,country) ex: skyline blvd 35, california, usa. $str = "skyline blvd 35, munchen, germany"; result: munchen what thought first find lat , lng , reverse geo cityname. lat n long: developers.google.com/maps/documentation/geocoding/?csw=1#geocoding reverse geo:developers.google.com/maps/documentation/geocoding/?csw=1#reversegeocoding i wonderring if there way of getting cityname may string itself.. skyline blvd35, munchen, germany. $x = file_get_contents( "http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=" . urlencode( "skyline blvd 35, california, usa" )); $o = json_decode( $x ); foreach ( $o->results[0]->address_components $component ) { if ( $component->types[0] == 'administrative_area_level_1' ) print $component->long_name; }

sql server - T-SQL Case Then Else Command inside Join -

i have preface telling learning sql. task validate report generated t-sql written consultant used work our company. can explain me following section doing? understand idea of left outer join, don't understand how case statement evaluates. from shipmentqty left outer join shipmentcost on case when shipmentqty.rsldnm <> 0 0 else shipmentqty.sdshpn end = shipmentcost.fhshpn , shipmentqty.rsldnm = shipmentcost.fhldnm i assume expression runs without error, again, task not run sql, validate each step of code. thank in advance , please forgive inexperience. it means if shipmentqty.rsldnm not 0, use 0, otherwise, use shipmentqty.sdshpn

javascript - Will a 'JavaScriptResult' return to an 'eval' in MVC and effect site performance? -

i looking ways redirect ajax request , came across solution: return javascript("window.location = 'http://www.google.co.uk'"); i told might wrapped in eval upon return, can change how code compiled , effect efficiency. eval("window.location = 'http://www.google.co.uk'"); //actually gets executed i told change return redirect url. two questions this: 1) executing eval , in 'success' through ajax request, effect compilation of other javascript? 2) happens when return post javascript actionresult ? run inside eval (implicitly)? // in mvc controller [httppost] public actionresult myaction() { return jsonresult("window.location = 'url'"); } // in javascript $.ajax({ type: 'post', url: '/myaction' }); javascriptresult returns javascript client, can, instance, access <script> element: <script src="/mycoolcontroller/givemescript?param5=7"></scri...

sql server - SQL: "Where" or "AND" what performs better on large database? -

this question has answer here: inner join on vs clause 10 answers i have sql query. runs on same table , creates dataset 3 columns. concern whether should use 'where' clause or 'and'. have feeling 'and' more efficient , faster 'where'. please advise. 1st 1 'where' , 2nd 1 without it. select distinct t1.rpsrespondent id_num,t1.rpscontent pid, t2.rpscontent seqno table t1 inner join table t2 on t1.rpsrespondent=t2.rpsrespondent inner join table t3 on t3.rpsrespondent=t1.rpsrespondent t1.rpsquestion='pid' , t2.rpsquestion = 'visitid' , t3.rpsquestion ='int99' , t3.rpscontent in('36','37') select distinct t1.rpsrespondent id_num,t1.rpscontent pid, t2.rpscontent seqno table t1 inner join table t2 on t1.rpsrespondent=t2.rpsrespondent , t1.rpsquestion='pid' , t2.rpsquestion = ...

php - How to search and remove various string in array elements? -

i have array login data, need remove various, user defined strings, example, array looks like: array ( [0] => date: 16/03/2015 20:39 [1] => ip address: 93.136.99.89 [2] what want remove "date:" first array element , "ip address" second array element. now using str_replace: $lastlogindate = str_replace('date:', 'datum:', $lastlogin[0]); but there more elegant way of this, , maybe, find defined occurance, , wrapp tag, every defined occurance in string in array element? you can still use str_replace() , pass array arguments it: $lastlogindate = str_replace(array('date: ', 'ip address: '), '', $lastlogin); for input array: $lastlogin = ['date: 16/03/2015 20:39', 'ip address: 93.136.99.89']; it returns you: array ( [0] => 16/03/2015 20:39 [1] => 93.136.99.89 )

Autoit How to retrieve file path opened by process by process PID -

i want full path of file opened process example : image opened paint or in case multiple notepad processes running , got pid each notepad.exe process when using _processgetpath i path of notepad.exe not file.txt opened process, how retrieve txt file path ? credits go authors of autoit unlocker! #notrayicon #include "winapiex.au3" #include <winapi.au3> dim $htimer = timerinit() dim $afiles = _processlistfiles("firefox.exe") ; list of files opened process consolewrite("+>took " & round(timerdiff($htimer)) & " milliseconds" & @crlf) #include <array.au3> _arraydisplay($afiles) exit func _processlistfiles($vprocess, $nmaxfiles = 1000) static local $aprivilege = dllcall("ntdll.dll", "int", "rtladjustprivilege", "int", 20, "int", 1, "int", 0, "int*", 0) local $nprocessid = processexists($vprocess), $aret static local $...

python 2.7 - Modifying an existing, timezone-naive scheduler to deal with daylight savings time? -

we have timezone-unaware scheduler in pure python. it uses heapq (a python binary heap) of ordered events, containing time, callback , arguments callback. gets least-valued time heapq, computes number of seconds until event occur, , sleeps number of seconds before running job. we don't need worry computers being suspended; run on dedicated server, not laptop. we'd make scheduler cope timezone changes, don't have problem in november did (we had important job had adjusted in database make run @ 8:15am instead of 9:15am - runs @ 8:15am). i'm thinking could: store times in utc. make scheduler sleep 1 minute , test, in loop, recomputing “now” each time, , doing <= comparison against job datetimes. jobs run more once hour should “just run normally”. hourly jobs run in between 2:00am , 2:59am (inclusive) on time change day, should skip hour pst->pdt, , run time pdt->pst. jobs run less hourly should avoid rerunning in either case on days have time ch...

spring - Unable to load ApplicationContext for tests only because of org.springframework.data.neo4j.config.Neo4jConfiguration validator auto wiring -

trying tests on controller , have got weird error when launching test. astonishing part have same configurations "production" , working nicely. want achieve set environment test on controllers , starting simple 1 apparently not simple.. java.lang.illegalstateexception: failed load applicationcontext @ org.springframework.test.context.defaultcacheawarecontextloaderdelegate.loadcontext(defaultcacheawarecontextloaderdelegate.java:94) @ org.springframework.test.context.defaulttestcontext.getapplicationcontext(defaulttestcontext.java:72) @ org.springframework.test.context.web.servlettestexecutionlistener.setuprequestcontextifnecessary(servlettestexecutionlistener.java:170) @ org.springframework.test.context.web.servlettestexecutionlistener.preparetestinstance(servlettestexecutionlistener.java:110) @ org.springframework.test.context.testcontextmanager.preparetestinstance(testcontextmanager.java:212) @ org.springframework.test.context.junit4.springjunit4classrunner.createtes...

python - Logo recognition in OpenCV -

i making application opencv , web server finds car brands part of ongoing game in family. however, don't know start. googled found post on finding yellow ball. want find car logo picture (which angled or glaring) identify car brand , add points score. i know seems tall order help? you use haar cascades in opencv this. need train haar detectors both positive , negative samples of logo there utilities in opencv this. read haar in opencv documentation

ruby - Using regular expression to get values from a string -

this question has answer here: parsing strings may have different values each time 5 answers i have string in database... "[{:@error=>"invalid information sent: ''. check attribute correct input value."}, {:@error=>"invalid phone number: "}, {:@error=>"invalid address: "}]" i parse out strings inside @error=> appears. something similar "invalid information sent: ''. check attribute correct input value." "invalid phone number: " "invalid address: " from previous example tried use this... string.scan(/'([^']+)'/).flatten.map{ |msg| msg.gsub(/(\.|\s+)/, ' ').strip } but returned empty array. you can use simple regex this: @error=>"(.*?)" working demo match information match 1 1. [12-91] `invalid inform...

regex - sed backreferences returning their numerical index rather than their value -

weird problem here don't seem see repeated anywhere else, posting here. in advance. i have following multiline sed code printing further sed , copy commands script (yep, using script insert code script). code looks this: sed -i -r '/(rpub )([$][a-za-z0-9])/i\ sed -i '\''/#pbs -n/d'\'' \1\ cp \1 '"$filevariable"'' $masterscript which supposed following: 1.) open master script 2.) navigate each instance of rpub $[a-za-z0-9] in script 3.) insert second line (sed) , third line (cp) lines before rpub instance, using \1 backreference of matched $[a-za-z0-9] step 1. this works great; lines print enough in relation each other. however, of \1 references appearing explicitly, minus backslashes. of \1's appearing 1. i know pattern match specifications working correctly, nail instances of rpub $[a-za-z0-9] enough, guess i'm not understanding use of backreferences. see going on here? thanks. edit 1 special...

html - Microsoft Outlook python new line character -

Image
i trying figure out how send output python script outlook mailbox. i'm having issues formatting. original method below def email_mailbox(file_checked, error_list): error_msg = '' e in error_list: if e not none: e += '\n' error_msg += e if len(error_msg) > 1: error_msg += '\nautomated test result: failed' else: error_msg = 'automated test result: passed' msg = mimetext(error_msg) msg['subject'] = 'automated review ' + file_checked[:-6] msg['from'] = 'a' msg['to'] = 'b' s = smtplib.smtp('smlsmtp') s.sendmail('a', 'b', msg.as_string()) s.quit() print(file_checked + ' review email sent') the problem unknown reason me when send large amounts of output, lines not displayed on new line using note pad open email address can see formatting looks ok ubnzi91d not start p...

c++ - When do I use & when making a pointer -

this question has answer here: what array decaying? 7 answers i understand this: int foo = 5; int * foopointer = &foo; but know can this: int foo[5] = {32,12,4}; int * fooptr = food; which strange because when int have put & operator before foo , don't have if array. can declare pointer , array? it's not list; it's array. under circumstances, name of array evaluates address of first element of array, can assign (or use initialize) pointer element type of array. there few exceptions (passing array sizeof or address-of operator (unary & ), or passing array reference, none of applies here.

sockets - /var/run/docker.sock unaccessible in container running on centos 7 -

i'm launching container runs bash script docker build internally using docker 1.3.2 on centos 7.0.1406 . files/commands @ https://gist.github.com/wrabbit-revisited/1d70d0f1805be1848c08 . the docker build needs access docker socket use common trick, per http://nathanleclaire.com/blog/2014/07/12/10-docker-tips-and-tricks-that-will-make-you-sing-a-whale-song-of-joy/ : -v /var/run/docker.sock:/var/run/docker.sock prior build run check in script: if [ -e "/var/run/docker.sock" ]; echo "docker.sock found" else echo "docker.sock not found" fi and "echo" shows docker.sock not found. found if check done outside container using sudo. i tried adding "--permissive=true" "docker run" command line, no apparent change. there reference similar problem here: https://github.com/dpw/selinux-dockersock . targets fedora/rhel, doesn't resolve issue, either. if use "setenforce permissive" , sestatus ensure ...

AngularJS ng-repeat list not updating with new array values -

i'm trying learn angularjs (along ionic framework) , have got stuck because can't page reflect new items. i use ng-repeat display items on page. i have delete item button works. when click delete, single item disappears off page. far. however, when try add/push new item nothing happens. if debug in chrome , inspect timeentries array can see item being added array, page doesn't update display new item. i don't understand why deleteitem works fine, testadd not work simplified code below.... in html have: <ion-list ng-controller="entriesctrl"> <ion-item ng-repeat="entry in model.timeentries"> <div class="row"> <div>{{entry.jobcode}}</div> <div>{{entry.description}}</div> <div>{{entry.minutesspent}}</div> </div> <ion-option-button ng-click="deleteitem(entry, $index)"> </ion-opt...

math - Sphere center point and radius from 3 points on the surface -

is possible find center of sphere , radius 3 points on surface ? i'm building model segmented brain structure 3 points within structure; head, tail , middle. thank you, express center of sphere equidistant 3 given points , coplanar them (assuming 3 given points on great circle). (x - xa)² + (y - ya)² + (z - za)² = r² (x - xb)² + (y - yb)² + (z - zb)² = r² (x - xc)² + (y - yc)² + (z - zc)² = r² |x y z 1| |xa ya za 1| |xb yb zb 1| = 0 |xc yc zc 1| subtracting first equation second , third, rid of quadratic terms. (2x - xb - xa)(xb - xa) + (2y - yb - ya)(yb - ya) + (2z - zb - za)(zb - za) = 0 (2x - xc - xa)(xc - xa) + (2y - yc - ya)(yc - ya) + (2z - zc - za)(zc - za) = 0 now have easy linear system of 3 equations in 3 unknowns. for conciseness can translate 3 points xa=ya=za=0 , , equations simplify as |x y z | |xb yb zb| = 0 |xc yc zc| (2x - xb) xb + (2y - yb) yb + (2z - zb) zb = 0 (2x - xc) xc + (2y - yc) yc + (2z - zc) zc = 0 or ...

ios - watchkit image asset naming convention -

is there standard naming convention watchkit image assets when import them xcassets folder categorized correctly? i've tried watchimage@2x~watch.png watchimage@2x~38mm.png watchimage~watch@2x.png watchimage~38mm@2x.png none of worked. currently, lot of work drag bunch of 38mm images media asset, set them device specific "apple watch" drag them correct slot, rinse , repeat 42mm images. there isn't, unfortunately. apple support in future. ended writing automator script handle imports us. i'd recommend filing enhancement radar on apple's bug reporting system .

node.js - Connection bug with socket.io-client (Server to Server) -

i have problem socket.io-client normaly when connect clientws serverws try connect in loop if serverws not started. i tried in simple node app , work, when i'm trying include in project got error: .../node_modules/socket.io-client/lib/manager.js:75 this.nsps[nsp].emit.apply(this.nsps[nsp], arguments); ^ typeerror: cannot call method 'apply' of undefined @ manager.emitall (.../node_modules/socket.io-client/lib/manager.js:75:25) @ null._ontimeout (.../node_modules/socket.io-client/lib/manager.js:464:12) @ timer.listontimeout [as ontimeout] (timers.js:110:15) 16 mar 21:54:03 - [nodemon] app crashed - waiting file changes before starting... and it's same connection code in both project : var socket = require("socket.io-client"); var ws = socket("http://localhost:3000"); so don't know problem... (tested socket.io , socket.io-client 1.3.5)

java - Android: erro NullPointerException on getWritableDatabase() -

this question has answer here: android nullpointerexception + getdatabaselocked 1 answer i have problem nullpointerexception on getwritabledatabase() database i trying build small application store information in sqlite table. receive "java.lang.nullpointerexception" exception in getwritabledatabase method. can me? code below. public class pacientedatabase extends sqliteopenhelper { private static final string db_name = "paciente.sqlite"; private static final int version = 1; private static final string table = "paciente"; public pacientedatabase(context context) { super(context, db_name, null, version); } @override public void oncreate(sqlitedatabase db) { // crear tabla paciente db.execsql("create table paciente (" + "_id integer primary key autoincrement, start_date integer)"); } ...

jquery - Generating nested UL list using JSON and Javascript -

my end goal create html list. list defined in json string. example:- {“cluster”: [ {“name”:”seir”,”cluster”:[ {“name”:”tr 0.25”,”cluster”:[ {“name”:”rr 0.30”,”member”:[“sim1”,”sim5”,”sim10”]}, {“name”:”rr 0.35”,”member”:[“sim3”,”sim7”,”sim15”]}, {“name”:”rr 0.40”,”member”:[“sim6”,”sim9”,”sim25”]} ]}, {“name”:”tr 0.5”,”cluster”:[ {“name”:”rr 0.30”,”member”:[“sim1”,”sim5”,”sim10”]}, {“name”:”rr 0.35”,”member”:[“sim3”,”sim7”,”sim15”]}, {“name”:”rr 0.40”,”member”:[“sim6”,”sim9”,”sim25”]} ]} ]}, {“name”:”sir”,”cluster”:[ {“name”:”tr 0.25”,”cluster”:[ {“name”:”rr 0.30”,”member”:[“sim1”,”sim5”,”sim10”]}, {“name”:”rr 0.35”,”member”:[“sim3”,”sim7”,”sim15”]}, {“name”:”rr 0.40”,”member”:[“sim6”,”sim9”,”sim25”]} ]}, ...