• Hey, guest user. Hope you're enjoying NeoGAF! Have you considered registering for an account? Come join us and add your take to the daily discourse.

Programming |OT| C is better than C++! No, C++ is better than C

pompidu

Member
edit

Assume that there are only two stations A and B in a bus CSMA/CD network. The distance between the two stations is 2000 m and the propagation speed is 2 x 10^8 m/sec. If station A starts transmitting at time t1, does the protocol allow station B to start transmitting at time t1 + 8 micro-sec? Show the calculations you did to arrive at your answer. Use the HTML editor (instead of simply copy-pasting into the textbox). If the answer is yes, what will happen?
 

maeh2k

Member
Ugh, getting really frustrated with this class since the HW questions are not actually taught in class. Anyone help on this? I'm not sure if the protocol allows B to send since idk what to do with ti + 8 micro-seconds. Thanks Guys.

To get from A to B the signal takes 10 microseconds (2000m / 2*10^8 m/s).
At ti + 8 microseconds B doesn't know that a signal is coming, so it is allowed to send.
However, a collision is going to occur shortly thereafter.

Then it goes into the Collision Detected procedure here: http://en.wikipedia.org/wiki/Carrier_sense_multiple_access_with_collision_detection

If you want to give a detailed answer, you'll have to read up further on collisions. There are probably some really detailed examples somewhere on the internet.
 

pompidu

Member
To get from A to B the signal takes 10 microseconds (2000m / 2*10^8 m/s).
At ti + 8 microseconds B doesn't know that a signal is coming, so it is allowed to send.
However, a collision is going to occur shortly thereafter.

Then it goes into the Collision Detected procedure here: http://en.wikipedia.org/wiki/Carrier_sense_multiple_access_with_collision_detection

If you want to give a detailed answer, you'll have to read up further on collisions. There are probably some really detailed examples somewhere on the internet.

ah sweet thanx dude. Appreciate it. Il check those wikis out, text book does a terrible job at explaining it.
 

NotBacon

Member
That you for the input! I would rather not get a cheap/lower end windows notebook. Bad experiences in the past. I would spend $700+ on a laptop if the Chromebook route isn't ideal. Of course, I would have to save up and wouldn't buy it until early next year. Thanks again for your help!

Definitely check out Slick Deals. If you check it regularly, you can score some insane deals. I'm posting this from an Asus Zenbook UX31A(running Linux of course) I bought a year ago for 519. It was refurbished with a hairline scratch, but I literally saved me 500 dollars. I think my exact model still goes for around 800 these days.

BTW I'd try to stick to Lenovo, Asus, Sony, Acer, and maybe Samsung
 

hateradio

The Most Dangerous Yes Man
I'd like to look at the pic but the link doesn't work.
Really wish I had the time to take that course, first one was pretty great.

BTW, anyone know of any online courses using Haskell...?
Not that it matters, but here's the image (rehosted).

eX00wpd.png
 

Water

Member
I'm starting intro to CS next year and would like to have a laptop. Being a college student, I'm naturally broke. I was thinking about getting a Chromebook when I read about the web IDE's. Is that a viable option? Or should I try to spring for a laptop?

I should say that I have a desktop at home, and the Chromebook/laptop would be used around school to program on my break/whenever.
That's a big no. If you are a CS student, Chromebooks are not for you. CS is not power intensive at all, so you don't need a desktop to work. I recently sold off my old Macbook Air with a Core 2 Duo processor from late 2010, and even that would still be a viable machine. If you invest in a decent laptop it's enough to do your work anywhere you want. Between lectures, during lectures, while commuting. I can't emphasize enough how useful it is to have a proper laptop. If you wish, at the desk you can connect an external display and keyboard, no loss of ergonomics there.

Key qualities to look for in a laptop for miscellaneous CS stuff:
  • Good keyboard, trackpad and general feel of the hardware. These are often surprisingly bad in cheap laptops. Do not buy any unknown machine without touching it first. Apple laptops and Lenovo Thinkpads are the gold standard here. Most manufacturers have "entertainment tier" laptops and "business tier" laptops; the latter have worse specs at the price, but they are generally the right ones to buy.
  • Good display with at least decent resolution. I have 1440x900, and I strongly advise to get at least that much, and a minimum of 13" display size.
  • Battery life / size / weight. You might have to compromise on some of this, but be aware that it has real value in a work machine that is always with you.
  • (nice to have) Either a Mac, so you can run OS X, or a machine with hardware that has good Linux support. Windows isn't optimal for many things in CS. You can have Windows installed also, and boot to either when necessary.
Buying used could be an option, but I'd look for a machine that either has some warranty left or is dirt cheap.
 

nan0

Member
I need some career advice. I'm currently applying my first job in my field (medical CS) and currently have two invitations for an interview:

The first is a small startup company, very close to my place (commute is ~10 minutes), where my job is Java and C# development (both my primary languages). I'll have flexible working hours, and the short commute is for personal reasons currently a very big plus for me. I'm also positive that I can (quickly) get the job, since their field is very niche but fits almost exactly my qualifications. However, I guess the payment will be avarage at best.

The second one is a top-national hospitals, but with a longer commute (~30 Minutes) where I'm working on their overall architecture and its advancement. I have flexible working hours and stuff like a company physician. Their name alone would look very, very nice on my CV. However, since I'm kinda surprised they even invited me, it will probably take quite a long time until I get or won't get the acceptance after the interview (it's a big company, and they probably have to evaluate quite a lot of applicants). I'll get a standard wage, which is probably a bit higher than in the startup.

I wasn't at the interviews yet, so if I completely dislike one of them, they're obviously out. I have the first interview with the first company next week, the other one in three weeks. I could probably get to accept the first job quicker than I can take the second interview, but If I wait for the second one, I may lose both offers if thing to wrong. I realize that it's not a lifetime job and unless I like the job very much, will probably look for something better after I get a year or more of experience anyway.

Should I get the first job if I'm offered it, or should I risk trying to get the second? I currently tend to go for the first, since I want to become financially independent from my parents, and it's much closer to my home which is currently a big perk for me.
 

Water

Member
The first is a small startup company, very close to my place (commute is ~10 minutes), where my job is Java and C# development (both my primary languages). I'll have flexible working hours, and the short commute is for personal reasons currently a very big plus for me. I'm also positive that I can (quickly) get the job, since their field is very niche but fits almost exactly my qualifications. However, I guess the payment will be avarage at best.

The second one is a top-national hospitals, but with a longer commute (~30 Minutes) where I'm working on their overall architecture and its advancement. ... Their name alone would look very, very nice on my CV.
I think you are right to not emphasize pay in your choice of first job. Commute matters in the long run - the difference between those options is 40 minutes of your day every day - but 30 minutes really isn't a long commute.

I wonder if you are overestimating the hospital's value on your CV. As prestigious they may be, I'm sure they didn't get prestigious with the strength of their software development. If you were a surgeon, it'd be a different matter.

What I'd look at carefully is which place grows your actual skills more. It seems likely to me that a tech-based startup would surround you with more hardcore programmers than a hospital. The interview is the place to verify that. Interview the company, not just the other way around.
 
I just spent most of the day reading about demultiplexers thanks to that Scala reactive programing course. My brain was friend after looking at this image that someone made, but then . . . it made sense. It was the weirdest sensation, being confused and understanding.

As with the other course, I wish certain things were explained a little better or at least given external resources to research.
I just started doing the assignments for the course yesterday and man, first week's assignments were way easier. The epidemic simulation is really cool though, it's fun to tinker around with.
 

hateradio

The Most Dangerous Yes Man
I just started doing the assignments for the course yesterday and man, first week's assignments were way easier. The epidemic simulation is really cool though, it's fun to tinker around with.
The epidemy problem seemed a lot more difficult that it actually was. Especially after looking at some of the comments.

Thankfully I finished it yesterday; I got a 10.
 

AngryMoth

Member
I have a html/php question if someone can help me out? I'm a beginner so please bare with me.

I am implementing the login system for my website. I have set up the login form on my homepage and written the php code which verifies the username and password. What I want is to redirect back to the homepage upon a successful login and have a welcome message displayed in place of the login form, but I don't know how to go about this. Like, how do I 'switch off' that part of the html code and put the welcome message in it's place?
 
I have a html/php question if someone can help me out? I'm a beginner so please bare with me.

I am implementing the login system for my website. I have set up the login form on my homepage and written the php code which verifies the username and password. What I want is to redirect back to the homepage upon a successful login and have a welcome message displayed in place of the login form, but I don't know how to go about this. Like, how do I 'switch off' that part of the html code and put the welcome message in it's place?

Well, you could just echo the HTML for the successful login via PHP if they are indeed logged in. Otherwise, you can echo the HTML for the login form.

Example:

Code:
// $logged_in is determined somewhere in your php to see if a user is logged in
if($logged_in) {
   echo "<h1>Welcome!</h1>";
}
else {
    echo "Login form HTML stuff";
}

If there's going to be a lot of stuff changing depending on whether a user is logged in or not, I recommend looking into some sort of templating engine. (Just doing what I showed in the example above is fine for a few cases, but VERY quickly becomes unmanageable without some sort of templating.) Basically, they let you easily change the HTML you're sending to the client based on various conditions on the server side (whether the user is logged in for example). I'm not familiar enough with PHP to recommend a good templating solution for it, but I use Jinja2 when doing webdev in Python.
 

AngryMoth

Member
Well, you could just echo the HTML for the successful login via PHP if they are indeed logged in. Otherwise, you can echo the HTML for the login form.

Example:

Code:
// $logged_in is determined somewhere in your php to see if a user is logged in
if($logged_in) {
   echo "<h1>Welcome!</h1>";
}
else {
    echo "Login form HTML stuff";
}

If there's going to be a lot of stuff changing depending on whether a user is logged in or not, I recommend looking into some sort of templating engine. (Just doing what I showed in the example above is fine for a few cases, but VERY quickly becomes unmanageable without some sort of templating.) Basically, they let you easily change the HTML you're sending to the client based on various conditions on the server side (whether the user is logged in for example). I'm not familiar enough with PHP to recommend a good templating solution for it, but I use Jinja2 when doing webdev in Python.
Thanks very much I forgot you can echo html. Using a templating engine sounds nice but my website is for an assessment and I'm not sure if it would be allowed. Our lecturer seems to want us to do things 'from scratch', only API's we're allowed to use are JQuery and PDO. I'll ask though.
 
Thanks very much I forgot you can echo html. Using a templating engine sounds nice but my website is for an assessment and I'm not sure if it would be allowed. Our lecturer seems to want us to do things 'from scratch', only API's we're allowed to use are JQuery and PDO. I'll ask though.

If it's just going to be a couple of things, then a couple of echo statements should be fine. When you've got an app that does a lot of server-side stuff to generate the HTML that you'll be sending, that's when you definitely want to look into templates and probably an MVC type architecture.
 
Put together a little project today. It's called Chaturly and the idea is that people can chat about specific URLs. It didn't take long to do but let me know what you think.

Submitted it to HackerNews as well, so any up votes would be much appreciated!

Chaturly on HackerNews

Chaturly

Cool!

Coupla small things I noticed. Would it be possible to validate the url's based on whether they have a correct TLD instead of http:// ? That would make it easier to type url's in. Also, I noticed it doesn't seem to do any checking to make sure you have a TLD as long as there's an http://. e.g., putting in "http://fjdsklfjdlskfj" seems to work, but "google.com" does not.

Thought of putting a list of url's recently commented on, or popular urls? So that someone could jump in real quick and see what others are saying about it?
 
Cool!

Coupla small things I noticed. Would it be possible to validate the url's based on whether they have a correct TLD instead of http:// ? That would make it easier to type url's in. Also, I noticed it doesn't seem to do any checking to make sure you have a TLD as long as there's an http://. e.g., putting in "http://fjdsklfjdlskfj" seems to work.

Thought of putting a list of url's recently commented on, or popular urls? So that someone could jump in real quick and see what others are saying about it?

Validation of URLs was a bit of a nightmare to be honest. I'll probably refactor it as I just put something quick in to get it out there. I'd like to be able to support FTP and other valid URLs as well, instead of just http/https. It's more complicated than I thought it would be!

The way the friendly URLs are generated is a bit rough as well, with validation only happening via the home page at the moment.

I was thing of a page showing the newest/most popular URLs as well as allowing users to filter by host name, for similar URLs. There also needs to be usernames and post numbers to allow people to actually chat properly. It's all anonymous at the moment.

Thanks for the feedback.
 
The way you have it setup now, your logic says that "If any of these are not true...". This would be a problem since input can only equal one thing, not three!

that's true and I'm still honestly stumped on this. can I get a hint at what I need to do? also,I want to validate a user's ssn and only the ssn but that validation for the ssn is in another class. I was told to use something called a dummy(?) class. unfortunately, the instructor didn't really explain it that well.
 

Atruvius

Member
so in java, how do insure that the user has to select from the three letter choices provided? I'm trying to insure that user selects from Y for yes, N for no or O for other.

I tried

if(input!= "Y" || input != "N"|| input!= "O")

{
return false;
}

but that does not work because it won't let the user move on becuase despite making the right choice the comp still counts it as invalid. could someone give me a hint at what I did wrong? do I have to code in stacked if statements?

I believe this should work:

if(input.equals("Y")==false && input.equals ("N")==false && input.equals( "O")==false)

{
return false;
}
 

Zoe

Member
Thanks very much I forgot you can echo html. Using a templating engine sounds nice but my website is for an assessment and I'm not sure if it would be allowed. Our lecturer seems to want us to do things 'from scratch', only API's we're allowed to use are JQuery and PDO. I'll ask though.

I'm not too familiar with php, but can't you echo content from a sub page? ASP.NET MVC has these as "partials".
 

phoenixyz

Member
I believe this should work:

if(input.equals("Y")==false && input.equals ("N")==false && input.equals( "O")==false)

{
return false;
}

My Java is a bit rusty, but equals should return a boolean, so

Code:
if(!(input.equals("Y") || input.equals("N") || input.equals("O"))) {
    return false;
}

should work and is a bit easier to read.
 

Dr_Swales

Member
My Java is a bit rusty, but equals should return a boolean, so

Code:
if(!(input.equals("Y") || input.equals("N") || input.equals("O"))) {
    return false;
}

This one, I think the problem unknownhero was having was the positioning of his parenthesis. Its usually a good idea to group your conditions like phoenixyz has here.

You could also use the is equalsIgnoreCase to make sure the case of the letter is not effecting the conditionals, using phoenixyz's code

Code:
if(!(input.equalsIgnoreCase("Y") || input.equalsIgnoreCase("N") || input.equalsIgnoreCase("O"))) {
    return false;
}
 
Hey guys, just found this thread and I wanted to ask a question to all of you:

I'm looking to learn more about CUDA and parallel programming but I'm having a hard time grasping some of the concepts. Is there any kind of book/tutorial that you would recommend to beginners?
 
Hey guys, just found this thread and I wanted to ask a question to all of you:

I'm looking to learn more about CUDA and parallel programming but I'm having a hard time grasping some of the concepts. Is there any kind of book/tutorial that you would recommend to beginners?

I don't really know much about CUDA or parallel programming, but Udacity has a free course on it:

https://www.udacity.com/course/cs344

I haven't taken that one, so I can't speak to the quality, but Udacity courses are generally excellent.
 

jokkir

Member
What's a good resource to look up tutorials and such with data structures like Linked Lists (Single, Double, etc), Binary Trees and so on?

So far I only have my notes and using YouTube on tutorials so I understand it more clearly (I think I'm more of a visual learner lol >__>)
 
Started a course in programming lately alongside my Maths degree. I'm just starting but I love it. I do absolutely hate the IDE we're using for it which is blueJ and it annoys me to no end. Obviously we're hoping to move on to something more flexible in the future, but does anyone have any guides or anything which might help with making the transition by myself? Thanks in advance.
 

usea

Member
What's a good resource to look up tutorials and such with data structures like Linked Lists (Single, Double, etc), Binary Trees and so on?

So far I only have my notes and using YouTube on tutorials so I understand it more clearly (I think I'm more of a visual learner lol >__>)
I mostly learned these concepts from wikipedia.
 
My Java is a bit rusty, but equals should return a boolean, so

Code:
if(!(input.equals("Y") || input.equals("N") || input.equals("O"))) {
    return false;
}

should work and is a bit easier to read.

it works! thank you guys!

btw, if I wanted to validate a person's full name, how do I ensure they place a space?
 
Hey guys, just found this thread and I wanted to ask a question to all of you:

I'm looking to learn more about CUDA and parallel programming but I'm having a hard time grasping some of the concepts. Is there any kind of book/tutorial that you would recommend to beginners?

I don't really know much about CUDA or parallel programming, but Udacity has a free course on it:

https://www.udacity.com/course/cs344

I haven't taken that one, so I can't speak to the quality, but Udacity courses are generally excellent.
I've taken some of this course (did not complete it, I really should though, the subject is pretty cool) and it's very well done. The concepts are explained well and you can do the assignments in your browser, so even if you don't have a CUDA-capable graphics card, you can still do them. That's probably my biggest criticism of the class, CUDA is proprietary is only supported on Nvidia cards. However, once you know the basics of CUDA, I don't think switching over to OpenCL should be too hard.
 

usea

Member
it works! thank you guys!

btw, if I wanted to validate a person's full name, how do I ensure they place a space?
something like this:
Code:
String name = "Scott Summers";
bool nameHasSpace = name.contains(" "); //true

I get that this is probably part of the assignment, but remember to never validate names in real production code, unless it's required by some legacy system. Not all names have spaces, or two words, or middle names, etc etc.

Falsehoods programmers believe about names
 
something like this:
Code:
String name = "Scott Summers";
bool nameHasSpace = name.contains(" "); //true

I get that this is probably part of the assignment, but remember to never validate names in real production code, unless it's required by some legacy system. Not all names have spaces, or two words, or middle names, etc etc.

Falsehoods programmers believe about names

Also, this article: Personal names around the world, which expands on some of the concepts of the linked article.
 
something like this:
Code:
String name = "Scott Summers";
bool nameHasSpace = name.contains(" "); //true

I get that this is probably part of the assignment, but remember to never validate names in real production code, unless it's required by some legacy system. Not all names have spaces, or two words, or middle names, etc etc.

Falsehoods programmers believe about names

gotcha and one last thing before I leave this thread for a while. say that I want to make sure a person has his/her ssn validated but that validation is in another class. how do I invoke the validation to the main class?
 
Playing around with jquery, php, and html, and I need some help.
I have two drop down menus of cities that are both connected to a database of the same table. One is displayed right away, the other his hidden until the first drop down menu is no longer the default. The default is an "all" where I will display all cities. What I'm trying to do is remove the element that was first selected in the first drop down menu. I came across this:
http://jsfiddle.net/m8QCZ/50/
and tried it out, but while it works for some of the cities, it doesn't work for all. Plus, I don't really understand what's going on in that code since I'm still new to javascript. Is there a way I can do this in jquery?
 

usea

Member
gotcha and one last thing before I leave this thread for a while. say that I want to make sure a person has his/her ssn validated but that validation is in another class. how do I invoke the validation to the main class?
This can be done a bunch of ways. Here is a common one:
Code:
public class SocialSecurityNumberValidator {
    public bool validate(String ssn) {
        //validate ssn here, return true (valid) or false (invalid)
    }
}

public class MainAssignmentThingy {
    private SocialSecurityNumberValidator ssnValidator;
    
    public static void main(String[] args) {
        MainAssignmentThingy assign = new MainAssignmentThingy();
        assign.do_the_work();
    }

    public MainAssignmentThingy() {
        this.ssnValidator = new SocialSecurityNumberValidator();
    }
    
    public void do_the_work() {
        //your main code is here
        //validate a ssn:
        String ssn = somehowGetSSN();
        boolean ssnIsValid = this.ssnValidator.validate(ssn);
    }
}

You could also just make everything static and call the function directly.
 
I don't really know much about CUDA or parallel programming, but Udacity has a free course on it:

https://www.udacity.com/course/cs344

I haven't taken that one, so I can't speak to the quality, but Udacity courses are generally excellent.



I've taken some of this course (did not complete it, I really should though, the subject is pretty cool) and it's very well done. The concepts are explained well and you can do the assignments in your browser, so even if you don't have a CUDA-capable graphics card, you can still do them. That's probably my biggest criticism of the class, CUDA is proprietary is only supported on Nvidia cards. However, once you know the basics of CUDA, I don't think switching over to OpenCL should be too hard.

Thanks guys, looking into it ;)
 

Dr_Swales

Member
Code:
if(input!= "Y" || input != "N"|| input!= "O")
{
    return false;
}

Declare me null if I'm wrong.

One last thing... the reason this was not working as expected is because in Java (I think) when you compare an OBJECT (a string is an object) using == or != for example it compares the address of the object not the value.

This is the reason for using the methods in the string class such as .equals() and .equalsIgnoreCase() to compare the values stored in the string.
 
This can be done a bunch of ways. Here is a common one:
insert help here
You could also just make everything static and call the function directly.

thanks!

shit, I think the isLetter() is interfering with the space validation. well, shit. I'm not having a good week.
 

Onemic

Member
Have a slight problem. My function is supposed to simplify fractions and for some reason the denominator always equals zero if the function goes through the first if statement. Anyone knwo why this is the case?

Code:
void simplify(int *numerator, int *denominator) {
[B]    if(*denominator % *numerator == 0) {
        *denominator /= *numerator;
        *numerator = *numerator / *numerator;
    }[/B]
    if(*denominator = 0) {
        printf("invalid entry\n");
    }
    while(*denominator % 2 == 0 && *numerator % 2 == 0) {
        *numerator /= 2;
        *denominator /= 2;
    }
}

If I pass 7 as the numerator and 21 as the denominator I'll get 1/0 instead of 1/3.
 

Tamanon

Banned
Have a slight problem. My function is supposed to simplify fractions and for some reason the denominator always equals zero if the function goes through the first if statement. Anyone knwo why this is the case?

Code:
void simplify(int *numerator, int *denominator) {
[B]    if(*denominator % *numerator == 0) {
        *denominator /= *numerator;
        *numerator = *numerator / *numerator;
    }[/B]
    if(*denominator = 0) {
        printf("invalid entry\n");
    }
    while(*denominator % 2 == 0 && *numerator % 2 == 0) {
        *numerator /= 2;
        *denominator /= 2;
    }
}

If I pass 7 as the numerator and 21 as the denominator I'll get 1/0 instead of 1/3.

I'm guessing it's the one = sign in your denominator = 0 statement. The logic seems sound. And it worked perfectly fine in my Python conversion of the code.
 
I'm guessing it's the one = sign in your denominator = 0 statement. The logic seems sound. And it worked perfectly fine in my Python conversion of the code.

Yeah, that's most likely it.

The fact that C/C++ lets you do assignments in conditional statements sure results in a lot of difficult to find bugs.

I've made that mistake enough times myself that it's one of the first things I check now when my code isn't doing what I expect. But I prefer how, say, Python doesn't even let you do that.
 
Top Bottom