Yay, I have a service running, updating a database and sending events to a log file (I'm not using eventviewer yet, a text file was quick a dirty. I'll add proper logging later)
Here is a test to see if I was able to make a successful SQL update
Starting Service
Stopping Service
Starting Service
update machine_state set is_online = 1,username = "halkun",last_active = (NOW())where ip_address = "192.168.0.10"
Making connection now
OK, Poop is coming out
I'm a twitter shitter!
update machine_state set is_online = 1,username = "halkun",last_active = (NOW())where ip_address = "192.168.0.10"
Making connection now
...
I may have to clean that up a little
halkun on
0
Monkey Ball WarriorA collection of mediocre hatsSeattle, WARegistered Userregular
edited November 2010
In C, if I have made up a structure(say it is called Foo), and I want to make up a type that is an array of pointers to those structures, is:
typedef Foo **FooTable;
Somehow having a pointer to another pointer seems weird or obfuscatory to me, but trying to define it as an array makes functions complain. I understand an array and a pointer are basically the same thing, but is this the right way to do this?
Monkey Ball Warrior on
"I resent the entire notion of a body as an ante and then raise you a generalized dissatisfaction with physicality itself" -- Tycho
In C, if I have made up a structure(say it is called Foo), and I want to make up a type that is an array of pointers to those structures, is:
typedef Foo **FooTable;
Somehow having a pointer to another pointer seems weird or obfuscatory to me, but trying to define it as an array makes functions complain. I understand an array and a pointer are basically the same thing, but is this the right way to do this?
Yes, this is correct.
You have a pointer, which as you say can be considered an array (indexing is just dereferencing with an addition first) and then what is your array made of?
Foo *
So it's an array of Foo pointers. Your FooTable variable t say is a pointer to memory, when you dereference it it will be of type Foo *, all is good. If you index it, it will be of type Foo *, since index == dereference. There is nothing wrong or bizarre here once you get the feel for it. As you've probably seen others and I mentioning before, var[x] is the same as *(var + x).
I understand the difference between the two and I understand the arguments, but I gotta say... the ease of use and scalability of Flash really overshadows the complexity and unstable nature of Ajax methods, (mainly due to browser support issues) and it's almost forcing me to use Flash for simple dynamic information and that upsets me because the major drawback to flash is the ability to "edit on the fly" when changes need to be made. I WANT to use HTML output.
This cross-browser shit is really really starting to piss me off as newer better technologies are taking fooooooreeevvveerr to be implimented, and then of course are broken in their various forms.
</endrant>
I'm actually a fan of GWT(Google Web Toolkit) which lets you program in JAVA and it translates it into JS. It creates different permutations for each of the main web browsers. I'd say it works 95% of the time, sometimes one of the browsers (Usually IE) will render something how you didn't want to.
But being able to code websites in Java and use to a lot of Google's awesome APIs allows for some awesome stuff quickly.
I understand the difference between the two and I understand the arguments, but I gotta say... the ease of use and scalability of Flash really overshadows the complexity and unstable nature of Ajax methods, (mainly due to browser support issues) and it's almost forcing me to use Flash for simple dynamic information and that upsets me because the major drawback to flash is the ability to "edit on the fly" when changes need to be made. I WANT to use HTML output.
This cross-browser shit is really really starting to piss me off as newer better technologies are taking fooooooreeevvveerr to be implimented, and then of course are broken in their various forms.
</endrant>
Use jQuery, takes care of cross browser bullshit and the DOM for you. Slips in next to frameworks and works solely on javasript, client side, with there being Ajax modules.
I always like the RFC 2822 Regex. That's a prime example of a WTF regex. But if I'm doing a lot of parsing and file spelunking, I usually would do it in a Regex. Though lately, I've been messing around with Clojure and Chukwa/Hadoop as a possibility for large data set work.
So I'm taking a community college intro to programming with C++ class right now. I'm starting to get the appeal of coding. As obtuse as the language can be sometimes and I sometimes feel like its going over my head, I AM slowly learning it. I just spent the last 4 hours working on one problem for the homework, and by god it fucking works. Shit yeah. Nothing like pure unadulterated satisfaction to end my night before going to bed.
It's hard to suggest a proper language to start off in. C++ can be incredibly obtuse, and its advanced features (STL) are tough to learn. A proper toolkit like QT takes care of most of the ickiness for you, though.
But in terms of learning... Just to disagree with the thread title, I'd have to go with Python for the first language. No, not Java. Either that, or C, just so people get an appreciation of what's actually going on.
I understand the difference between the two and I understand the arguments, but I gotta say... the ease of use and scalability of Flash really overshadows the complexity and unstable nature of Ajax methods, (mainly due to browser support issues) and it's almost forcing me to use Flash for simple dynamic information and that upsets me because the major drawback to flash is the ability to "edit on the fly" when changes need to be made. I WANT to use HTML output.
This cross-browser shit is really really starting to piss me off as newer better technologies are taking fooooooreeevvveerr to be implimented, and then of course are broken in their various forms.
</endrant>
Use jQuery, takes care of cross browser bullshit and the DOM for you.
No one codes straight JS anymore. Frameworks are the way to go.
Nightslyr on
PSN/XBL/Nintendo/Origin/Steam: Nightslyr 3DS: 1607-1682-2948 Switch: SW-3515-0057-3813 FF XIV: Q'vehn Tia
zomg, more java questions! for whatever reason linkedlists are making my brain die. right now, i'm trying to do a few things.
first thing:
i'm creating a new LinkedList class of integers, and i'm just adding basic/meh functionality to it.
i figured out some of it, but i'm stuck on a few key methods, such as:
a "count duplicate" method, which counts the number of times a number appears in the list of integers. i.e., you have the number of 3, it appears 4 times throughout the list, you have 3 duplicates of it. add it a counter called duplicates. do the same thing with the next number, add to the counter, finally display the result at the end.
i'll post what i currently have - the only way i can think of right now to make it work is with two while loops, and that just does not seem OK to me.
public void countDuplicates() {
ListNode current = front;
int value = current.data;
int duplicates=0;
while (current.next != null) {
if (value==current.data) {
duplicates++;
}
current = current.next;
}
System.out.println(duplicates);
}
the other problem i'm tripping up on is basically an equals method, which returns true when the two LinkedLists are exactly the same (same values in the same order and the same length), and returns false if anything is off.
for whatever reason, i can't get my brain around what needs to be done logically, and it's very much like hitting my face against a brick wall over and over.
here's the full class + the ListNode class which is what allows for listnode objects.
import java.util.NoSuchElementException;
// Simple first version of LinkedIntList with just a constructor
// and methods for add and toString.
public class LinkedIntList {
private ListNode front; // first value in the list
// post: constructs an empty list
public LinkedIntList() {
front = null;
}
// post: returns comma-separated, bracketed version of list
public String toString() {
if (front == null) {
return "[]";
} else {
String result = "[" + front.data;
ListNode current = front.next;
while (current != null) {
result += ", " + current.data;
current = current.next;
}
result += "]";
return result;
}
}
// post: appends the given value to the end of the list
public void add(int value) {
if (front == null) {
front = new ListNode(value);
} else {
ListNode current = front;
while (current.next != null) {
current = current.next;
}
current.next = new ListNode(value);
}
}
// post: finds the minimum value in a LinkedList using a while loop.
public int min() {
if (front == null) {
throw new NoSuchElementException();
} else {
ListNode current = front;
int oldMin = 0;
while (current.next != null) {
if (current.data < oldMin) {
oldMin = current.data;
}
System.out.println("A");
current = current.next;
}
return oldMin;
}
}
public void countDuplicates() {
ListNode current = front;
int value = current.data;
int duplicates=0;
while (current.next != null) {
if (value==current.data) {
duplicates++;
}
current = current.next;
}
System.out.println(duplicates);
}
public boolean equals(LinkedIntList a) {
ListNode current = front;
bada = front;
while (current.next != null) {
if (current.data != data) {
return false;
} else {return true;}
}
}
}
// ListNode is a class for storing a single node of a linked
// list. This node class is for a list of integer values.
public class ListNode {
public int data; // data stored in this node
public ListNode next; // link to next node in the list
// post: constructs a node with data 0 and null link
public ListNode() {
this(0, null);
}
// post: constructs a node with given data and null link
public ListNode(int data) {
this(data, null);
}
// post: constructs a node with given data and given link
public ListNode(int data, ListNode next) {
this.data = data;
this.next = next;
}
}
Xenocide Geek on
i wanted love, i needed love
most of all, most of all
someone said true love was dead
but i'm bound to fall
bound to fall for you
oh what can i do
Two simple approaches without using any fancier data structures to implement your basic linked list class, which would be silly. :P
Sort the list, then count the runs for each item, iterates the list once with no extra storage required.
Add a flag to the nodes, clear them all to start your dupe count, then do two loops where you find an unflagged node, flag it, and start the second loop where you flag all further nodes of that value, counting as you go.
The problem with sorting is that you will need to use an efficient sorting algorithm(merge/quick) or you will be slower than two iterations over the dataset.
The second problem is even easier as it can be done in a single loop and is simply a comparison of nodes value.
The problem with sorting is that you will need to use an efficient sorting algorithm(merge/quick) or you will be slower than two iterations over the dataset.
The second problem is even easier as it can be done in a single loop and is simply a comparison of nodes value.
and the third problem is, that unless you are doing this implementation for Homework, use someone else's objects.
I have a cygwin install and I'm trying to build a curses program.
Single file, building with gcc, just: gcc -lncurses source.c
The source file is:
#include <ncurses/ncurses.h>
int main()
{
initscr();
}
Taking a look at what it's actually doing under the hood, ld is actually reading in the ncurses library at one point in /lib, but I get undefined reference to `_initscr'
Any ideas?
use python and its interface to curses?
yuck, straight curses programming... i guess its better than the alternative....
It's like people who code in Notepad. Sure, you can, but why the hell would you?
For DOM selection and CSS manipulation I use jQuery, but the logical features of jQuery such as custom enumeration functions are slow as fuck and I'm not crazy about some of their event handlers either.
my problem was less with the logic and more with the actual code implementation
my teacher often gives us 2+ weeks to do a given set of assignments, and since i wait until the last minute, i forget what i learned and have to teach myself again
and i am not very fond of java!
but i figured out the second problem without using two loops, using this implementation-
public int countDuplicates() {
ListNode current = front;
int duplicates=0;
while (current.next != null) {
if (current.data == current.next.data) {
duplicates++;
current = current.next;
} else if (current.data < current.next.data) {
current = current.next;
}
}
System.out.println(duplicates);
return duplicates;
}
working on the third problem now, which my biggest problem with is actual syntax in passing a LinkedList and trying to compare against it. coming up against syntax errors, because i forgot the appropriate way to do it.
Xenocide Geek on
i wanted love, i needed love
most of all, most of all
someone said true love was dead
but i'm bound to fall
bound to fall for you
oh what can i do
The problem with sorting is that you will need to use an efficient sorting algorithm(merge/quick) or you will be slower than two iterations over the dataset.
The second problem is even easier as it can be done in a single loop and is simply a comparison of nodes value.
The problem with sorting is that you will need to use an efficient sorting algorithm(merge/quick) or you will be slower than two iterations over the dataset.
The second problem is even easier as it can be done in a single loop and is simply a comparison of nodes value.
and the third problem is, that unless you are doing this implementation for Homework, use someone else's objects.
It is pretty obviously homework which is why there is no code given or suggesting use of other data structures.
It can be done in a single loop but is a time/storage tradeoff since you need something to track already seen values and counts, and your value range may be large (any valid 32 bit int?)
my problem was less with the logic and more with the actual code implementation
my teacher often gives us 2+ weeks to do a given set of assignments, and since i wait until the last minute, i forget what i learned and have to teach myself again
and i am not very fond of java!
but i figured out the second problem without using two loops, using this implementation-
public int countDuplicates() {
ListNode current = front;
int duplicates=0;
while (current.next != null) {
if (current.data == current.next.data) {
duplicates++;
current = current.next;
} else if (current.data < current.next.data) {
current = current.next;
}
}
System.out.println(duplicates);
return duplicates;
}
working on the third problem now, which my biggest problem with is actual syntax in passing a LinkedList and trying to compare against it. coming up against syntax errors, because i forgot the appropriate way to do it.
Your solution is the first I suggested, counting runs in a sorted list. I don't see where you can make the assumption that your list is sorted, since you don't insert in-order, and worse is that your count function will infinite loop if the list is not sorted.
we are just assuming the list is in sorted order, sorry for the confusion
and you're right, it was the first you suggested - i have a really hard time converting pseudocode into workable code for whatever reason, so i didn't see the obv. solution like you suggested
i can do the logic for every one of these assignments, but like i said before, syntactically i end up spending 2 hours trying to write 4 lines of code
after looking at the same problem for 2 hours, you just start to over think it and end up going down roads that you should never venture down!
Xenocide Geek on
i wanted love, i needed love
most of all, most of all
someone said true love was dead
but i'm bound to fall
bound to fall for you
oh what can i do
What's the best way to dive into kernel hacking? I've interviewed for a few internships and missed out because of a lack of kernel experience - I've got a good book on the Linux kernel, the C chops, and a good understanding of hardware architecture and basic OS theory. I just can't think of what to start with for hacking around.
Start by implementing your own serial driver.
The kernel isn't scary, you just need to be meticulous. I wish that I could mentor you on it more, but that requires a close, physical work/school relationship.
we are just assuming the list is in sorted order, sorry for the confusion
and you're right, it was the first you suggested - i have a really hard time converting pseudocode into workable code for whatever reason, so i didn't see the obv. solution like you suggested
i can do the logic for every one of these assignments, but like i said before, syntactically i end up spending 2 hours trying to write 4 lines of code
after looking at the same problem for 2 hours, you just start to over think it and end up going down roads that you should never venture down!
Gotcha, was just confused by the insert given in your code with it.
I have to vent. My greatest pet peeve, I have come across today. Again.
CoreData is the most abused and misused framework in the history of everything.
You don't need a goddamned relational database to store a list of strings, goddamnit.
not strings with associated data. not strings and some other stuff too but in a different table
just one table, one column.
Jasconius on
0
Monkey Ball WarriorA collection of mediocre hatsSeattle, WARegistered Userregular
edited November 2010
Oh, oh, I know this one!
Create and open a bog standard text file;
for each string in string_array
{
Write the damn string to the text file;
End the damn line;
}
Close the file;
Collect paycheck;
Monkey Ball Warrior on
"I resent the entire notion of a body as an ante and then raise you a generalized dissatisfaction with physicality itself" -- Tycho
But coredata is so cool and you get to have the satisfaction of adding right-click->add framework and on your resume you can claim you have CoreData experience!
How does one handle HttpWebRequests in C# to login a web page and then keep those credentials active? Right now it keeps me logged off. I got an idea for a potentially cool application but this is my first time working with web requests and the like in C#.
How does one handle HttpWebRequests in C# to login a web page and then keep those credentials active? Right now it keeps me logged off. I got an idea for a potentially cool application but this is my first time working with web requests and the like in C#.
You need a cookie jar setup properly, not sure how you do it exactly with HttpWebRequests but I would look into the CookieContainer class, are you creating one for your requests?
How does one handle HttpWebRequests in C# to login a web page and then keep those credentials active? Right now it keeps me logged off. I got an idea for a potentially cool application but this is my first time working with web requests and the like in C#.
You need a cookie jar setup properly, not sure how you do it exactly with HttpWebRequests but I would look into the CookieContainer class, are you creating one for your requests?
Does this mean I have to keep the cookie jar and pass it to each web request I create?
Say I create a web request and I know of 3 links that I want to visit after login. I create the cookie jar with the correct data for the web site, create the login request and somehow run a POST? Then in the 3 other requests I make I pass them the cookie jar to use?
How does one handle HttpWebRequests in C# to login a web page and then keep those credentials active? Right now it keeps me logged off. I got an idea for a potentially cool application but this is my first time working with web requests and the like in C#.
You need a cookie jar setup properly, not sure how you do it exactly with HttpWebRequests but I would look into the CookieContainer class, are you creating one for your requests?
Does this mean I have to keep the cookie jar and pass it to each web request I create?
Say I create a web request and I know of 3 links that I want to visit after login. I create the cookie jar with the correct data for the web site, create the login request and somehow run a POST? Then in the 3 other requests I make I pass them the cookie jar to use?
I will read up on the CookieContainer.
Yes, this is exactly what the cookie jar is for and how the web goes from stateless http to a stateful session, it's transparent in use and something most take for granted. Your login process may be done once, but you are presenting your id in some fashion every single time over and over again in the cookies.
But coredata is so cool and you get to have the satisfaction of adding right-click->add framework and on your resume you can claim you have CoreData experience!
Yes, but fuck that guy. Seriously.
Honestly, a simple list of strings? So terrible.
Linden on
0
Monkey Ball WarriorA collection of mediocre hatsSeattle, WARegistered Userregular
edited November 2010
People who do the coding for a living, how often is it that you break tests due to newly implemented features, not because you broke the program in the course of it, but rather because the test assumed the feature didn't exist, so then you have to go and update the test itself to support the new feature.
I could see this being a problem sometimes, but it's hard to tell from my academic point of view.
Also I wish there was a color for sarcasm. Maybe orange? Because everyone knows orange is the best color. I don't know, does that look sarcastic?
Monkey Ball Warrior on
"I resent the entire notion of a body as an ante and then raise you a generalized dissatisfaction with physicality itself" -- Tycho
People who do the coding for a living, how often is it that you break tests due to newly implemented features, not because you broke the program in the course of it, but rather because the test assumed the feature didn't exist, so then you have to go and update the test itself to support the new feature.
I could see this being a problem sometimes, but it's hard to tell from my academic point of view.
Also I wish there was a color for sarcasm. Maybe orange? Because everyone knows orange is the best color. I don't know, does that look sarcastic?
It can be hard to foresee and account for everything, which is why tests will break and need updating, and which is why I don't like TDD. If you don't spend a lot of time writing tests and doing it well, you're going to have a hard time developing what you want, and I find working with a design and coding to that a lot more efficient than looking at the design, implementing the tests, and then doing the code (and fixing up the tests as we go along because no one did them fully).
Infidel on
0
KakodaimonosCode fondlerHelping the 1% get richerRegistered Userregular
People who do the coding for a living, how often is it that you break tests due to newly implemented features, not because you broke the program in the course of it, but rather because the test assumed the feature didn't exist, so then you have to go and update the test itself to support the new feature.
I could see this being a problem sometimes, but it's hard to tell from my academic point of view.
Also I wish there was a color for sarcasm. Maybe orange? Because everyone knows orange is the best color. I don't know, does that look sarcastic?
Yes, when you update the code or implement a new feature you may break tests.
However, if new functionality is frequently breaking existing tests, I would say that you've probably got some odd coupling issues and haven't quite got the separation of concerns down to the right level in your design. Ideally, a new feature won't touch existing features unless as part of the new functionality, you are redesigning/updating existing functionality.
People who do the coding for a living, how often is it that you break tests due to newly implemented features, not because you broke the program in the course of it, but rather because the test assumed the feature didn't exist, so then you have to go and update the test itself to support the new feature.
I could see this being a problem sometimes, but it's hard to tell from my academic point of view.
Also I wish there was a color for sarcasm. Maybe orange? Because everyone knows orange is the best color. I don't know, does that look sarcastic?
I want to raise the point that breaking a test and making a test fail are very different. I work with a testing framework that use image regression tests inside a Qt UI framework. When you implement a new feature you are required to execute all the tests and see which ones break and which ones fail. Broken tests mean that generally the UI has changed and the test needs to be updated, while a regressed tests means you might have broken the rendering engine. Once you have fixed all the broken tests and resolved the regressed tests you commit those changes to the testing framework alongside the feature. So generally while every new feature 'breaks' tests it shouldn't break them for long.
I figured this would be the best place to ask this.
I'm taking an Intro to Java course and we're coming up around finals.
Our final project is a text based maze navigation game (think Shadowgate only much simpler)
In our game you can encounter monsters (turn based combat) my job is to code a part of the game
that keeps track of the player (users) health. Meaning, after having fought a monster and won you would
have 54 HP and when fighting a new monster you still have 54. And when you got down to 0 you would have to start the game over.
The game has a "Fight" class which keeps track of the monsters and players health. But the problem is that the players HP can go into the negatives meaning the player can't die. Whereas the monster can and when you enter a new room with a monster you both have 100 HP again.
I'm still new to Java so any jumping off points or tips would be appreciated.
I can/will post the code I currently have later on.
just gonna throw this out there, noting that i am not a programmer but i took a few classes in school
but how does the fight class work? do you have an object for the player? what's the overall structure of your program in terms of objects and classes?
it would make sense to have objects for the player and the monsters, and for each encounter you enter them as input into the fight class, with the fight class checking the health of each each turn, and if ones health is <=0 then the player either dies or the monster wins the game
I don't know, just seems like you'd check if the players health is at or below 0 to counter-act that. Seems that the objects get reinitialized when moving between rooms if they both get reset to 100.
bowen on
not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
State such as the player's current health, items, status effects, etc has to be maintained at a higher level than at individual fights; if you want you can initialize a Fight instance from the Player object that should store all of this and then load the result back into the Player class at the end
Posts
Here is a test to see if I was able to make a successful SQL update
I may have to clean that up a little
Somehow having a pointer to another pointer seems weird or obfuscatory to me, but trying to define it as an array makes functions complain. I understand an array and a pointer are basically the same thing, but is this the right way to do this?
Yes, this is correct.
You have a pointer, which as you say can be considered an array (indexing is just dereferencing with an addition first) and then what is your array made of?
Foo *
So it's an array of Foo pointers. Your FooTable variable t say is a pointer to memory, when you dereference it it will be of type Foo *, all is good. If you index it, it will be of type Foo *, since index == dereference. There is nothing wrong or bizarre here once you get the feel for it. As you've probably seen others and I mentioning before, var[x] is the same as *(var + x).
I'm actually a fan of GWT(Google Web Toolkit) which lets you program in JAVA and it translates it into JS. It creates different permutations for each of the main web browsers. I'd say it works 95% of the time, sometimes one of the browsers (Usually IE) will render something how you didn't want to.
But being able to code websites in Java and use to a lot of Google's awesome APIs allows for some awesome stuff quickly.
Use jQuery, takes care of cross browser bullshit and the DOM for you. Slips in next to frameworks and works solely on javasript, client side, with there being Ajax modules.
Joe's Stream.
THE EASTER BUNNY IS A LIE!!!!
Joe's Stream.
It's hard to suggest a proper language to start off in. C++ can be incredibly obtuse, and its advanced features (STL) are tough to learn. A proper toolkit like QT takes care of most of the ickiness for you, though.
But in terms of learning... Just to disagree with the thread title, I'd have to go with Python for the first language. No, not Java. Either that, or C, just so people get an appreciation of what's actually going on.
Joe's Stream.
No one codes straight JS anymore. Frameworks are the way to go.
Switch: SW-3515-0057-3813 FF XIV: Q'vehn Tia
Well. I used to. Now I don't do any JS at all, so nyah.
first thing:
i'm creating a new LinkedList class of integers, and i'm just adding basic/meh functionality to it.
i figured out some of it, but i'm stuck on a few key methods, such as:
a "count duplicate" method, which counts the number of times a number appears in the list of integers. i.e., you have the number of 3, it appears 4 times throughout the list, you have 3 duplicates of it. add it a counter called duplicates. do the same thing with the next number, add to the counter, finally display the result at the end.
i'll post what i currently have - the only way i can think of right now to make it work is with two while loops, and that just does not seem OK to me.
public void countDuplicates() { ListNode current = front; int value = current.data; int duplicates=0; while (current.next != null) { if (value==current.data) { duplicates++; } current = current.next; } System.out.println(duplicates); }the other problem i'm tripping up on is basically an equals method, which returns true when the two LinkedLists are exactly the same (same values in the same order and the same length), and returns false if anything is off.
for whatever reason, i can't get my brain around what needs to be done logically, and it's very much like hitting my face against a brick wall over and over.
here's the full class + the ListNode class which is what allows for listnode objects.
import java.util.NoSuchElementException; // Simple first version of LinkedIntList with just a constructor // and methods for add and toString. public class LinkedIntList { private ListNode front; // first value in the list // post: constructs an empty list public LinkedIntList() { front = null; } // post: returns comma-separated, bracketed version of list public String toString() { if (front == null) { return "[]"; } else { String result = "[" + front.data; ListNode current = front.next; while (current != null) { result += ", " + current.data; current = current.next; } result += "]"; return result; } } // post: appends the given value to the end of the list public void add(int value) { if (front == null) { front = new ListNode(value); } else { ListNode current = front; while (current.next != null) { current = current.next; } current.next = new ListNode(value); } } // post: finds the minimum value in a LinkedList using a while loop. public int min() { if (front == null) { throw new NoSuchElementException(); } else { ListNode current = front; int oldMin = 0; while (current.next != null) { if (current.data < oldMin) { oldMin = current.data; } System.out.println("A"); current = current.next; } return oldMin; } } public void countDuplicates() { ListNode current = front; int value = current.data; int duplicates=0; while (current.next != null) { if (value==current.data) { duplicates++; } current = current.next; } System.out.println(duplicates); } public boolean equals(LinkedIntList a) { ListNode current = front; bada = front; while (current.next != null) { if (current.data != data) { return false; } else {return true;} } } }// ListNode is a class for storing a single node of a linked // list. This node class is for a list of integer values. public class ListNode { public int data; // data stored in this node public ListNode next; // link to next node in the list // post: constructs a node with data 0 and null link public ListNode() { this(0, null); } // post: constructs a node with given data and null link public ListNode(int data) { this(data, null); } // post: constructs a node with given data and given link public ListNode(int data, ListNode next) { this.data = data; this.next = next; } }most of all, most of all
someone said true love was dead
but i'm bound to fall
bound to fall for you
oh what can i do
Sort the list, then count the runs for each item, iterates the list once with no extra storage required.
Add a flag to the nodes, clear them all to start your dupe count, then do two loops where you find an unflagged node, flag it, and start the second loop where you flag all further nodes of that value, counting as you go.
Quite a few ways you could go about it.
The second problem is even easier as it can be done in a single loop and is simply a comparison of nodes value.
and the third problem is, that unless you are doing this implementation for Homework, use someone else's objects.
Joe's Stream.
use python and its interface to curses?
yuck, straight curses programming... i guess its better than the alternative....
Joe's Stream.
For DOM selection and CSS manipulation I use jQuery, but the logical features of jQuery such as custom enumeration functions are slow as fuck and I'm not crazy about some of their event handlers either.
my teacher often gives us 2+ weeks to do a given set of assignments, and since i wait until the last minute, i forget what i learned and have to teach myself again
and i am not very fond of java!
but i figured out the second problem without using two loops, using this implementation-
public int countDuplicates() { ListNode current = front; int duplicates=0; while (current.next != null) { if (current.data == current.next.data) { duplicates++; current = current.next; } else if (current.data < current.next.data) { current = current.next; } } System.out.println(duplicates); return duplicates; }working on the third problem now, which my biggest problem with is actual syntax in passing a LinkedList and trying to compare against it. coming up against syntax errors, because i forgot the appropriate way to do it.
most of all, most of all
someone said true love was dead
but i'm bound to fall
bound to fall for you
oh what can i do
It is pretty obviously homework which is why there is no code given or suggesting use of other data structures.
It can be done in a single loop but is a time/storage tradeoff since you need something to track already seen values and counts, and your value range may be large (any valid 32 bit int?)
Your solution is the first I suggested, counting runs in a sorted list. I don't see where you can make the assumption that your list is sorted, since you don't insert in-order, and worse is that your count function will infinite loop if the list is not sorted.
and you're right, it was the first you suggested - i have a really hard time converting pseudocode into workable code for whatever reason, so i didn't see the obv. solution like you suggested
i can do the logic for every one of these assignments, but like i said before, syntactically i end up spending 2 hours trying to write 4 lines of code
after looking at the same problem for 2 hours, you just start to over think it and end up going down roads that you should never venture down!
most of all, most of all
someone said true love was dead
but i'm bound to fall
bound to fall for you
oh what can i do
Start by implementing your own serial driver.
The kernel isn't scary, you just need to be meticulous. I wish that I could mentor you on it more, but that requires a close, physical work/school relationship.
Joe's Stream.
Gotcha, was just confused by the insert given in your code with it.
well, not in java, but on linux, "wc file.txt".
Joe's Stream.
CoreData is the most abused and misused framework in the history of everything.
You don't need a goddamned relational database to store a list of strings, goddamnit.
not strings with associated data. not strings and some other stuff too but in a different table
just one table, one column.
Create and open a bog standard text file; for each string in string_array { Write the damn string to the text file; End the damn line; } Close the file; Collect paycheck;You need a cookie jar setup properly, not sure how you do it exactly with HttpWebRequests but I would look into the CookieContainer class, are you creating one for your requests?
Does this mean I have to keep the cookie jar and pass it to each web request I create?
Say I create a web request and I know of 3 links that I want to visit after login. I create the cookie jar with the correct data for the web site, create the login request and somehow run a POST? Then in the 3 other requests I make I pass them the cookie jar to use?
I will read up on the CookieContainer.
Yes, this is exactly what the cookie jar is for and how the web goes from stateless http to a stateful session, it's transparent in use and something most take for granted. Your login process may be done once, but you are presenting your id in some fashion every single time over and over again in the cookies.
Yes, but fuck that guy. Seriously.
Honestly, a simple list of strings? So terrible.
I could see this being a problem sometimes, but it's hard to tell from my academic point of view.
Also I wish there was a color for sarcasm. Maybe orange? Because everyone knows orange is the best color. I don't know, does that look sarcastic?
It can be hard to foresee and account for everything, which is why tests will break and need updating, and which is why I don't like TDD. If you don't spend a lot of time writing tests and doing it well, you're going to have a hard time developing what you want, and I find working with a design and coding to that a lot more efficient than looking at the design, implementing the tests, and then doing the code (and fixing up the tests as we go along because no one did them fully).
Yes, when you update the code or implement a new feature you may break tests.
However, if new functionality is frequently breaking existing tests, I would say that you've probably got some odd coupling issues and haven't quite got the separation of concerns down to the right level in your design. Ideally, a new feature won't touch existing features unless as part of the new functionality, you are redesigning/updating existing functionality.
I want to raise the point that breaking a test and making a test fail are very different. I work with a testing framework that use image regression tests inside a Qt UI framework. When you implement a new feature you are required to execute all the tests and see which ones break and which ones fail. Broken tests mean that generally the UI has changed and the test needs to be updated, while a regressed tests means you might have broken the rendering engine. Once you have fixed all the broken tests and resolved the regressed tests you commit those changes to the testing framework alongside the feature. So generally while every new feature 'breaks' tests it shouldn't break them for long.
I'm taking an Intro to Java course and we're coming up around finals.
Our final project is a text based maze navigation game (think Shadowgate only much simpler)
In our game you can encounter monsters (turn based combat) my job is to code a part of the game
that keeps track of the player (users) health. Meaning, after having fought a monster and won you would
have 54 HP and when fighting a new monster you still have 54. And when you got down to 0 you would have to start the game over.
The game has a "Fight" class which keeps track of the monsters and players health. But the problem is that the players HP can go into the negatives meaning the player can't die. Whereas the monster can and when you enter a new room with a monster you both have 100 HP again.
I'm still new to Java so any jumping off points or tips would be appreciated.
I can/will post the code I currently have later on.
but how does the fight class work? do you have an object for the player? what's the overall structure of your program in terms of objects and classes?
it would make sense to have objects for the player and the monsters, and for each encounter you enter them as input into the fight class, with the fight class checking the health of each each turn, and if ones health is <=0 then the player either dies or the monster wins the game