Posts

Showing posts from 2018

C++ virtual function: Base class function is called instead of derived

Image
Clash Royale CLAN TAG #URR8PPP C++ virtual function: Base class function is called instead of derived I have following code snippet: using namespace std; class base { public: virtual void print(char a){ std::cout<<" Base "<<std::endl;} }; class derived :public base { public: void print(floata) {std::cout<<" Derived "<<std::endl;} }; int main() { base* d = new derived; d->print(1.5); return 0; } Output is "base" Why output is coming from base function and not from derived one By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

two way webservice communication REST

Image
Clash Royale CLAN TAG #URR8PPP two way webservice communication REST G'day folks, So I have an application in mind with a client-server architecture where multiple clients are connected to a web service. The webservice needs to be able to call or send messages to all or some of the clients. I have previously done the same using SOAP based services in WCF but now I am working with java and wish to avoid SOAP. I have been experimenting with Server Sent Events in reactive framework in Spring framework but have been mostly unlucky. Is there a way to implement two way communication without explicitly exposing a webservice or such on the client? thanks a bunch :) 1 Answer 1 Try WebSockets for two-way communication and simple Restful for request-response communication. Here is a simple guide: http://www.baeldung.com/java-websockets By clicking "Post Your...

jaxb unmarshal xml element to object with some fields

Image
Clash Royale CLAN TAG #URR8PPP jaxb unmarshal xml element to object with some fields I have some classes: class Location { private Long id; private String roomTitle; protected Specialization specialization; } public class Specialization { private Long id; private boolean archived; private String title; } and xml: <location id="10"> <roomTitle>string</roomTitle> <specializationId>10</specializationId> </location> Can I unmarshal specializationId to Location.specialization.id ? By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Regex - How to capture all iterations of a repeating pattern?

Image
Clash Royale CLAN TAG #URR8PPP Regex - How to capture all iterations of a repeating pattern? Take a look at this example, I want to capture not just the last iteration (which is 5), but also 2, 3 and 4. It says here: A repeated capturing group will only capture the last iteration. Put a capturing group around the repeated group to capture all iterations... but I don't know how to do this. Since I need this in C++, I was looking for a way to get all iterations of capturing group using some regex functions in C++, but I always end up with same groups which the website finds. How about instruction d((,d)*) ? (IMHO, this is meant in the cited text.) Though, this leaves still the task to separate the inner matches... – Scheff 17 mins ago instruction d((,d)*) Thou...

Does VueJS production mode remove all warning

Image
Clash Royale CLAN TAG #URR8PPP Does VueJS production mode remove all warning Inside VueJS deployment doc, they say that in production mode warnings are not displayed https://vuejs.org/v2/guide/deployment.html However, these warning strings become useless in production and bloat your app’s payload size Does every warning are not displayed anymore or some of this warnings can't still be there, especially compilation error ? It seems weird that compilations errors displayed in vue warning on dev mode cannot be seen in prod mode. Furthermore compilation error can break other non VueJS scripts. By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Why does powershell give different result in one-liner than two-liner when converting JSON?

Image
Clash Royale CLAN TAG #URR8PPP Why does powershell give different result in one-liner than two-liner when converting JSON? Overview From a powershell 3 prompt,, I want to call a RESTful service, get some JSON, and pretty-print it. I discovered that if I convert the data to a powershell object, and then convert the powershell object back to json, I get back a nice pretty-printed string. However, if I combine the two conversions into a one-liner with a pipe I will get a different result. TL;DR: this: PS> $psobj = $orig | ConvertFrom-JSON PS> $psobj | ConvertTo-JSON ... gives me different result than this: PS> $orig | ConvertFrom-JSON | ConvertTo-JSON Original data [ { "Type": "1", "Name": "QA" }, { "Type": "2", "Name": "whatver" } ] Doing the conversion in two steps I'm going to remove the whitespace (so it fits on one line...), convert it to a powershell object, and then...

Groovy : Constructor call must be the first statement in a constructor

Image
Clash Royale CLAN TAG #URR8PPP Groovy : Constructor call must be the first statement in a constructor New to Groovy. Using scripts as part of Jenkins pipeline. Editing in Sublime with only a linter. Receiving this error: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: file:/var/jenkins_home/jobs/{repo}/branches/master/builds/9/libs/{jenkins-library-name}/src/{srcPath}/Pom_EX.groovy: 12: Constructor call must be the first statement in a constructor. at line: 12 column: 11. 1 Answer 1 Really beat myself up here for taking so long to see it. I didn't see it, since I've been working in Java for a few years now - and the IDE points out this type of mistake. Name of the constructor didn't match the class.... I reproduced the problem with a dummy class. Running DUMMY d = new DUMMY('blah') produced : DUMMY d = new DUMMY('blah') 1 compilation...

Passing a JSON object to Datasnap Server application

Image
Clash Royale CLAN TAG #URR8PPP Passing a JSON object to Datasnap Server application I have a datasnap application server and a client witten in Delphi Tokyo 10.2. I need to know whether I do the communication between the two correctly. I will write down the client code here : Client Code: procedure TRemoteAcessModule.InitialiseRESTComponents(BaseURL: string); var ReqParam : TRESTRequestParameter; begin //URL to which client has to connect RESTClient1.BaseURL := BaseURL;//'http://192.168.110.160:8080/datasnap/rest/TserverMethods1'; RESTClient1.Accept:= 'application/json, text/plain; q=0.9, text/html;q=0.8,'; RESTClient1.AcceptCharset := 'UTF-8, *;q=0.8'; RESTRequest1.Client := RESTClient1; RESTRequest1.Response := RESTResponse1; RESTResponse1.RootElement := 'Rows'; RESTResponseDataSetAdapter1.Response := RESTResponse1; RESTResponseDataSetAdapter1.Dataset := FDMemTable1; RESTResponseDataSetAdapter1.NestedElements := true; end; class function TIt...

Does Spring Transaction management close related connection?

Image
Clash Royale CLAN TAG #URR8PPP Does Spring Transaction management close related connection? Does @Transactional annotation close Session and SessionFactory connection or we need to close it manually? By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Space delimiter in CSV import to Python

Image
Clash Royale CLAN TAG #URR8PPP Space delimiter in CSV import to Python I know there are more than a few questions regarding space delimiters in CSV files. I have a CSV file that appears to be separated by a space. When importing to Python, I have tried every code out there to identify space as a delimiter. However, I keep getting error messages. For example: test_filepath = 'test_data.csv' with codecs.open(test_filepath, "r", "Shift-JIS", "ignore") as file: # import UTF8 based csv file test_df = pd.read_table( file, delim_whitespace=True ) this yields the following error: EmptyDataError: No columns to parse from file when I try this: test_filepath = 'test_data.csv' with codecs.open(test_filepath, "r", "Shift-JIS", "ignore") as file: # import UTF8 based csv file test_df = pd.read_table( file, delimiter=" " ) it gives the same error. when i try this: test_filepath = 'test_data....

Using nested apply functions instead of nested for loops

Image
Clash Royale CLAN TAG #URR8PPP Using nested apply functions instead of nested for loops My objective here was to iterate across each column in a df and then for each column iterate down each row and perform a function. The specific function in this case replaces the NA values with the corresponding value in the final column, but the details of the function required are not relevant to the question here. I got the results I needed using two nested for loops like this: df NA for (j in 1:ncol(df.i)) { for (i in 1:nrow(df.i)) { df.i[i,j] <- ifelse(is.na(df.i[i,j]), df.i[i,39], df.i[i,j]) } } However, I believe this should be possible using an apply(df.i, 1, function) nested within an apply(df.i, 2, function) But I'm not totally sure that is possible or how to do it. Does anyone know how to achieve the same thing with a nested use of the apply function? apply(df.i, 1, function) apply(df.i, 2, function) apply ifelse is a vectorized function, s...

fatal error LNK1104 'libboost_date_time_vc110-mt-gd-1.51.lib'

Image
Clash Royale CLAN TAG #URR8PPP fatal error LNK1104 'libboost_date_time_vc110-mt-gd-1.51.lib' I am trying to build a program made by someone else (VS2012) on visual studio 2017 and this isn't working. 1>LINK : fatal error LNK1104: cannot open file 'libboost_date_time-vc110-mt-gd-1_51.lib' I'm not even sure why it is searching for this file specifically, besides all the files are -vc141- and not -vc110- . Is there any way to specify to look for any libboost_xxxx_-vc141-xxxx.lib ? Is there any reason why it is searching for another vc format? I've checked the project's properties in C++General->Additionnal include directories , LinkerGeneral->Additional Library Directories and LinkerInput->additionnal dependencies and nothing mentions vc110 . -vc141- -vc110- libboost_xxxx_-vc141-xxxx.lib C++General->Additionnal include directories LinkerGeneral->Additional Library Directories LinkerInput->additionnal dependencies vc110 ...

WebAPI routing does not work

Image
Clash Royale CLAN TAG #URR8PPP WebAPI routing does not work I have WebApiConfig public static class WebApiConfig { public static void Register(HttpConfiguration config) { config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); } } Web API controller: [RoutePrefix("api/Trip")] public class TripApiController : ApiController { [Route("SaveRouting")] [HttpPost] public async Task<HttpResponseMessage> SaveRouting(string points, int tripId, decimal totalMileage) { // ...... return Request.CreateResponse(HttpStatusCode.OK); } and call from jquery: $.post("/api/trip/SaveRouting", { points: JSON.stringify(arrayStops), tripId: $("#hdTripId").val(), totalMileage: tMiles }, fu...

Casting an object to a IList with an abstract type parameter

Image
Clash Royale CLAN TAG #URR8PPP Casting an object to a IList with an abstract type parameter In my code, I have an object: object obj = ... Which I know is of type MyListType, where MyListType is a subclass of IList and T is a subclass of MyAbstractClass. The type parameter of MyListType is constrained so that it is always a subclass of MyAbstractClass. However, trying to cast obj MyListType<MyAbstractClass> myList = (MyListType<MyAbstractClass>)obj; gives a runtime error. I tried to define an explicit operator public static explicit operator MyListType<MyAbstractClass>(MyListType<T> list) { MyListType<MyAbstractClass> newList = new MyListType<MyAbstractClass>(); foreach(T t in list) newList.Add((MyAbstractClass) t); return newList; } However, this operator doesn't get used by the cast since obj is an object, not a MyListType. Is there a workaround to successfully perform this cast? I've looked at this question, but their t...

I don't understand JWT refresh token's behaviour (LARAVEL)

Image
Clash Royale CLAN TAG #URR8PPP I don't understand JWT refresh token's behaviour (LARAVEL) I have just tried JWT auth with LARAVEL and this https://github.com/tymondesigns/jwt-auth But there's something i can't understand. In their config they put : 'ttl' => env('JWT_TTL', 60), // in munutes 'refresh_ttl' => env('JWT_REFRESH_TTL', 20160), // in minutes What i understant : the token's live is 1hour and can be refreshed within 2 weeks But after 3hours, if i try to query something, it says "token expired". Does this system mean, a user must get his token updated / refreshed within every hour but with a limit of 2 weeks ? I don't get it. How can a user persist login with this kind of system ? How is the refresh Token useful when after the first hour, though it hasn't been 2 weeks yet, i can't get a fresh token ? thanks UPDATE: CODE config/jwt.php 'ttl' => 2, // 2 minutes 'refresh_ttl' => 5,...

Upload files into SFTP server using PHP

Image
Clash Royale CLAN TAG #URR8PPP Upload files into SFTP server using PHP This is my first time using sftp, and I'm stuck "This was pedictable"...I have a csv file dowloanded via web browser into my Downloads Directory using a "Webservice" permetting such thing, and I wanna upload this file into a sftp server. I've tried many codes that I've found here or on other websites but none of them worked. Here is two examples of codes I tried to run: FISRT EXAMPLE: <?php $ftp_server = 'example.server.net'; // Address of FTP server. $ftp_user_name = 'username'; // Username $ftp_user_pass = 'password'; // Password $destination_file = "serverpath"; //where you want to throw the file on the webserver (relative to your login dir) $conn_id = ftp_connect($ftp_server,22) or die("<span style='color:#FF0000'> <h2>Couldn't connect to $ftp_server</h2></span>"); //set up basic connection $login_r...