Posts

Showing posts from September 6, 2018

Laravel Display table product if not exist on quantity table

Image
Clash Royale CLAN TAG #URR8PPP Laravel Display table product if not exist on quantity table In PHP-MySQL I can create this query... $sql = "SELECT * FROM product"; $result = $conn->query($,con, $sql); while($row =mysql_fetch_array($result)) $sqlquantity = "SELECT * FROM quantity where branchid='4' and productid='$row['productid']'"; $resultquantity = $conn->query($,con, $sqlquantity); if (mysqli_num_rows($resultquantity) == 0) echo $row['productname']. "not available in branch" else echo $row['productname']. "available in branch" But how can I do this using Laravel? I have 3 tables +-----------------+ +-----------------+ +----------------+ | product table | | quantity table | | branch table | +-----------------+ +-----------------+ +----------------+ | id | | productid | | id | | productname | | branchid | | branchname | +-----------------+ | quantity | +----------------+ +---------...

CsvHelper, writing dynamic variable names (c#)

Image
Clash Royale CLAN TAG #URR8PPP CsvHelper, writing dynamic variable names (c#) Assume want to write bank user account details in a following csv file format. AccountId, Name, Jan, Feb, Mar ........... Dec 1, Anne, 1000.00, 400.00, 500.00 .......... 200.00 2, John, 900.00, 400.00, 500.00 .......... 1200.00 3, Brit, 600.00, 400.00, 500.00 .......... 2200.00 To represent this above data structure I have following model class: class AccountBalance int ID get; set; ; string Name get; set; ; List<string> lastTwelveMonths get; set; ; My Code is to write csv is: using (var stream = new MemoryStream()) using (var streamWriter = new StreamWriter(stream)) using (var stringWriter = new StringWriter()) using (var csvWriter = new CsvWriter(stringWriter)) csvWriter.WriteRecords(listOfAccountBalances); streamWriter.Write(stringWriter.GetStringBuilder()); streamWriter.Flush(); stream.Position = 0; return stream.ToArray(); But above code will not give exact output when it comes to lis...

How to use something like s.end() in for loop with auto?

Image
Clash Royale CLAN TAG #URR8PPP How to use something like s.end() in for loop with auto? I have a below program, I want to see how to condition on last element in the container when using auto in C++11, that's why this question. #include <iostream> #include <set> using namespace std; void show(set<string>& s) cout << "<"; for (const auto &e: s) if (e != s.end()) // This is WRONG -- results in compilation error !! cout << e << ","; else cout << e; cout << ">" << endl; int main(int argc, char *argv) set <string> s = "a", "e", "i", "o" ; show(s); return 0; above program outputs <a,e,i,o,> <a,e,i,o,> I tried to use s.end() in the for loop in the show() , but compilation fails. s.end() for show() desired output : <a,e,i,o> I am currently developing a library that allows to simply write something like std::cop...

VBA Format function, custom format to set numbers as millions with one DP not working

Image
Clash Royale CLAN TAG #URR8PPP VBA Format function, custom format to set numbers as millions with one DP not working I am running some VBA in Excel 2010 to output numbers from tables within my spreadsheet to an external PowerPoint presentation. Because of the variety of numbers involved, I am using custom formatting strings specified in the tables which the macro is reading to determine the output format like so: CellData = Format(SourceData,FormattingCode) I have been able to get this to work with little difficulty for numbers in millions (0,,) and percentages (0.0%). However, I now want to do numbers in millions but displaying one decimal place, that is 1,200,000 should render as 1.2 The format code for doing this normally is (0.0,,) which I can see works in the normal cell formatting settings. However, when I pass this to the format function, I get the number to one decimal place unrounded with no separators like 1200000.0. Any idea why this is? I know Format function is slight...

using if statements and icons in flutter

Image
Clash Royale CLAN TAG #URR8PPP using if statements and icons in flutter i have an if statement and I want to set two conditions inside it as the following code shows: if (subtitle !="you are currently not signed in" && Icon==Icons.bookmark_border) ..... but I cant do so since it is giving the following error "equality operator == invocation with reference of unrelated types". Any idea about how to implement this what is the value of "Icon" var ? – diegoveloper Aug 10 at 16:22 Use IconData instead of Icon. Also what is your variable here that you are trying to compare to Icons.bookmark_border? – Vikas Pandey Aug 10 at 16:22 i have future builder that returns 2 widgets ,one is bookmark and other is bookmark border icon, i want to set them into variables and put them into if statement.@VikasPandey – serjo macken Aug 10 at 21:26 2 Answers 2 In your case Icon is a type. You cannot compare a type with an object ( Icons...

SSMS Results to Grid - CRLF not preserved in copy/paste - any better techniques?

Image
Clash Royale CLAN TAG #URR8PPP SSMS Results to Grid - CRLF not preserved in copy/paste - any better techniques? When I have a result set in the grid like: SELECT 'line 1 line 2 line 3' or SELECT 'line 1' + CHAR(13) + CHAR(10) + 'line 2' + CHAR(13) + CHAR(10) + 'line 3' With embedded CRLF, the display in the grid appears to replace them with spaces (I guess so that they will display all the data). The problem is that if I am code-generating a script, I cannot simply cut and paste this. I have to convert the code to open a cursor and print the relevant columns so that I can copy and paste them from the text results. Is there any simpler workaround to preserve the CRLF in a copy/paste operation from the results grid? The reason that the grid is helpful is that I am currently generating a number of scripts for the same object in different columns - a bcp out in one column, an xml format file in another, a table create script in another, etc... +1 T...

How to reference java.sql from a Scala Script without encountering SecurityException?

Image
Clash Royale CLAN TAG #URR8PPP How to reference java.sql from a Scala Script without encountering SecurityException? Since Java 9, calling objects defined in java.sql from within Scala throw a java.lang.SecurityException when used directly from a scala script. Java Version: 10.0.1 Scala Version: 2.12.4 sbt Version: 1.2.0 The below screenshot is an entire minimum working example, with console output for a working and non-working version. Specifically: copying the script code into a class, and running it from that class, resolves the issue. Is there a way to write a Scala script that directly uses objects from java.sql ? java.sql build.sbt build.sbt name := "mypackage" version := "0.1" scalaVersion := "2.12.4" libraryDependencies += "org.postgresql" % "postgresql" % "42.2.4" broken-script.scala broken-script.scala import java.sql.Connection, DriverManager import java.util.Properties object Main private def url = "jdbc...

The origin server did not find a current representation for the target resource or is not willing to disclose that one exists. Error when starting app

Image
Clash Royale CLAN TAG #URR8PPP The origin server did not find a current representation for the target resource or is not willing to disclose that one exists. Error when starting app package controller; import domain.PersonService; import domain.ProductService; import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.ArrayList; import java.util.List; @WebServlet("/Controller") public class Controller extends HttpServlet private static final long serialVersionUID = 1L; private PersonService model = new PersonService(); private ProductService productModel = new ProductService(); private ControllerFactory controllerFactory = new ControllerFactory(); private BlogServer server = new BlogServer(model); public Controller() super(); ...

How can I remove all trailing backslashes from a string in Scala?

Image
Clash Royale CLAN TAG #URR8PPP How can I remove all trailing backslashes from a string in Scala? I want to remove all trailing backslashes ( '' ) from a string. '' For example: "ab" -> "ab" "ab\\" -> "ab" "\\ab\" -> "\\ab" "\" -> "" I am able to do this using below code but unable to handle the scenario where the String has only slash(es). Please let me know if this can be achieved through a different regex. val str = """\\q\""" val regex = """^(.*[^\])(\+)$""".r str match case regex(rest, slashes) => str.stripSuffix(slashes) case _ => str Try: str.replaceFirst("\\+$", ""); – anubhava Aug 10 at 15:07 str.replaceFirst("\\+$", ""); Maybe add this as an answer ? Seems great :-) – C4stor Aug 10 at 16:06 @anubhava, it works. Guess you don't need any more...

How do I configure multiple dictionary keys in a yaml file in Python?

Image
Clash Royale CLAN TAG #URR8PPP How do I configure multiple dictionary keys in a yaml file in Python? I am trying to use a yaml file to store dictionary keys so I can parse various json payloads. I have the following yaml file loaded into a variable called 'cfg': my_table: metadata When I run: for i in json['resources']: print(i[cfg['my_table']]) I can see all values from my json's ['metadata'] keys just fine. However, I would like to see all values from the ['metadata']['guid'] keys that exist under ['resources']. So when I change my yaml file to: my_table: metadata, guid It doesn't work. I've also tried these variations: my_table: ['metadata', 'guid'] #tried ''.join("['0']".format(a) for a in cfg['my_table']) which gives me what I want, but when I shove this inside i, I get a key error my_table: ['metadata']['guid'] #yaml file doesn't parse...

Conditional If statements with decimal constaints

Image
Clash Royale CLAN TAG #URR8PPP Conditional If statements with decimal constaints Say I have a condition that if a number ends with.00 add 2 to it and if a number ends with.99 add 3 to it. So if I had 5.00 and 5.99, I want to write a nested if statement that would allow me to add the right value to the original number based on its ending. could someone please help me out on how to do that in R (or python) what do you mean by right value? so do you need 7.00 and 8.99 as your answer? – Onyambu Aug 10 at 16:01 What form is your number in? Note that if it's a float, your representation is not guaranteed to have the exact value that you expect. – Prune Aug 10 at 16:05 @onyambu, by "right value" I meant adding the corresponding value, so either the 2 or the 3 based on the ending of the original number. – Ef. O Aug 10 at 16:20 4 Answers 4 Due to floating point precision, you will need to round your numbers to two decimals as values s...

IntelliJ IDEA Test Coverage window doesn't show

Image
Clash Royale CLAN TAG #URR8PPP IntelliJ IDEA Test Coverage window doesn't show I'm using Spring Boot project with the last version of IntelliJ IDEA (2018.2.1 Ultimate Edition). When I run all my test with coverage the Coverage window doesn't show, and there's no percentage beside my main classes. I've tried enabling the coverage window by going to View -> Tool Windows -> Coverage , but the coverage tab is disabled (not clickable). View -> Tool Windows -> Coverage If I remember correctly the coverage was working fine before I update IntelliJ. Is that a bug with the last version ? Edit the coverage plugin is already installed Try to reinstall Intellij IDEA. When installing, he asks about install the "Coverage" plugin. – Dherik Aug 10 at 16:19 If it's a matter of the plugin not being installed, you don't have to reinstall the IDE to solve it...just install the plugin. – ChiefTwoPencils Aug 10 at 16:28 @ChiefTwoPenc...

CKEditor TypeError: c[a] is undefined in CodeIgniter

Image
Clash Royale CLAN TAG #URR8PPP CKEditor TypeError: c[a] is undefined in CodeIgniter Im trying to install CKEditor in my codeigniter based website and I have followed this tutorial: CKEditor in Codeigniter Tutorial But Im receiving this error: TypeError: c[a] is undefined TypeError: c[a] is undefined CKEDITOR.lang.load/d() ckeditor___ckeditor:230 CKEDITOR.scriptLoader</<.load/f() ckeditor___ckeditor:231 CKEDITOR.scriptLoader</<.load/x() ckeditor___ckeditor:231 CKEDITOR.scriptLoader</<.load/A() ckeditor___ckeditor:231 CKEDITOR.scriptLoader</<.load/u/g.$.onerror() The folder which ckeditor folder is in: assets/js/ ( which will be: assets/js/ckeditor/ ) The CKEDITOR_BASEPATH is CKEDITOR_BASEPATH = 'http://localhost:5678/assets/js/ckeditor/'; CKEDITOR_BASEPATH = 'http://localhost:5678/assets/js/ckeditor/'; I have no idea what this error is and I can't find properly answers or fix to it. Thanks in advance. Hey that tutorial is years old -...