Traevel 216 Light Poster

Somewhat related to reading/answering: locking old topics? Perhaps with an option for the OP to unlock it again. I'm not talking weeks, but 10 year old threads that get a reboot every now and then probably doesn't help anyone. Unless you would lose money on doing so, obviously. But sometimes people create an account just to respond to a dead thread with either a useless answer or a question of their own that will get ignored.

Traevel 216 Light Poster

I would also try to uninstall and reinstall the graphics driver. After that blow out the inside with compressed aiir.

Similar useful things OP could try:

  • re-install windows 98
  • hook up a CRT monitor
  • try rebooting from a floppy
  • upgrade to a Voodoo 3 graphics card

    Or, if that didn't help, realize it's now 2017 and just give up and buy a new one.

Traevel 216 Light Poster

Ah, I thought AI was your plan with Reverend Jim's suggestion as well. I wouldn't know of a language detector in PHP, but I know the one github uses is open source (Ruby).

But it's all going to be overkill if its only goal is to get a thread in the correct forum. Would probably be easier to just put a "suggest relocation" button on the page or something.

Traevel 216 Light Poster

Therefore, asking them if they have the wrong forum upon selecting the java tag could never happen.

Not to pile on a ton of work, but couldn't the analysis be applied on the content they provide instead of the tags they choose? For instance, if they're posting a community center thread, with community tags, but write about java a friendly message pops up suggesting a different forum.

Something that popped up while thinking about the code block parser: couldn't you automatically add the language detected by the highlighter as a tag to the thread? Regardless of forum location, java people would find the posts with java code blocks, and so on.

Traevel 216 Light Poster

Perhaps more of a DIY solution, but I'll mention it anyway.

Logstash has a twitter plugin. You can visualize it with Kibana. It should all be open source and free. There's an ELK stack (Elastic, Logstash, Kibana) docker image that has all of them combined.

YouTube: Twitter analysis using ELK

Edit: this seems a free analytics site/app but I've never tried it: tweetchup

  • Insights on tweets containing specific keywords/hashtag/user mention.
  • Stats on users mentioned keywords.
  • Interactive map with locations of users mentioned keywords.
  • Hashtags most used within tweets containing keywords.
Traevel 216 Light Poster

then apply this fix i have worked out with you

It's not really a fix though. When multiple people start adding records you're still at risk of getting duplicates. You won't be able to prevent that anywhere else but in the database itself. Whether it's with locking, triggers, restrictions etc. If you think that making the number random will decrease the chance of another GUI getting the same random number at the same time remember that over time there will be fewer and fewer possibilities left for those random numbers (after all, you need one that doesn't exist yet).

"its good enough, dont go changing anything that doesnt need to be changed"

I don't know what your position is in this case, internship/freelance/contract etc., but I'd argue that this needs to be changed. From what you've told me, and the arguments they've given you this is not a valid reason for not fixing it where it's supposed to be fixed. In the database. With the dirty shortcut being that you can add an always unique UUID which will be unique unless those 16 million calls per second start happening. But that means a 64-bit integer as key.

If this were a leaky ship you've only made the hole a bit smaller. And I think that's something you should always be able to discuss with your employer/customer.

Traevel 216 Light Poster

@Ivan_15

I think you're better off creating a new question and tag it with Java to receive more help for your own specific problem. I'll add this though:

Apache Axis received its last update in 2006. Before trying to solve an issue with parameters I strongly suggest you update to Axis2. You can use the following migration guide to help you make the switch. There's really no point in trying to fix an error that's occuring in code that's been discontinued for over 10 years. Migrating might even solve your problem all on its own.

Traevel 216 Light Poster

would the greater than or equal to 1 solve my problem?

It would if you are really checking against all tables. In your loop I see $i < $table_count[0]-7;. I'm assuming (zing!) you came to that by trial and error. However, the underlying problem remains that there are already duplicates in your tables, causing multiple records to be returned.

On a side note, have a look at creating Views. That way you can reduce that looped query over multiple tables to just a single query on the view.

In order to ensure uniqueness over multiple tables, one of the two UUID functions is the way to go.

An increment could also ensure uniqueness over multiple tables if you store its value outside of those tables, in the most simple form it could be in its own table. That way you can start at 10.000 and keep adding 1. However, in an ideal world you would not let the front end have any influence on this. For instance, what if you're running your code above, the id comes back as unique so you do your thing but before you can actually insert the record someone else has just submitted their record, making your id a duplicate.

What you could do is look into Triggers. In your code you would leave sec_id blank, as you would with an auto_increment id, the triggers in the database will fire on insertion and put a unique id in the …

Traevel 216 Light Poster

I like Submit as well. It suggests there is an upcoming choice regarding what you want to submit.

I'd prefer "Topics" and "Topics Tagged with java" because it's broad (which fits the result) and because it's actually tagged content. Subtily implying that you need to add tags to your submissions (assuming people look around a bit before submitting anything).

Traevel 216 Light Poster

so im doing a lot of assuming

Be very careful with that, it will come back to bite you in the end.

From the page I linked you:

The value of UUID_SHORT() is guaranteed to be unique if the following conditions hold:

  • The server_id value of the current server is between 0 and 255 and is unique among your set of master and slave servers
  • You do not set back the system time for your server host between mysqld restarts
  • You invoke UUID_SHORT() on average fewer than 16 million times per second between mysqld restarts

What it does is the following:

(server_id & 255) << 5 
+ (server_startup_time_in_seconds << 24)
+ incremented_variable++;

I'm not a database expert, but I'd say this will generate a unique number regardless of tables. The resulting number will be longer than 8 digits though.

If I were you I would contact my employer/customer and ask them if they have any particular restrictions on that sec_id. Things like:

  • should it be readable by a human (if someone has to type it in you'll probably want something else)
  • should it be unpredictable (even UUID() is predictable)
  • is it limited to a certain amount and type of characters/digits
  • how many sec_id's can there be expected to be, also in the future (thousands? millions? billions?)

Then I would change the id's accordingly, based on the information you get.

No one will expect you to guess or assume. …

Traevel 216 Light Poster

Can you please explain to me what I'm missing?

I was thinking along the lines of what you mentioned earlier, a shift to a different type of more curated content. I now know that if I want code snippets about programming (in general, or more specific) I can get a list by clicking on more. From what I read your goal is to make DaniWeb a place where people go to thinking "I'll find what I'm looking for here" instead of relying on Google traffic. I've been here quite a while, so I know that content and those people exist, but if I were a new visitor I would only see questions being asked.

I guess what I meant is that if there's a more prominent place to put snippets/tutorials etc. it will show that DaniWeb is more than a Q&A website. That the reason to stay here is not dependent on whether or not you have a question that needs answering. But also because a lot of cool new things are being discussed.

As for the long list of snippets/tutorials, I'm always being told that the customer doesn't know what he/she wants. Of course there's a limited subset of things I'd be interested in. However, that would not be limited to a specific programming language. Though I agree with you that snippets might be less "browse worthy" than tutorials or articles would be.

Traevel 216 Light Poster
<button type="button" onclick="Light()"> Change Image!</button> 

You're calling Light() but the method is now light(). Also you might have to change all the image url's to their full path (i.e. http://localhost/myproject/img/start.png). If they are local files you could use the image url's diafol posted. Be sure to read his post, that's the way to do it properly.

For instance, where I live the lights don't turn amber when you can start driving again (only when you're about to stop). With his solution you could adjust the code to my situation simply by removing the corresponding image from the array.

Traevel 216 Light Poster

Well, the queries I see in the do-while loop are all SELECT queries. So that's not the bit of code that INSERTS the sec_id into the database.

From what I can tell this is what's happening:

// create a random number between 10.000 and 10.000.000
// select all the records where sec_id matches this random number
// if there is exactly one record that matches, repeat the process
//
// implied > if the random number does not exist as a sec_id OR there is more than one match the whole process stops

After seeing this I realize that this is the bit of code you use to generate a random number that will be used as a sec_id later on in your code. The first adjustment I would make would be on the database side, by adding a Unique Index on the sec_id field. If you try to enter a duplicate the insertion will fail.

A crude way of solving it would then be to keep generating random id's until the insertion succeeds.

Is there a particular reason why the numbers can't be sequential? Does it have to be a certain number of digits?

MySQL has a built in function for generating unique integer ID's in the form of UUID_SHORT().

You invoke UUID_SHORT() on average fewer than 16 million times per second between mysqld restarts

This bit about ensuring uniqueness made me chuckle.

Traevel 216 Light Poster

I think the code of how you are creating the sec_id's would be more helpful because this seems to be a checking method only. One that keeps running until there is no longer a response on a random id (which might as well be the first number generated). Also, unless those sec_id's you posted are fake, they're all above 14.000.000 and your random test only goes up to 10.000.000.

FYI it's past 6 a.m. here so I won't be able to look at it until tomorrow if you do post the generating code (others will though!).

Traevel 216 Light Poster
Tutorial - Content extraction using Apache Tika

From the official website:

The Apache Tika™ toolkit detects and extracts metadata and text from over a thousand different file types (such as PPT, XLS, and PDF). All of these file types can be parsed through a single interface, making Tika useful for search engine indexing, content analysis, translation, and much more.

In this tutorial we will try and implement the four most important features of Apache Tika (as of version 1.14).

Table of contents
  1. Is this tutorial for me?
  2. Requirements
  3. How can I detect a file's type?
  4. How can I extract a file's content?
  5. How can I extract a file's metadata?
  6. How can I detect a file's language?
  7. Final thoughts
  8. External Resources
Is this tutorial for me?

What can Tika do?

  • Filetype detection
  • Language detection
  • Metadata extraction
  • Content extraction

What else can Tika do?

  • Named Entity Recognition (in combination with OpenNLP)
  • Image recognition (in combination with Tensorflow)
  • Language translation (in combination with Joshua)

What can't Tika do?

  • Bypass a password
  • Bypass file encryption

Can Tika handle filetype ... ?

Yes.

Really?

Yes.

What if I make one up?

Yes.

Send me $100!

Ye... wait a minute!

Requirements
  • Java SDK 1.7+ (required)
  • JUnit 4 to unit test with (required)(optional if you just want to watch the world burn)
  • An IDE (optional)

Note that this tutorial will use Java 8.

To include Tika in your project add the required …

Traevel 216 Light Poster

I figured I'd put my money where my mouth is (I think that's the expression anyway). So I wrote a tutorial that I'll post in a second as an article. I'd classify it as a code snippet but that requires one block of code for the library and that's not entirely the case. Feel free to re-categorize it, or make adjustments/improvements for that matter.

PS I did eventually manage to find a list of code-snippets using the json API.

Traevel 216 Light Poster

Hi,

In JavaScript a single = is used to assign a value and a double == is used to check a value. Also the term then can be removed entirely. You also have an error in the image tag itself, style= "width:304px;height:500px; <onclick="light()"> should just be style= "width:304px;height:500px;">. You already have the onclick attribute. Lastly, the original image has stop.png as a source but you check for Stop.png in your function.

If I change your JavaScript to the following (note the == when checking and the = when assigning)

function light() {
  if (document.getElementById("Img").src == "Stop-Amber.png") {
    document.getElementById("Img").src = "Stop.png";
  } else if (document.getElementById("Img").src == "Go.png") {
    document.getElementById("Img").src = "Stop-Amber.png";
  } else if (document.getElementById("Img").src == "Amber.png") {
    document.getElementById("Img").src = "Go.png";
  } else if (document.getElementById("Img").src == "Stop.png") {
    document.getElementById("Img").src = "Amber.png";
  }
}

the sequence I get is

  • Stop
  • Amber
  • Go
  • Stop-Amber
  • Stop
  • etc.

Also, you might have to change the img url's to their full paths. I tried this in a JSFiddle and had to change all the image paths to https://fiddle.jshell.net/_display/Amber.png for it to work.

Considering this is probably a homework assignment, here are some general pointers.

  • Function names should begin with a lowercase letter, following camelCase.
  • Even though JavaScript has automatic semi-colon insertion (leading to both hilarious and frustrating problems) you should add them to let the parser know where your statement ends.
  • Giving an image the id Img will work, but it's not very useful when you have several. Try …
diafol commented: Excellent example of what Daniweb is all about. Hats off to you. +15
cereal commented: +1 +14
Traevel 216 Light Poster

The post below is meant as feedback, not critique. I know DaniWeb always had more than just questions and answers, but I've always believed it's been an underexposed element. So as an experiment I tried finding snippets and what I would have to do to write one.

... perhaps a different type of curated content. Our code snippet library. Tutorials. Articles ...

I might be looking in the wrong places, but I can't find a list of code snippets, tutorials or articles that aren't questions. I know they exist, and I know a lot of them have a high quality. If people are meant to come to DaniWeb for that kind of quality content, that will keep them coming back on their own, I think there should be some form of finding that type of content, regardless of its subject. I like to think I have a broad interest, but (as a user) I won't type in random words in search in hopes of finding a code snippet that might show me something new or interesting. Perhaps these lists do exist, but if so, I'm having a hard time finding them and perhaps others would too.

I remembered that code-snippet was an option when creating a new article. I never really started a lot of discussion threads so I think I qualify as a newbie in that regard. I clicked Ask which I think is a good term of phrase, if it had suggested I was writing an …

Traevel 216 Light Poster

Well, without knowing anything about the webpage or the language it's written in there's not much anyone can do to help.

If you want to know how to connect MySQL to Visual Studio you can follow this manual.

If you want people to be able to help you with the code side of things you'll have to give some extra information. Such as the language it's written in and what you have tried so far. On a side note, adding the language as a tag will help you get more and better answers. The only tag I see now is sql-server and as far as I can tell you actually want the database to remain MySQL. If you want to convert it to SQL Server you can try Microsoft's SQL Server Migration Assistent.

Traevel 216 Light Poster

I believe that's what I mentioned could happen. And because you only posted that one line of css, and nothing regarding the structure/location of the files this will always remain a guessing game. My point is this:

You have a main page, and a main stylesheet (it contains that line you posted). You also have other pages, which are in a different directory than the main page (that is why the line won't work for both). Ideally, stylesheets (regardless whether you use wordpress or not) should work following the rules of inheritance. That means you only change the things you want different from the parent stylesheet in a child stylesheet, and things you want the same simply come from the parent stylesheet.

So let's say you have a structure as follows:

  • /index.html
  • /parent.css
  • /wp-content/
    • /themes/
  • /someFolder/
    • /about.html
    • /shop.html
    • /child.css

parent.css might look like this (no dots, because it should work for the main page)

/* lots of stuff */
 background: url(/wp-content/plugins/hrticulate/assets/hrs/hr-bluetooth-saw.png) repeat-x 0 0;
/* lots of stuff */

Now, because you only want the background different in the /someFolder/ you make a child.css that only changes the one line:

background: url(../wp-content/plugins/hrticulate/assets/hrs/hr-bluetooth-saw.png) repeat-x 0 0;

In your about.html or any page you want the different background url in you would let them use parent.css first and child.css second, that way the child overrides the css from the parent, but only on the part of the background url.

You could make a separate "child" stylesheet …

Traevel 216 Light Poster

Not very familiar with WordPress, but if the homepage is in the same directory as wp-content the two dots in the url will make it go up a directory and look for wp-content there. It's an easy check to see if it works on the homepage if you remove the two dots.

background: url(/wp-content/plugins/hrticulate/assets/hrs/hr-bluetooth-saw.png) repeat-x 0 0;

It could be that your child pages now no longer show the background. From what I read it's best practice in WordPress to provide child theme pages with their own stylesheets, overriding only the things you want different (in this case the background-url for the child pages).

If it doesn't change anything then posting the structure of your site could shed some more light.

Traevel 216 Light Poster

Traavel, even when there are multiple misspelled words, even on the same line?

This is how it looks on my end in Firefox 51.01 (64-bit) > webm
It does seem to blink two or three times, but always when typing.

I do however see the erratic behavior you described if I switch to Chrome. If that were happening I'd fully agree with not having spellcheck at all.

To that end, I also want to do absolutely everything in my power to turn those people who post "bad" first posts into good citizens (...)

I read the rest of your post and it gives a bit of context that I'll certainly keep in mind when seeing bad posts. On a side note, I joined DaniWeb all those years ago because I noticed knowledgeable people like James taking time to answer questions and trying to help the other person get to the root of their problem. Whereas the stackoverflows of the day were beginning to get a bit hostile towards the "newbie" questions, immediately assuming laziness and/or stupidity. So if you ask me it's not just a business model but also what makes DaniWeb a nice place to be.

Traevel 216 Light Poster

Aren't you noticing that the red swiggly under a word comes and leaves based on the position of the cursor?

It's staying the same here, regardless of position. The only thing I'm noticing is that a typo is not recognized as such if there's a number in it. So for instance asdiojhiobn would get underlined consistently, even when moving the cursor around, but asd9asd is not considered a typo.

But I understand what you mean. In that case no spellchecker would indeed be preferable.

Traevel 216 Light Poster

Sorry, I messed up in my answer. It should be index = videoList.length - 1 (d'oh!).

If there are four items the first one is videoList[0] and the fourth one is videoList[3].

Traevel 216 Light Poster

Our editor is not actually an HTML 5 textarea, which is why you are unable to make use of the browser's built-in spellchecker.

The spellchecker would work if the spellcheck attribute for the editor wasn't set to false. I can enable the (browser) spellcheck by running $(".CodeMirror-code").attr("spellcheck",true);. I have it running in a Tampermonkey now so for me it's not a major problem anymore.

I do prefer the DaniWeb editor over a textarea and I think it's improved a lot over the years.

Remember the vBulletin days where the moderators would spend half their day wrapping code in code tags?

I do. I think we were also able to add LaTeX to our posts. But apart from that I don't really miss those days.

Traevel 216 Light Poster

the middle column needs to be adaptable to move

By "move", do you mean change width responsively? That's pretty much the default behavior when you use columns.

If you want the sidebar container's height to stay the same (but width still responsive), then perhaps something like this: http://www.bootply.com/1POOiXcvxL.

You can customize the width and adjust the proportions of the columns by adjusting the values in the column class, for instance col-xs-3 to col-xs-6. Just keep in mind that the values of all columns in a row need to add up to 12. If you want different behavior depending on the device add multiple classes to the columns, i.e. col-xs-3 col-sm-4. The reference for Bootstrap 3's grid layout can be found here.

Traevel 216 Light Poster

You have two toolbar arguments. The second one overrides your first and only the first one has fontsizeselect. Merge both into one and it should work.

diafol commented: good catch - I didn't get that far! +15
Traevel 216 Light Poster

It's been a while since my last login, so I'm not sure if this is related but the editor is no longer picked up by the spellchecker (Firefox 51.0.1). It does however notice there is more to it than just static text because it offers the option to download dictionaries. The spellcheck does work on the "search DaniWeb" field, and the dictionaries are correctly installed.

However, if I set the spellcheck="false" in the editable div to true the browser's spellchecker works correctly.

As a non native English speaker I like to rely on one to check my assumptions on spelling. And with the DaniWeb spellchecker disabled (which used to check the preview for errors) there would be no easy way to do that.

I've also noticed "list dots" appearing in the editor when I press a function key (or use the keyboard/mouse volume control for that matter). It does not show up in the preview window however so I think it's silently ignored.

dots.png

Either way I like the new addition, it makes larger posts a lot easier to organize.

Traevel 216 Light Poster

When in doubt, the official tutorials are usually a good place to start learning.

Getting started with ASP.NET Core MVC

As far as prerequisites go it depends on your own knowledge. If you have no programming experience it's better to start with plain C# (or Java *cough*) and leave the frameworks for when you're more familiar with coding in general. Aside from experience in an Object Oriented programming language some HTML experience will help when you start making the Views (the V in MVC).

no one will go through all the search results reading all the posts and their replies to got his aim

With a little effort it's not that hard to filter the good from the bad. If the results are all bad, rephrase the question. You're not the first, nor the last person who wants to learn ASP.NET MVC.

Traevel 216 Light Poster

You're doing a check for when the video index is equal to the length of the video instead of when it's going negative.

index = index - 1;
if(index==videoList.length)
index = 0;

For instance if you have 4 videos, and the current index is 0 the above part will go: if(-1 == 3) and return false, hence index stays -1 and since there's no video with that index it will fail.

Instead you should do (for a back button) a check on a negative index. Depending on what you want to happen: nothing or circle back to the last video you set the index to 0 or videoList.length.

index = index - 1 
if(index<0)
index = videoList.length
Traevel 216 Light Poster

You can do it in vanilla JavaScript if you want. There is a getElementsByClassName function, similar to the familiar getElementById, that returns an array of the elements with that class name.

Something along the lines of

var elements = document.getElementsByClassName("command");
for(var i = 0; i < elements.length; i++) {
  elements[i].innerHTML = "changed";
}

In jQuery the same action would be something like

$(".command").html("changed");

It's easier to do in jQuery, but marginally slower in terms of performance. It would depend on the rest of your JavaScript code whether or not it would be worth to use a library, but if this is the only part I wouldn't bother with it.

Traevel 216 Light Poster

If you just want to mess around with simple image recognition (i.e. silhouets or colors) there are some frameworks you can use. Neuroph (note that is meant for use with Java) even has a GUI "studio" where you can train, tweak and save neural networks without the need for coding. You can then use the network from your (Java) application. It will not give you a perfectly trained network for any serious real world problems, but it might give you some general insight in the proces, without the immediate need for a math degree. They have some tutorials on image recognition, stock market prediction or poker hand prediction for instance.

But again, consider it a learning tool, not a crafting tool.

Writing one from scratch that can identify faces is going to be an extremely difficult and long proces. Ddanbe and Rubberman already described the steps for that route perfectly.

Traevel 216 Light Poster

That's true. I didn't mean to crack down on your script or anything, it was just something I noticed.

Dawkins is a classic. I can also strongly recommend The Computational Beauty of Nature by Gary Flake (ISBN 9780262062008). It's a good read, and relatively low on math, considering the topic.

I often heard the question why genetic algorithms are better than guessing over and over (I assume because that's what it sounds like). He has a marvelous bit on the sheer size of even the simplest problem. As a sample problem he starts with a string of 35 random letters and he wants to achieve a target string: furious green ideas sweat profusely (the book is full of funny references like that btw). With 26 letters and a space as the possible options that would make for a total of 27^35 possibilities for a 35 letter string. Or as he puts it: "assuming there are 2^80 electrons in the universe and that the universe is around 10 billion years old, then each electron would have to make 300 million guesses per second for the entire age of the universe before a correct guess was likely to be made". The genetic algorithm he describes gets the required string in 46 guesses. Powerful stuff!

Again, I was just happy to see this script up here! There can't be enough posts about AI on Daniweb if you ask me.

Traevel 216 Light Poster

No that's why I was surprised to see it in my alerts. I think it has been 6 months. Had a little hickup logging back in with the new system, but all is good now.

Edit:
I think it was just the convo history and that the real alert was for a message from a month ago.

Traevel 216 Light Poster

Unfortunately, most of the articles and examples I came across involved far too much tech speak and math for a brain long removed from theoretical mathematics.

I relate to this.

Quite a few years ago I came across an excellent tool to experiment with models and algorithms called NetLogo. It has its own little scripting language and a lot of sample models. After you've set up your model you can easily change parameters with sliders and buttons to see the effects of the change. I've seen it make people enthusiastic of the field just by letting them watch the wolf/sheep predation model unfold.

On the topic of genetic algorithms; it has an example of the "all ones" problem. Basically given a random string like "101101100001" the goal is to get it to "111111111111" by the same proces you describe above.

netlogo.png
netlogo_code.png

As a possible expansion on your solution (consider it an afterthought on my end) there is also the possibility of including elitism. This way the best solutions can be preserved over generations, by including the parent(s) as a child into the next generation without mutations. It can drastically speed up the progress of the algorithm.

Traevel 216 Light Poster

I know I'm not the most regular user around, but I don't think I can make this in time.

message.png

Anyways, I love the changes, keep it up!

Traevel 216 Light Poster

Almost everything you do is inside the if statement.

Your statement stmt = c.createStatement(); will produce a null pointer, because all you did was Connection c ;. If statement or not, defining c is not enough to create a database connection.

edit:
@RudyM I'm sorry, I thought you were the original poster.
You're right, the phrasing is a tad confusing; claiming issues before introducing the if statement and at the same time having no issues before introducing it.

Traevel 216 Light Poster

Setting c to null wont fix your issue. You need to create a connection by using a DriverManager or a DataSource for instance.

Establishing a Connection

Traevel 216 Light Poster

From the UCanAccess Sourceforge page:

The distribution comes with both a number of Junit Test Cases (package net.ucanaccess.test) and a simple java example class (net.ucanaccess.example.Example) which illustrate how UCanAccess may be used.

Also..

i have searched on google but they are either using sql server or are just tutorials i want a working java application with code.

..no one is going to write your homework for you, so I'd revisit those tutorials if I were you. And since it's a JDBC implementation, there are plenty out there you can use.

Traevel 216 Light Poster

The engine is repl.it
Is there a better engine.

That one uses the same one as Firefox (SpiderMonkey), Node.js uses the one Chrome does (V8). You can even compare the two on that site I see. (For what it's worth, IE and Edge use the Chakra engines, Safari uses WebKit).

It's best to use code that compiles on all engines since your users will likely be on Firefox, Chrome, Safari or Edge as well. As you have noticed that isn't always as easy as it sounds.

rproffitt commented: Web developers, second verse! +6
Traevel 216 Light Poster
function unicoding(str) {
  for (i = 0; i < str.length; i ++) {
    console.log(String.charCodeAt(i))
  }
  return str;
}

You're not using the str variable but String, which should give you a type error.

2015-11-07--1446935403_476x330_scrot.png

Change it to str.charCodeAt(i).

My guess is that the engine you're using is interpreting String.charCodeAt(0) as String.charCodeAt('0') and giving you the unicode for 0, 1, 2, 3, 4 etc. which are the values of i given those str lengths you supplied. But, as you can see in the screenshot it won't compile on all JavaScript engines.

Traevel 216 Light Poster

Well, to reduce the complexity of this method you'll have to reduce the number of if-else statements. You could extract them to separate methods like isNull(object), isNumber(object) and isDecimal(object). Also you don't need an else since you're returning and thus never reaching the next if.

if (isNull(object)) {
    // message
    return false;
}

if (isNumber(object)) {
    // message
    return false;
}

if (isDecimal(object)) {
    // message
    return false;
}
Traevel 216 Light Poster

What you are calculating is the population standard deviation which, for 1-10, is 2.87228. The sample standard deviation for 1-10 is indeed 3.02765. For a sample deviation you need to divide by N - 1 instead of N. I'll leave it up to you to implement that. (hint: N is the length of your list of arguments)

A few general pointers about your code:

      intMath.myArray = new ArrayList<>(10);
            for (int i = 0; i < 10; i++) {
            intMath.myArray.add(1);
         intMath.myArray.add(2);
         intMath.myArray.add(3);
         intMath.myArray.add(4);
         intMath.myArray.add(5);
         intMath.myArray.add(6);
         intMath.myArray.add(7);
         intMath.myArray.add(8);
         intMath.myArray.add(9);
         intMath.myArray.add(10);
            }

That means you're adding 1-10 ten times, i.e. 100 numbers. You have access to the i variable, so use it to populate the ten numbers correctly. One way or another it will mess up your calculations (i.e. when you implement N-1). You need to change it so there's only one intMath.myArray.add left in the loop.

Always program to an interface and encapsulate your variables. So public ArrayList<T> myArray; should be private List<T> myArray;

There is no need for stdev to be static, especially since you already define an instance on line 10. So instead use intMath.stdev(intMath.myArray) on line 27 and remove the static keyword; you should also use List here, and optionally final.

public <T extends Number> double stdev(final List<T> a) 

Lastly, you're using stdev = Math.pow(stdev, .5); to calculate the square root. However, java.lang.Math has a sqrt method just for that:

stdev = Math.sqrt(stdev); 

Edit: keep in mind that you hardcoded 1-10 but by correctly implementing …

kayleigh0411 commented: Thank you! +0
Traevel 216 Light Poster

This is not what they mean by Delegation Principle.

Obviously no one will redesign your application to comply with OO principles for you.

You can start making your application OO by implementing the first five principles (S.O.L.I.D.).

  • Single Responsibility Principle - Each class should have its own responsibility. For instance a Book class does not contain Student information.

  • Open Closed Principle - Each class should be open for extension and closed to modification. For instance if you want to add a new book type that can only be read in the library but not lent out you do not want to have to modify the Book class. Instead you'll create something like a LibraryItem which Book extends. Later on you can then add a ReadOnlyBook as an extension as well.

  • Liskov Substition Principle - Objects should be replacable by instances of their subtypes. For instance if you have a LibraryItem, and Book extends LibraryItem, then in every place where you use LibraryItem you must be able to replace it with a Book instance and not alter the behaviour of your application.

  • Interface Segregation Principle - Interfaces should be specific to their clients. For instance if you had a ScannableItem interface, which could be a book, video or library card, you would only force methods/functions that are applicable, like scan(), and not something like read() or watch() which are specific to items and should be in their own interfaces. Otherwise you'd be forced to implement empty variations in items that can't …

Traevel 216 Light Poster

Those pos1 and pos2 variables are always 0 so it's constantly comparing the first two letters. Your i and j however remain unused.

Traevel 216 Light Poster

In PromotionAdapter

  • The variables should be made private (also instantiating them to null is pointless, Objects will be null by default)
  • On line 7 you're calling super() for no reason.

In promotionfragment

  • According to convention, classes should start with an upper case letter and be camel cased: PromotionFragment.

Also keep in mind that variable names should be meaningful and represent their purpose or content. Things like PromotionAdapter country = are rather confusing to a reader. For instance, name the class Country or the variable promotionAdapter. However, since it's neither a country nor adapting anything (it's merely a POJO) it would be far less confusing if you named it PizzaCoupon, PizzaPromotion or even Pizza. You can easily rename variables/classes etc. by right clicking on it in your IDE and choosing refactor -> rename.

Now, on to the question.

You could use a library like gson for that.

Then, you could solve it with something like:

public class Parser {

    public List<PromotionAdapter> parseJson(final String jsonString) {

        // promotion adapters to be returned
        List<PromotionAdapter> promotionAdapterList = new ArrayList<>();

        // input is a generic json array
        JsonArray jsonArray = new JsonParser()
                .parse(jsonString)
                .getAsJsonArray();

        // for each element
        for (JsonElement jsonElement : jsonArray) {

            // create a new promotion
            PromotionAdapter adapter = new PromotionAdapter();

            // turn into a jsonObject for easy retrieval of values
            JsonObject jsonObject = jsonElement.getAsJsonObject();

            // retrieve value for key "coupon_code"
            adapter.setCode(jsonObject.get("coupon_code").toString());

            // TODO implement other PromotionAdapter fields

            // add promotion to list
            promotionAdapterList.add(adapter);

        } …
Traevel 216 Light Poster

You could try using the old Android Development Tools plugin for Eclipse. It's not the official tool anymore, but at least it's an IDE.

Something else that could help is testing/running the application directly on the mobile device. If I remember correctly the plugin supports hooking up your phone and using it as a deployment location (will require some setting changes on your phone no doubt). That way you won't have the emulator hogging resources. If you do want to use an emulator, perhaps give Genymotion a look, it used to run a lot smoother than the included one.

Edit: the IntelliJ Community edition also supports android, if you don't use an emulator that might still give improvement

Traevel 216 Light Poster

You can create an array in various ways .

String[] array = new String[]{"I","did","not","read","my","textbook","and","I","don't","know","what","a","Google","is","nor","have","I","studied","line","63","outside","of","the","Netbeans","GUI-builder"};

Furthermore, it seems that most of this code was given to you (or generated by Netbeans) and that you haven't done much of it yourself. Until then I will only leave you reading material for your other questions:

Traevel 216 Light Poster

As @JamesCherrill pointed out, the add method you're using on line 101 is not the correct way to add data to a JTable. You are passing null as a component to public void add(Component comp, Object constraints). If you read the JavaDoc of that method you will find it says the following:

Parameters:
comp - the component to be added
constraints - an object expressing layout contraints for this component
Throws:
NullPointerException - if comp is null

Hence your NullPointer.

You add data to a table by using its model. More precisely: retrieve the model from the JTable, using its getModel() method. Add your data to the model, using addRow(Object[] objects) for instance. Then assign the model back to the JTable using its setModel(TableModel model) method.

Keep in mind that (as JamesCherrill also pointed out) your datafile currently looks like this:

1   
asd 
asda    
asd 
asd 

However, you are splitting on commas in your current code, which will result in this:

2015-10-09--1444428173_886x367_scrot.png

I'm assuming this is some sort of homework/practice assignment, so that's up to you to implement correctly (in either the saving, or the loading).

One last remark; if you were to split on commas, what would happen if a user added a comma in his/her input?

Traevel 216 Light Poster

Well, both have bootstrap. The first one has the "image" <form> in a <table>, the second one doesn't. The first one just has TestPage, because it's not in a <title></title>. The second one has a large "Upload page" text but that's it.

2015-09-29--1443545345_581x379_scrot.png

I don't see a "not working".

If you do mean the difference between a table alignment and a bootstrap alignment, then perhaps you can use this tutorial to apply a bootstrap layout to your form without using tables. Specifically the section entitled horizontal form layout, which resembles your original table version the most.

Obviously I had to remove the <?php include("img-upload.php");?> since you didn't post that. Perhaps the "non working" bit is in there. If it is, elaborate on what's not working.