Working with code generated by Simulink model

Uncategorized
Question: I am trying to use a code which was generated by Simulink model (MATLAB). What I have is:1. Many .h files, all with definitions of structs:typedef struct {...} 2. .lib files. There are no functions in the .h files, only typdefs. There are two "special" typedefs; one is called 'input' and the other 'output'. My question is this: I have no idea how to operate this code. I want to use it from c++ or c# module, but I can't find how. Any references/help will be welcomed. Answer: Read more
Read More

How to get response headers from iron-form Polymer

Uncategorized
Question: I have a form, which I submit like so:form.addEventListener("iron-form-response", function(event) { //How can I access response headers here? }); form.submit(); I know the way I can access response body:event.detail.response But what I want is server response headers. I need it, because this response may contain in headers some tokens, which I must store in cookies. Answer: The event.detail is actually an , which exposes the underlying XMLHTTPRequest via e.detail.xhr, which allows you to use getResponseHeader(name) for a specific header:_onResponse(e) { const header = e.detail.xhr.getResponseHeader('X-Special-Header'); ... } Example: My name Submit demo Read more
Read More

Solr calculate last day of month

Uncategorized
Question: I am building a Solr Index where data has date I need to calculate a field if date was last day of month? I would prefer if I can do It at query time, tried few things unsuccessfully any ideas Answer: if you mean 'a field that says if the date in another field is the last day of THAT month', then it makes much more sense to do it at index time:it will be more performant, you index it as a boolean, and no calculation needs to happen at query time, just matching it you have several of ways to compute it: at the client side (the easiest), in a UpdateRequestProcessor, tansformer if you are doing DIH, maybe some crazy regex can do it in a copyfield... Read…
Read More

Parse XML file using Python script

Uncategorized
Question: I am trying to fetch summary from ncbi Eutilities(esummary) using python script.But I am unable to fetch the data that I need Xml Input 21071030 NP_570602 alpha-1B-glycoprotein precursor [Homo sapiens] gi|21071030|ref|NP_570602.2|[21071030] 21071030 2002/02/092017/05/20 512 9606 495 live NP_570602.2 Expected output alpha-1B-glycoprotein precursor [Homo sapiens] Answer: Read more
Read More

What is the best way to execute javascript for a custom widget in Vaadin 8?

Uncategorized
Question: I have a custom widget that needs further initialization after the DOM elements have been created. What is the best way to do this? Assume that the javascript is in a js file. DOM ready can't be used because Vaadin is a single page application. @Javascript annotation loads the js file before the DOM has been fully created. Answer: Read more
Read More

Android wifi hotspot connected but not able to access internet

Uncategorized
Question: May be something is wrong on my mobile or linux. following is the output of some commands. $ iwconfig eth0 no wireless extensions. lo no wireless extensions. wlan0 IEEE 802.11abg ESSID:"Honor 6X_4E35" Mode:Managed Frequency:2.462 GHz Access Point: 31:74:92:B5:39:69 Retry long limit:7 RTS thr:off Fragment thr:off Power Management:off $ cat /etc/network/interfaces # interfaces(5) file used by ifup(8) and ifdown(8) auto lo iface lo inet loopback $ lspci -nnk| grep -iA2 net 12:00.0 Network controller [0280]: Broadcom Corporation BCM4313 802.11bgn Wireless Network Adapter [14e4:4727] (rev 01) Subsystem: Dell Inspiron M5010 / XPS 8300 [1028:0010] Kernel driver in use: wl 13:00.0 Ethernet controller [0200]: Qualcomm Atheros AR8152 v2.0 Fast Ethernet [1969:2062] (rev c1) Subsystem: Dell Device [1028:0466] Kernel driver in use: atl1c any idea, please suggest? Answer: Read more
Read More

Is floating point math broken?

Uncategorized
Question: 0.1 + 0.2 == 0.3 -> false 0.1 + 0.2 -> 0.30000000000000004 Why does this happen? Answer: Binary floating point math is like this. In most programming languages, it is based on the IEEE 754 standard. JavaScript uses 64-bit floating point representation, which is the same as Java's double. The crux of the problem is that numbers are represented in this format as a whole number times a power of two; rational numbers (such as 0.1, which is 1/10) whose denominator is not a power of two cannot be exactly represented. For 0.1 in the standard binary64 format, the representation can be written exactly as 0.1000000000000000055511151231257827021181583404541015625 in decimal, or 0x1.999999999999ap-4 in C99 hexfloat notation. In contrast, the rational number 0.1, which is 1/10, can be written exactly as 0.1…
Read More

Itext How to set both UTF encoding and Font to a Paragraph

Uncategorized
Question: I want to set a font to a text that is in cyrillic.I successfully convert the text to cyrilic, but i cannot set a Font to the same text. File fontFile = new File("arialuni.ttf"); Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT)); document.open(); writer.getAcroForm().setNeedAppearances(true); Font boldFont = new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD); Font normalFont = new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.ITALIC); BaseFont unicode = BaseFont.createFont(fontFile.getAbsolutePath(), BaseFont.IDENTITY_H, BaseFont.EMBEDDED); FontSelector fs = new FontSelector(); fs.addFont(new Font(unicode)); addContent(document,article.getTitle(),fs,boldFont); private static void addContent(Document document,String paragraph,FontSelector fs,Font font) throws DocumentException { Phrase phrase = fs.process(paragraph); Paragraph p = new Paragraph(phrase.toString(),font); document.add(p); } Answer: Read more
Read More

422 Not returning send message(Node.js/Redux)

Uncategorized
Question: I am having an issue where my node.js server is returning a 422 to the browser with a message but the browser is just seeing the 422 and nothing with it. //Node.js if (existingUser) { return res.status(422).send({ error: 'Email is in use' }); } I can confirm it is hitting there and returning at that point //Redux method export function signupUser({ email, password }) { return function(dispatch) { return axios.post(`${ROOT_URL}/signup`, { email, password }) .then(response => { dispatch(emailWasSent(response.data.return_msg)); }) .catch(response => { dispatch(authError(response.data.error));}); } } It will hit the catch but the response only contains 422 //Console.log of response Error: Request failed with status code 422 Answer: Read more
Read More

API assertion failure message to be displayed in my testNG report

Uncategorized
Question: I am having multiple assertions (assertTrue) in my test method, I want to pass the assertion failure to my @AfterMethod on which ever assertion my test failed so that I can get the exact location where my API test failed. Is there any way to achieve this? Using Rest assured, Maven & TestNG. Answer: Every @AfterMethod can accept a ITestResult as a parameter, which TestNG during execution natively injects the test result of the last @Test. So you can examine the ITestResult object and then proceed further. Here's a simple sample import org.testng.Assert; import org.testng.ITestResult; import org.testng.annotations.AfterMethod; import org.testng.annotations.Test; import java.io.PrintStream; import java.io.PrintWriter; import java.io.StringWriter; public class SampleTestClass { @Test public void passMethod() { Assert.assertTrue(true); } @Test public void failMethod() { Assert.assertTrue(false); } @AfterMethod public void afterMethod(ITestResult testResult) {…
Read More

Train a SVM (Support Vector Machine) classifier with Scikit-learn

Uncategorized
Question: I want to train different classifier with using Scikit-learn with following code:names = [ "Nearest Neighbors", "Linear SVM", "RBF SVM", "Gaussian Process", "Decision Tree", "Random Forest", "Neural Net", "AdaBoost", "Naive Bayes", "QDA"] classifiers = [ KNeighborsClassifier(3), SVC(C=0.025), SVC(gamma=2, C=1), GaussianProcessClassifier(1.0 * RBF(1.0)), DecisionTreeClassifier(max_depth=5), RandomForestClassifier(max_depth=5), MLPClassifier(alpha=0.5), AdaBoostClassifier(), GaussianNB(), QuadraticDiscriminantAnalysis()] for name, clf in izip(names, classifiers):clf.fit(X_train, Y_train) score = clf.score(X_train, Y_test) print name, score KNeighbors classifier works properly but when I reach to the SVM classifier it throws following exception:Traceback (most recent call last):File "/Users/mac/PycharmProjects/GraphLstm/classifier.py", line 87, in clf.fit(X_train, Y_train) File "/Library/Python/2.7/site-packages/sklearn/svm/base.py", line 151, in fit X, y = check_X_y(X, y, dtype=np.float64, order='C', accept_sparse='csr') File "/Library/Python/2.7/site-packages/sklearn/utils/validation.py", line 526, in check_X_y y = column_or_1d(y, warn=True) File "/Library/Python/2.7/site-packages/sklearn/utils/validation.py", line 562, in column_or_1d raise ValueError("bad input shape {0}".format(shape)) ValueError: bad input shape (9280, 39)…
Read More