|
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. |
On October 08 2016 06:56 Acrofales wrote:Show nested quote +On October 08 2016 05:07 Prillan wrote:On October 06 2016 02:05 Acrofales wrote:On October 06 2016 01:44 spinesheath wrote: OOP and functional are not mutually exclusive. I think Robert C. Martin once put it like that: Structured programming is the removal of GOTO. Object oriented programming is the removal of function pointers. Functional programming is the removal of assignments.
All of these can be integrated into a single language, and many functional languages already are both structured and object oriented. Support for functional programming in the OOP languages like C# is still limited (afaik we don't have much in the way of optimizations for recursion yet), but it's getting better.
The future will be FP + OOP, not either of these. many scripting languages (python, ruby, perl, php) have functional and oop aspects. In fact, Haskell, one of the ur-languages for functional programming, is at core a scripting language, and it has its own weird idea of objects (monads). Functional aspects are being increasingly adopted into classical OOP languages. The future is very much a mix, and probably some further innovation that I don't even know about yet. How is Haskell a scripting language? Also, in what way are monads similar to objects? Hugs, turtle, plenty of engines that allow for scripting in Haskell. As for monads and objects, I got a bit enthusiastic there. While they overlap in some of their purposes, they work completely differently and have different foundations, so disregard that bit.
Of course, turtle is a nice library you can use, but I wouldn't say "is at core a scripting language". That part really confused me.
|
my java program has an action listener it has some text fields
then i hit a button and it does calculations on numbers
what would I need to do to check for input that isn't numbers? like characters or null?
throw an illegal argument exception?
If so, how do I go about checking if it isn't a number?
edit:
should I check to see if the fields are "> 0", which will throw some sort of exception if they aren't?
edit 2:
This is what I did
try { principleF = Float.parseFloat(principle.getText()); rateF = Float.parseFloat(rate.getText()); yearF = Float.parseFloat(year.getText()); } catch (NumberFormatException e) { System.out.println("Please enter numbers into the fields"); }
|
On October 08 2016 05:56 mantequilla wrote: thanks for answering but it's not the problem of separate trial and full versions continuously deployed.
I want to deploy the same thing, with may be a few configs changed, numerous times. Like say today 10 people requested trials, and 5 people bought my app, I need 15 different instances with different url's (app1.com, app2.com ...), different databases, but its the same app, same code.
There's a resource management template concept in azure, but that only describes the architecture (tomcat+mysql). It doesn't describe what will be uploaded to where, with which config.
Imagine 10 people bought your app today, from your company's website. There should be a mechanism that deploys and configures your app for each of them. Ok I see, you're actually trying to find a good system for deploying separate whitelabeled instances of your app?
|
@travis: One thing you could do is use Spinners or FormatedTextFields instead of regular TextFields. With Spinners and FormattedTextFields you can decide which inputs are possible and which arent. A Spinner with a SpinnerNumberModel for example can be configured in a way that only doubles can be entered. Anything that is not a double will not be accepted by the Spinner.
But if you really have to stick to regular old JTextField then your current approach is okay. Instead of printing the error to console however you might want to have a pop-up dialog appear with the error message. The easiest way to do this is to use the JOptionPane. Its a horrible class from a design perspective but it is quite useful to get fast acceptable results.
Example:
try { principleF = Float.parseFloat(principle.getText()); rateF = Float.parseFloat(rate.getText()); yearF = Float.parseFloat(year.getText()); } catch (NumberFormatException e) { JOptionPane.showMessageDialog(principle, "Please enter numbers into the fields", "Error - Invalid Input", JOptionPane.ERROR_MESSAGE); }
Edit: I assume you use Swing. If you use JavaFX or some other GUI library (SWT, etc) then the above will obviously not work. Spinners however should be available in any GUI library.
|
On October 08 2016 08:09 phar wrote:Show nested quote +On October 08 2016 05:56 mantequilla wrote: thanks for answering but it's not the problem of separate trial and full versions continuously deployed.
I want to deploy the same thing, with may be a few configs changed, numerous times. Like say today 10 people requested trials, and 5 people bought my app, I need 15 different instances with different url's (app1.com, app2.com ...), different databases, but its the same app, same code.
There's a resource management template concept in azure, but that only describes the architecture (tomcat+mysql). It doesn't describe what will be uploaded to where, with which config.
Imagine 10 people bought your app today, from your company's website. There should be a mechanism that deploys and configures your app for each of them. Ok I see, you're actually trying to find a good system for deploying separate whitelabeled instances of your app?
His problem is how to do the automation of this. His customers will be able to customize and order something from his webpage, and then a VM has to be created on Microsoft's Azure for the customer. He is searching for how to deal with Azure through a script or whatnot, from the webpage running on his Unix stuff, and Azure running on Microsoft's servers that are Windows.
|
Yup, gotcha. But the terminology for what he's looking for has much less to do with deployment, and much more to do with whitelabeling. Might help the search.
|
@travis: your current approach is OK, but remember back when you were asking about exceptions, and people told you not to rely on them for the logic of your program, because it will be slow? That still applies. Checking if a string is a number is really easy with a regular expression: s.matches("-?\\d+(\\.\\d+)?") should work to start with. There's also NumberFormat, which might be more generic.
|
On October 08 2016 10:59 Acrofales wrote: @travis: your current approach is OK, but remember back when you were asking about exceptions, and people told you not to rely on them for the logic of your program, because it will be slow? That still applies. Checking if a string is a number is really easy with a regular expression: s.matches("-?\\d+(\\.\\d+)?") should work to start with. There's also NumberFormat, which might be more generic. But your regular expression does not do the same thing as parsing a double and checking for an exception. Here is the official JavaDoc for the valueOf(String) method from class Double: https://docs.oracle.com/javase/7/docs/api/java/lang/Double.html#valueOf(java.lang.String)
The doc contains an example of how to construct a correct regex:
final String Digits = "(\\p{Digit}+)"; final String HexDigits = "(\\p{XDigit}+)"; // an exponent is 'e' or 'E' followed by an optionally // signed decimal integer. final String Exp = "[eE][+-]?"+Digits; final String fpRegex = ("[\x00-\\x20]*"+ // Optional leading "whitespace" "[+-]?(" + // Optional sign character "NaN|" + // "NaN" string "Infinity|" + // "Infinity" string
// A decimal floating-point string representing a finite positive // number without a leading sign has at most five basic pieces: // Digits . Digits ExponentPart FloatTypeSuffix // // Since this method allows integer-only strings as input // in addition to strings of floating-point literals, the // two sub-patterns below are simplifications of the grammar // productions from section 3.10.2 of // The Java™ Language Specification.
// Digits ._opt Digits_opt ExponentPart_opt FloatTypeSuffix_opt "((("+Digits+"(\\.)?("+Digits+"?)("+Exp+")?)|"+
// . Digits ExponentPart_opt FloatTypeSuffix_opt "(\\.("+Digits+")("+Exp+")?)|"+
// Hexadecimal strings "((" + // 0[xX] HexDigits ._opt BinaryExponent FloatTypeSuffix_opt "(0[xX]" + HexDigits + "(\\.)?)|" +
// 0[xX] HexDigits_opt . HexDigits BinaryExponent FloatTypeSuffix_opt "(0[xX]" + HexDigits + "?(\\.)" + HexDigits + ")" +
")[pP][+-]?" + Digits + "))" + "[fFdD]?))" + "[\x00-\\x20]*");// Optional trailing "whitespace"
if (Pattern.matches(fpRegex, myString)) Double.valueOf(myString); // Will not throw NumberFormatException else { // Perform suitable alternative action } The code above is perhaps not the fastest, I believe they valued readability over performance. I think the solution using parseString could very well be the best way of doing this even though it is a bad practice. It is unfortunate that some of the java core classes work this way.
|
On October 08 2016 10:59 Acrofales wrote: @travis: your current approach is OK, but remember back when you were asking about exceptions, and people told you not to rely on them for the logic of your program, because it will be slow? That still applies. Checking if a string is a number is really easy with a regular expression: s.matches("-?\\d+(\\.\\d+)?") should work to start with. There's also NumberFormat, which might be more generic.
The thing about using a regex is that using an exception isn't that slow if the exceptional path isn't taken often (that is to say, using an exception doesn't slow down the happy path). Now in no way am I saying use exceptions in the general case, but based on what the Java standard library provides I *highly* recommend using parseXXX and catching Exception, it is more idiomatic based on Java standard library and faster than a simple regex. Plus you probably will fuck up regex unless you copy super long one (for example that regex rejects "100." or other locale formatting where "," is decimal seperator). See this answer http://stackoverflow.com/a/28075127 (I avoided top since I gave up trusting Java benchmarks without JMH from people I don't know tbh).
Obviously there are cases to sit down and think how do I avoid exception (in which case bringing in regex probably isn't the answer anyway...see the actual parseDouble http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/8u40-b25/sun/misc/FloatingDecimal.java#FloatingDecimal.readJavaFormatString(java.lang.String)).
For example see this benchmark comparing incorrect regex, try/catch, and some SO answer https://gist.github.com/anonymous/8ed6df7b5297151b7ff545ef25011798. Also this doesn't even have other methods feed you an integer at end of it.
|
On October 08 2016 08:24 Ropid wrote:Show nested quote +On October 08 2016 08:09 phar wrote:On October 08 2016 05:56 mantequilla wrote: thanks for answering but it's not the problem of separate trial and full versions continuously deployed.
I want to deploy the same thing, with may be a few configs changed, numerous times. Like say today 10 people requested trials, and 5 people bought my app, I need 15 different instances with different url's (app1.com, app2.com ...), different databases, but its the same app, same code.
There's a resource management template concept in azure, but that only describes the architecture (tomcat+mysql). It doesn't describe what will be uploaded to where, with which config.
Imagine 10 people bought your app today, from your company's website. There should be a mechanism that deploys and configures your app for each of them. Ok I see, you're actually trying to find a good system for deploying separate whitelabeled instances of your app? His problem is how to do the automation of this. His customers will be able to customize and order something from his webpage, and then a VM has to be created on Microsoft's Azure for the customer. He is searching for how to deal with Azure through a script or whatnot, from the webpage running on his Unix stuff, and Azure running on Microsoft's servers that are Windows.
yes this. The problem is not about azure being windows (azure has linux vm's too) and my site running on unix. Problem is finding a way to automate through a script or whatnot.
There's an api inside azure sdk about creating vm's but there's another problem. If you build a vm from scratch you have to take care of everything installed on it, meaning IaaS (you are just renting hardware). There are things called "app services" on azure, which are preconfigured PaaS solutions, like a preconfigured MySQL server, which publishers take care of it. I don't know if a VM created by you and a MySQL app service is equivalent.
|
c++ std::string::operator+=
string test("Aha"); char exclamation='!';
test += ", it was you"+exclamation;
test += ", it was you"; test += exclamation;
Any Ideas why putting it on one line throws an exception for me? edit: Found the answer in the primer:
When we mix strings and string or character literals, at least one operand to each + operator must be of string type in case anyone, wonders.
|
hey guys, i need some general advice for how to go on with my table tennis exercise project:
i want to code a site where you can 1) draw arrows on tables and add a bit of text to make it look similiar to this: 2) then the user can save this on the server to restore it and work on it later 3) the user can print a black and white version of the exercise that is not just the same thing you see in the browser, but with different styles applied (other colors for the table and arrows,maybe more things)
i implemented 1) already with canvas and javascript. how can i add 2) and 3) now? what do i need to do this?
what i thought was to somehow save the mouse interactions and then redraw them when the exercise gets restored. for 3) i have no idea...
also, is it better to use existing user frameworks or can i code a simple user registration and interface better by myself to get what i want?
|
I am not very familiar with canvas, so correct me if I'm wrong, but from what I read, canvas doesn't have semantic information about a rectangle, arrow, circle etc, after they are drawn. Like when you draw a rectangle it becomes a bunch of pixels, canvas doesn't know if there's a rectangle on it.
That means you only have to save it as an image and restore it the same way. You would upload it as a file to server, and download it later for editing.
I'd look at those popular canvas libraries, because the vanilla js api doesn't appear to be very capable.
What are you using on the server side?
|
On October 08 2016 16:22 mantequilla wrote:Show nested quote +On October 08 2016 08:24 Ropid wrote:On October 08 2016 08:09 phar wrote:On October 08 2016 05:56 mantequilla wrote: thanks for answering but it's not the problem of separate trial and full versions continuously deployed.
I want to deploy the same thing, with may be a few configs changed, numerous times. Like say today 10 people requested trials, and 5 people bought my app, I need 15 different instances with different url's (app1.com, app2.com ...), different databases, but its the same app, same code.
There's a resource management template concept in azure, but that only describes the architecture (tomcat+mysql). It doesn't describe what will be uploaded to where, with which config.
Imagine 10 people bought your app today, from your company's website. There should be a mechanism that deploys and configures your app for each of them. Ok I see, you're actually trying to find a good system for deploying separate whitelabeled instances of your app? His problem is how to do the automation of this. His customers will be able to customize and order something from his webpage, and then a VM has to be created on Microsoft's Azure for the customer. He is searching for how to deal with Azure through a script or whatnot, from the webpage running on his Unix stuff, and Azure running on Microsoft's servers that are Windows. yes this. The problem is not about azure being windows (azure has linux vm's too) and my site running on unix. Problem is finding a way to automate through a script or whatnot. There's an api inside azure sdk about creating vm's but there's another problem. If you build a vm from scratch you have to take care of everything installed on it, meaning IaaS (you are just renting hardware). There are things called "app services" on azure, which are preconfigured PaaS solutions, like a preconfigured MySQL server, which publishers take care of it. I don't know if a VM created by you and a MySQL app service is equivalent.
You're not asking for a generic problem that is already solved, you're asking for your specific problem with your specific configurations and your specific deployment needs. No one is going to do that job for you, or else they would be getting paid and not you. Your talking about projects that takes months or years to complete and you think someone on the internet is just going to give you a step by step instruction on how to do it? People that know how to do the stuff your talking about get paid six figures plus to figure that stuff out.
I'm not sure why you think that should be "easy".
|
what's too "specific" about automating a web app's deployment? you mean thousands of companies in the world are deploying their web apps to cloud by hand or through homemade solutions they wrote and paying 6 figures to do it? And I am not asking for step by step solutions, just asking what kind of a tool or api or whatever they are using.
|
On October 08 2016 22:01 mantequilla wrote: what's too "specific" about automating a web app's deployment? you mean thousands of companies in the world are deploying their web apps to cloud by hand or through homemade solutions they wrote and paying 6 figures to do it? And I am not asking for step by step solutions, just asking what kind of a tool or api or whatever they are using.
Yes, I think thousands of companies are using pieced together home grown solutions, or they are paying big money to help them through consultants. You aren't just talking about deploying as phar already pointed out. Once you want different configurations and automated rollouts, the orchestration of all of that _is your business value_.
I don't know anything about Azure, as I work with java deployments to linux systems.. but our deployment system has taken years to build and tune to get it to work, and it's not anywhere near as fancy as some of the stuff you are talking about. We're in the process of moving to AWS and in order to get to where we want to go we're getting ready to take about a 1-3 year project to do so because everything is moving towards containers so our old deployment system isn't going to work anymore.
That being said, your ability to parse through and read between the lines of what people are doing could make you a powerful asset to your company. Trust me, I went through a similar path you did, which is why I know it's not easy. Everyone talks about how great it is, but when you look for specifics as to how things were implemented or trying to figure out how all the dots are connected -- no one is talking.
|
On October 08 2016 21:50 mantequilla wrote: I am not very familiar with canvas, so correct me if I'm wrong, but from what I read, canvas doesn't have semantic information about a rectangle, arrow, circle etc, after they are drawn. Like when you draw a rectangle it becomes a bunch of pixels, canvas doesn't know if there's a rectangle on it.
That means you only have to save it as an image and restore it the same way. You would upload it as a file to server, and download it later for editing.
I'd look at those popular canvas libraries, because the vanilla js api doesn't appear to be very capable.
What are you using on the server side?
Is it possible to record what the canvas draws or what I input via mouse so I just play the same input when I restore the images?
I have not started with the server side, thats why I ask. I only know the most basic php.
|
On October 08 2016 22:01 mantequilla wrote: what's too "specific" about automating a web app's deployment? you mean thousands of companies in the world are deploying their web apps to cloud by hand or through homemade solutions they wrote and paying 6 figures to do it? And I am not asking for step by step solutions, just asking what kind of a tool or api or whatever they are using.
It may sound obvious but have you looked at Chef/Puppet/Ansible?
|
On October 09 2016 00:41 Hhanh00 wrote:Show nested quote +On October 08 2016 22:01 mantequilla wrote: what's too "specific" about automating a web app's deployment? you mean thousands of companies in the world are deploying their web apps to cloud by hand or through homemade solutions they wrote and paying 6 figures to do it? And I am not asking for step by step solutions, just asking what kind of a tool or api or whatever they are using. It may sound obvious but have you looked at Chef/Puppet/Ansible?
Not at all, I will check them out, thanks
|
On October 08 2016 22:01 mantequilla wrote: what's too "specific" about automating a web app's deployment? you mean thousands of companies in the world are deploying their web apps to cloud by hand or through homemade solutions they wrote and paying 6 figures to do it? And I am not asking for step by step solutions, just asking what kind of a tool or api or whatever they are using. Again, it's not a deployment problem. Automating deployment for a webpage is not hard, and azure makes it even easier by providing hooks for e.g. continuous deployment with whatever you're already using (GitHub, or what have you).
The issue is that someone's asking for a whitelabeling solution, and trying to phrase it as a deployment problem .
They're asking the wrong questions, that's why they're not getting great answers.
|
|
|
|