Open Side Menu Go to the Top
Register
Programming homework and newbie help thread Programming homework and newbie help thread

10-24-2016 , 03:26 PM
When you define a foreign key you do it as such:

Code:
Foreign Key (attr_1, ... , attr_2) references SomeTable(attr_1 ... , attr_n)
ie you have to explicitly state which table it's referring to.

I don't entirely understand the solution you're proposing. If you have a foreign key in the Humans table identical to the primary key in other tables, how would you get rid of ambiguity when you have the same id in multiple tables? ie Humans(id: 1) can be a reference to Man(id: 1) or Woman(id: 1)

Quote:
Originally Posted by just_grindin
You can also insert the primary key of the humans table as foreign keys in the other tables. That way you can query any table and know exactly which record you're looking for.
This is the best solution I've come up with so far, but seeing as how the primary key for the humans table is (id, gender), it involves adding a gender attribute to the men and womens table which seems ridiculous.

Quote:
Originally Posted by just_grindin
I'd also be curious why you have 2 separate tables for genders.
As opposed to how many?
It's just an abstraction of a homework question that I'm doing. I asked about this first at a q&a platform we have for the class, so I had to try my best to abstract away from the original question to give up as little information as possible. Id is probably a pretty poor choice of identifier because it's intuitively thought of as unique so having the same id multiple times in the humans table looks strange.
Programming homework and newbie help thread Quote
10-24-2016 , 05:03 PM
Quote:
Originally Posted by Mavoor
When you define a foreign key you do it as such:

Code:
Foreign Key (attr_1, ... , attr_2) references SomeTable(attr_1 ... , attr_n)
ie you have to explicitly state which table it's referring to.
Right so why don't you have a column called gender_table or something that references the primary key (id) of the appropriate table?

Quote:
Originally Posted by Mavoor
I don't entirely understand the solution you're proposing. If you have a foreign key in the Humans table identical to the primary key in other tables, how would you get rid of ambiguity when you have the same id in multiple tables? ie Humans(id: 1) can be a reference to Man(id: 1) or Woman(id: 1)
Well there should be no ambiguity in the Id in any table. That was basically my point. Human's should each have a unique Id and you would use the foreign key to look them up in the other tables. You would have to use gender to identify which table to look in. So you're right for your specific question it doesn't work but the way I'm interpreting it now it seems like the tables are set up incorrectly.



Quote:
Originally Posted by Mavoor
This is the best solution I've come up with so far, but seeing as how the primary key for the humans table is (id, gender), it involves adding a gender attribute to the men and womens table which seems ridiculous.
Yea I guess I'm confused why there are 2 tables for gender that just hold an id? What precisely are you trying to accomplish? Are you just trying to normalize a dataset that has a an identifier that is not unique but can be made unique by including another column?


Quote:
Originally Posted by Mavoor
As opposed to how many?
It's just an abstraction of a homework question that I'm doing. I asked about this first at a q&a platform we have for the class, so I had to try my best to abstract away from the original question to give up as little information as possible. Id is probably a pretty poor choice of identifier because it's intuitively thought of as unique so having the same id multiple times in the humans table looks strange.
Yea I guess I'm not going to be much help to you here without really understanding what you're trying to do.

It looks like you have a single humans table whose primary key is some id and gender.

Then you have tables man and woman that reference the same identifier used to construct the primary key that holds some other data and you want to make a relation between the tables somehow for some unknown end?
Programming homework and newbie help thread Quote
10-24-2016 , 05:16 PM
Quote:
Originally Posted by Ankimo
Is there no publically available AHK code for scanning cards on Stars? When I google it, the only hit I get is for writing a bot which only explains the concept but no code.
What do you mean by "scanning cards" ?

In any case, PokerStars.log.0 contains them written in realtime.
Programming homework and newbie help thread Quote
10-24-2016 , 06:59 PM
Quote:
Originally Posted by Mavoor
This is the best solution I've come up with so far, but seeing as how the primary key for the humans table is (id, gender), it involves adding a gender attribute to the men and womens table which seems ridiculous.
This is not ridiculous. Your proposed schema design, as you already admitted, presents anomalies. If you want to have a separate table for genders, you would create a table called genders and map the human_id to the appropriate gender, but there is nothing wrong with having a gender column in your humans table, since gender is an attribute of humans and this won't present anomalies.

edit to add: This is what people refer to when they talk about object-relational impedence. SQL is not OOP. SQL is set theory in practice, which does not imply OO style inheritance.

Last edited by daveT; 10-24-2016 at 07:05 PM.
Programming homework and newbie help thread Quote
10-24-2016 , 09:09 PM
Quote:
Originally Posted by _dave_
What do you mean by "scanning cards" ?



In any case, PokerStars.log.0 contains them written in realtime.


Thanks Dave. I was looking into all these image scanning solutions.

I meant I want to scan the cards as dealt and. It have to wait for HH to be saved.
Programming homework and newbie help thread Quote
10-26-2016 , 08:09 PM
When you have a programming related question and you can't find the answer by using search engines, what is the next best place to search? If this question is too general, then where would you go to learn more about the command line in DOS?
Programming homework and newbie help thread Quote
10-27-2016 , 07:44 AM
books
Programming homework and newbie help thread Quote
10-27-2016 , 12:47 PM
I don't think I've ever had a programming question that google couldn't answer

My next place to look would probably be posting, somewhere like here or stack overflow, etc
Programming homework and newbie help thread Quote
10-27-2016 , 08:32 PM


Is this even possible?

If I do:
S -> X | empty
X -> aXc | bXc | Xc | empty

then I can make the content of the strings accepted by this language but I can also make strings that are not accepted by this language. If it was a push down automaton I feel like I could solve this easy, but for CFG I am failing. Any tips?
Programming homework and newbie help thread Quote
10-28-2016 , 07:13 PM
Quote:
Originally Posted by Ryanb9


Is this even possible?

If I do:
S -> X | empty
X -> aXc | bXc | Xc | empty

then I can make the content of the strings accepted by this language but I can also make strings that are not accepted by this language. If it was a push down automaton I feel like I could solve this easy, but for CFG I am failing. Any tips?
I think instead of having X -> bXc you should have a rule X -> bYc, to make the transition from creating a's to creating b's. Y would then have the same rules as X except it can't generate a string that includes an a.
Then you'd do something similar when transitioning from b's to c's
Programming homework and newbie help thread Quote
10-29-2016 , 08:22 AM
So with this piece of code, I can get a progressbar(javafx) running to max and display it.

Code:
Task task = new Task<Void>() {
		    @Override public Void call() {
		    	 final long max = 1500000000;
		         for (int i=1; i<=max;i++) {
		             if (isCancelled()) {
		                break;
		             }

		             updateProgress(i, max);
		         }
		         return null;
		     }
		};
		progess_download_games.progressProperty().bind(task.progressProperty());
		new Thread(task).start();
Now I haven't worked with Threads/GUIs at all, but I want a progressbar that shows me the progress of my task, but whatever I do the progressbar only updates after finishing.

I changed the code to this

Code:
Task task = new Task<Void>() {
		    @Override public Void call() {
		    	 final long max = 15
		         for (int i = api.get_Progress(); i<=max;) {
		             if (isCancelled()) {
		                break;
		             }
                             api.get_Progress();
                             //Here was sleep but even without it didn't work
		             updateProgress(i, max);
		         }
		         return null;
		     }
		};
		progess_download_games.progressProperty().bind(task.progressProperty());
		new Thread(task).start();
The get_Progress() just returns the index of a for loop in another class.

The progressbar only changes when the task is finished, what am I missing here?

Last edited by NiSash1337; 10-29-2016 at 08:27 AM.
Programming homework and newbie help thread Quote
10-29-2016 , 08:53 AM
Quote:
Originally Posted by RustyBrooks
I don't think I've ever had a programming question that google couldn't answer

My next place to look would probably be posting, somewhere like here or stack overflow, etc
Can't be serious...

It has been my experience that if Google didn't answer my question then posting it on SO is futile. Example of one of my questions on SO : MongoDB import

Warning : was trying to do it on Windows when I was a programming noob so posted solutions might actually work...
Programming homework and newbie help thread Quote
10-29-2016 , 11:17 AM
Quote:
Originally Posted by NiSash1337
So with this piece of code, I can get a progressbar(javafx) running to max and display it.

Code:
Task task = new Task<Void>() {
    @Override public Void call() {
     final long max = 1500000000;
         for (int i=1; i<=max;i++) {
             if (isCancelled()) {
                break;
             }

             updateProgress(i, max);
         }
         return null;
     }
};
progess_download_games.progressProperty().bind(task.progressProperty());
new Thread(task).start();
Now I haven't worked with Threads/GUIs at all, but I want a progressbar that shows me the progress of my task, but whatever I do the progressbar only updates after finishing.

I changed the code to this

Code:
Task task = new Task<Void>() {
    @Override public Void call() {
     final long max = 15
         for (int i = api.get_Progress(); i<=max;) {
             if (isCancelled()) {
                break;
             }
                             api.get_Progress();
                             //Here was sleep but even without it didn't work
             updateProgress(i, max);
         }
         return null;
     }
};
progess_download_games.progressProperty().bind(task.progressProperty());
new Thread(task).start();
The get_Progress() just returns the index of a for loop in another class.

The progressbar only changes when the task is finished, what am I missing here?
I'm not a Java expert but according to the documentation here:
https://docs.oracle.com/javafx/2/api...rent/Task.html

Your task is returning type <Void> which is meant to return no value. Don't know of that helps or not.

Also if progress is dependent on the state of other threads I think your code needs to be altered slightly based on the documentation, though as I said no expert.
Programming homework and newbie help thread Quote
10-29-2016 , 11:28 AM
The first result for DOS command line is this very good resource:

http://www.computerhope.com/msdos.htm

http://www.computerhope.com/overview.htm

Unfortunately, so much of command line is trail and error plus learning as you need a new command. Windows command line sucks, but learning how to create batch files makes it much easier to deal with.
Programming homework and newbie help thread Quote
10-29-2016 , 12:38 PM
Quote:
Originally Posted by just_grindin
I'm not a Java expert but according to the documentation here:
https://docs.oracle.com/javafx/2/api...rent/Task.html

Your task is returning type <Void> which is meant to return no value. Don't know of that helps or not.

Also if progress is dependent on the state of other threads I think your code needs to be altered slightly based on the documentation, though as I said no expert.
Ahh a I just realized that foolishly if your task is just meant to display the progress bar then you probably don't want to return anything so Void is likely valid return type.
Programming homework and newbie help thread Quote
10-29-2016 , 12:58 PM
Yeah it doesn't work without, I'm quite the noob as far as threads go. I guess the problem lies with getting data from another thread or something at this point I don't even feel like continuing, I just thought "Hey a progressbar would be nice, how hard can it be", yeah not even gonna say how many hours I've been looking now and I honestly didn't even really need it lol.

Last edited by NiSash1337; 10-29-2016 at 01:04 PM.
Programming homework and newbie help thread Quote
10-29-2016 , 03:12 PM
Quote:
Originally Posted by Ryanb9


Is this even possible?

If I do:
S -> X | empty
X -> aXc | bXc | Xc | empty

then I can make the content of the strings accepted by this language but I can also make strings that are not accepted by this language. If it was a push down automaton I feel like I could solve this easy, but for CFG I am failing. Any tips?
This was the solution I came up with.


edit: for anyone wondering, CFG's are used in things like compilers, parsers, etc. I know google uses them in its speech to text algorithms.
Programming homework and newbie help thread Quote
10-29-2016 , 03:17 PM
Quote:
Originally Posted by Mavoor
I think instead of having X -> bXc you should have a rule X -> bYc, to make the transition from creating a's to creating b's. Y would then have the same rules as X except it can't generate a string that includes an a.
Then you'd do something similar when transitioning from b's to c's
This is exactly what I ended up doing. Thanks for your help.
Programming homework and newbie help thread Quote
10-29-2016 , 05:43 PM
Quote:
Originally Posted by NiSash1337
Yeah it doesn't work without, I'm quite the noob as far as threads go. I guess the problem lies with getting data from another thread or something at this point I don't even feel like continuing, I just thought "Hey a progressbar would be nice, how hard can it be", yeah not even gonna say how many hours I've been looking now and I honestly didn't even really need it lol.
Not a Java expert. Try this:

Thread.Yield()
Programming homework and newbie help thread Quote
10-30-2016 , 12:02 PM
Jesus I got it working, figured I need a thread for my other class as well, then I thought "This has to work now, but why doesn't it". Then I stumbled upon Atomic values and it was like "NOW it has to work", still didn't, so I googled again added "volatile", was like "Now please?", nope. So kept looking, added "static" and now it works. Now I gotta remove everything to see what is not needed, but hey at least the bar moves.

I also got a new problem because of it, but hey I learned quite a lot about threads.
Programming homework and newbie help thread Quote
10-31-2016 , 09:33 PM
Something that just came up in my intro to SQL class that my teacher couldn't really explain to me. I have something like:
Code:
SELECT DATEDIFF(years, HireDate, GETDATE()) AS 'Years Employed'
FROM EMPLOYEE
WHERE 'Years Employed' >= 5
ORDER BY 'Years Employed' DESC
The issue is I get a conversion error when comparing Years Employed to 5. I don't understand this, because DATEDIFF is supposed to return an integer. The ORDER BY clause works fine. Also, the query works perfectly fine if I change it to:
WHERE DATEDIFF(etc)

So what is happening here?
Programming homework and newbie help thread Quote
10-31-2016 , 10:00 PM
Quote:
Originally Posted by LBloom
Something that just came up in my intro to SQL class that my teacher couldn't really explain to me. I have something like:
Code:
SELECT DATEDIFF(years, HireDate, GETDATE()) AS 'Years Employed'
FROM EMPLOYEE
WHERE 'Years Employed' >= 5
ORDER BY 'Years Employed' DESC
The issue is I get a conversion error when comparing Years Employed to 5. I don't understand this, because DATEDIFF is supposed to return an integer. The ORDER BY clause works fine. Also, the query works perfectly fine if I change it to:
WHERE DATEDIFF(etc)

So what is happening here?
Single quote isn't the correct way to delimit a column name, it denotes a string. SQL Server is letting it slide in the SELECT clause because context makes it clear that a column name is intended. I would actually expect the ORDER BY clause to be interpreted as a string and thus have no effect on ordering, does it really work? Weird quirk if so. In the WHERE clause, it's definitely being interpreted as the string 'Years Employed'. You want [Years Employed].

Edit: Bit alarming that your teacher doesn't know that, lol. Also, square brackets are peculiar to T-SQL. In MySQL you use backticks, in Oracle you can use double quotes but I think it's frowned on.

Last edited by ChrisV; 10-31-2016 at 10:14 PM.
Programming homework and newbie help thread Quote
10-31-2016 , 10:40 PM
My advice to you is to avoid quoting altogether and just use column names that are acceptable as bare words, but yeah, it's a context issue, as ChrisV said.
Programming homework and newbie help thread Quote
11-01-2016 , 06:18 AM
So I got a for loop

Quote:
for
{
does something with a StringBuilder sb
}
now I need that string builder object in an other class for like 20-25 methods, so I had the choice of

a) Calling the 20 methods right there in the for loop, which seems stupid.

b) Creating a helper method in the other class that calls the 20 methods and call only that method in the for loop.

c) put everything in the constructor of the other class and just create a new instance of the class in the for loop:

Code:
new Data_Extraction (sb);
What would be the correct way to go? Are the any efficency differences ?
Programming homework and newbie help thread Quote
11-01-2016 , 07:43 AM
Really vague about what you want, probably need to be more specific.
Programming homework and newbie help thread Quote

      
m