• 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

Pau

Member
So I can't seem to figure out how to install python module on Mac. I thought I had installed pip and thought everything had worked, python tells me that none of the modules have install.

I have no idea what's going on.

I'm trying to install xlrd. Typed in Terminal:
Code:
pip install --user xlrd

And got this:
Code:
Traceback (most recent call last):
  File "/usr/local/bin/pip", line 5, in <module>
    from pkg_resources import load_entry_point
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 2603, in <module>
    working_set.require(__requires__)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 666, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 565, in resolve
    raise DistributionNotFound(req)  # XXX put more info here
pkg_resources.DistributionNotFound: pip==6.0.6

What's going wrong?
 

leroidys

Member
I tried looking online, but I haven't been able to stumble across a solution. I'm very, very new to Python and I'm learning while coding for this intern project I have been assigned to. I was web scraping data previously, and now, I'm trying to use a csv file to output the information.

The csv file contains a bunch of info (ObjectID, Boro, Type, Provider, Name, etc) and I'm trying to just grab three pieces of info (Name, Lat and Long). I have been able to grab the info that I need, but here is the problem: some of the info is missing a name and it shows up as a blank line in the output shell. I was wondering how I can skip any info that contains blank lines.

Edit- I'm using Python 2.7.

Here is the code that I am using:

Code:
import csv

with open ('NYC_Free_Public_WiFi_12052014.csv') as csvfile:
    reader = csv.DictReader(csvfile)
    for row in reader:
        print(row['Name'])
        print(eval(row['Lat']))
        print(eval(row['Long_']))
        print ('')

Here is (some) of the output:




There are 50+ pieces of info that are missing the name. Either skipping or putting a generic name would help tremendously. If someone help or point me in the right direction, I would love you forever. Thanks.

I'm not sure I understand. Can't you just check if the element is not empty before you print it? Also, why are you printing an empty string at the end?
 

GK86

Homeland Security Fail
I'm not sure I understand. Can't you just check if the element is not empty before you print it? Also, why are you printing an empty string at the end?


The empty string at the end is to make the output results more readable.
 

Zeus7

Member
Quick question.

What is the best way to connect to a database using C# & Visual Studio 13?

I have tables in Access which I can connect to. I am just wondering if there would be any other ways of doing it which would be better in any way, such as using SQL server instead of Access, or is it 6 and half a dozen?

Thanks
 

Zoe

Member
Quick question.

What is the best way to connect to a database using C# & Visual Studio 13?

I have tables in Access which I can connect to. I am just wondering if there would be any other ways of doing it which would be better in any way, such as using SQL server instead of Access, or is it 6 and half a dozen?

Thanks

Anything is better than Access.

My preference is SQL Server, but the library calls are pretty much the same for any RDBMS.
 

Kalnos

Banned
Quick question.

What is the best way to connect to a database using C# & Visual Studio 13?

I have tables in Access which I can connect to. I am just wondering if there would be any other ways of doing it which would be better in any way, such as using SQL server instead of Access, or is it 6 and half a dozen?

Thanks

SQL and Entity framework, IMO.
 

Zeus7

Member
Anything is better than Access.

My preference is SQL Server, but the library calls are pretty much the same for any RDBMS.

SQL and Entity framework, IMO.

Thanks for the replies. I am trying to find a good tutorial or book online to create and connect to a database from a Windows Forms Application. Nothing I have found so far explains step by step!
 
Anything is better than Access.

My preference is SQL Server, but the library calls are pretty much the same for any RDBMS.

In fairness it depends on your use case. When I was in college I worked for the access and disability office to build a system for them to use when screening candidates for various grants etc. They had no servers to speak of, just local machines and access to a shared drive. An access application with a central database file with local UI's connected to it was a perfect fit for that use case, and this is as someone who typically avoids anything MS like the plague and really really detests VB. Not even VB, VBA, that shit is horrific. But it was the right choice for the project.
 

OlympicTechno

Neo Member
This is probably really simple but I can't figure it out.

I am currently creating a web page and am in the very early stages of development. I have an image centered in my header and I have 4 navigation links which can be clicked. The navigation bar is split either side of the image by using two unordered lists and I have used float: left and float: right to make them go either side.

My question is how do I get the links to be next to the image rather than at the edge of the div, without altering the alignment of the image?

Thanks!
 
I need some suggestions from you guys.

I'm working on a .Net project that will wrap a brand new API. This wrapper is to help developers move from their current API(lets call it API A) to the new version(API B), so the wrapper should emulate a lot of the stuff API A does from the developers point of view but then translate it all to API B ready logic, etc.

I'm trying to figure out the best way to implement exceptions for this wrapper. I'm thinking to copy the fifteen or so exclusive exceptions API A has to the wrapper, and throw them the same way API A would.

For example API A throws BadConnectionException if it cannot connect. I'm thinking of creating MyWrapperNameBadConnectionException and throwing it if a similar situation occurs.

I've never really worked on a project creating a wrapper before so I'm not sure.

What are your thoughts? Do you have any suggestions for handling exceptions in an API wrapper?

BTW sorry my names are vague as hell, NDAs and all that good stuff...
 

poweld

Member
I need some suggestions from you guys.

I'm working on a .Net project that will wrap a brand new API. This wrapper is to help developers move from their current API(lets call it API A) to the new version(API B), so the wrapper should emulate a lot of the stuff API A does from the developers point of view but then translate it all to API B ready logic, etc.

I'm trying to figure out the best way to implement exceptions for this wrapper. I'm thinking to copy the fifteen or so exclusive exceptions API A has to the wrapper, and throw them the same way API A would.

For example API A throws BadConnectionException if it cannot connect. I'm thinking of creating MyWrapperNameBadConnectionException and throwing it if a similar situation occurs.

I've never really worked on a project creating a wrapper before so I'm not sure.

What are your thoughts? Do you have any suggestions for handling exceptions in an API wrapper?

BTW sorry my names are vague as hell, NDAs and all that good stuff...

First of all, what you're talking about is the Adapter Pattern. As far as exceptions go, the exceptions thrown from the adapter would have to remain the same (or at least, a subclass) of the ones being thrown from the old class, otherwise the old code wouldn't know what to do with the thrown exception.
 

Chris R

Member
Thanks for the replies. I am trying to find a good tutorial or book online to create and connect to a database from a Windows Forms Application. Nothing I have found so far explains step by step!

a) Add the connection (Tools -> Connect To Database)
b) Add a new ADO.Net Entity Data Model (Right click on Project -> Add -> Data -> ADO.Net Entity Model)
c) Walk through the wizard, selecting the table(s)/view(s)/stored proc(s) you want to bring into your project
d) Done!

Of course the first step would be making sure your tables are properly setup. Nothing worse than pulling two tables in and not seeing a relationship that should be there (that wasn't added because actually defining your relationships in SQL makes lazy ass "updating" via truncation harder due to dropping and recreating the restraint)

Just don't use access please.
 
First of all, what you're talking about is the Adapter Pattern. As far as exceptions go, the exceptions thrown from the adapter would have to remain the same (or at least, a subclass) of the ones being thrown from the old class, otherwise the old code wouldn't know what to do with the thrown exception.

Well it can't really use the same or even subclass the original exceptions since they are classes that are specific to "API A". The wrapper should ideally know nothing about the old API, yet let developers sanely migrate from the old API to the new API.

Developers using this wrapper will go into knowing they will have to modify their code. Its not meant to be a comparability swap without modifications. Its really just to make it easier for them to move to the new API without going to a competitor.
 

poweld

Member
Well it can't really use the same or even subclass the original exceptions since they are classes that are specific to "API A". The wrapper should ideally know nothing about the old API, yet let developers sanely migrate from the old API to the new API.

Developers using this wrapper will go into knowing they will have to modify their code. Its not meant to be a comparability swap without modifications. Its really just to make it easier for them to move to the new API without going to a competitor.

I see now. In that case, sure, making it obvious to the devs how the exceptions map is probably the best you can do.
 

Zeus7

Member
a) Add the connection (Tools -> Connect To Database)
b) Add a new ADO.Net Entity Data Model (Right click on Project -> Add -> Data -> ADO.Net Entity Model)
c) Walk through the wizard, selecting the table(s)/view(s)/stored proc(s) you want to bring into your project
d) Done!

Of course the first step would be making sure your tables are properly setup. Nothing worse than pulling two tables in and not seeing a relationship that should be there (that wasn't added because actually defining your relationships in SQL makes lazy ass "updating" via truncation harder due to dropping and recreating the restraint)

Just don't use access please.

Thanks for this, exactly what I was needing.
 

Karl2177

Member
I'm writing in C. Can I use a char for an uint8_t? I'm using fwrite() to write to a file and was wondering what differences would pop up if any.
 
After a few years of having bad jobs I took a year to go back to school and learn programming, web mostly (html, css, php, js). I'm struggling with the concept of objects oriented programming and model/view/controller. I know what that means but I lack examples of their use. It still has not ticked in my brain I was wondering if you know some tutorials/websites/videos that explains all this a bit better. Something you watched/read and it seems logical?

This may help, it is Ruby but explores the basics of methods and briefly touches on OO.

https://www.codeschool.com/courses/try-ruby

This is a really great start and Jeff explains things in simple terms and is great for beginners. (Probably best for you, not sure if these are free but one month doesn't cost much!)

https://laracasts.com/series/laravel-5-fundamentals
 
quick question about scanf, does it automatically skip to a newline after reading in characters or a string?
scanf() only reads one character at a time with %c so it'll just be the next character. With %s it reads to the first whitespace character, but leaves the whitespace character in the stream/buffer.

I'm writing in C. Can I use a char for an uint8_t? I'm using fwrite() to write to a file and was wondering what differences would pop up if any.
If your warnings are set high enough your compiler will either throw a warning or an error for an incompatible type. Why do you want to use a different type?
 
Has anyone used any of these books? Would you recommend any of those, or there are better books?

For which programming language?

In general I've found the O'Rielly books(with the animals on them) to be pretty good. They haven't steered my wrong. Also if the Ruby book is what I think it is then its supposed to be really good, I haven't read it myself tho.
 

tokkun

Member
I'm writing in C. Can I use a char for an uint8_t? I'm using fwrite() to write to a file and was wondering what differences would pop up if any.

You can cast a char to a uint8_t and vice versa without problems.

The difference is that the standard does not define char as being signed or unsigned, whereas uint8_t is always unsigned. This will only become an issue when doing comparison operations with other data types or when casting to a signed data type with > 8 bits.

Code:
void test_overflow() {
  for (char c = 0; c < 128; ++c) {}  // May be an infinite loop.
  for (uint8_t u = 0; u < 128; ++u) {}  // Guaranteed to terminate.
}

void test_comparison(char c) {
  uint8_t u = c;
  bool c_gt = c > 1;
  bool u_gt = u > 1;

  assert(c_gt == u_gt);  // Not guaranteed to be true.
}

void test_expansion(char c) {
  uint8_t u = c;

  assert(u == c);  // Guaranteed to be true.

  int expanded_u = u;
  int expanded_c = c;

  assert(expanded_u == expanded_c);  // Not guaranteed to be true.

}
 
scanf() only reads one character at a time with %c so it'll just be the next character. With %s it reads to the first whitespace character, but leaves the whitespace character in the stream/buffer.


If your warnings are set high enough your compiler will either throw a warning or an error for an incompatible type. Why do you want to use a different type?

Shouldn't matter, fwrite takes a void* anyway so it's already getting casted. Internally it's casting that to a uint8_t*, but that's just an implementation detail.
 
I wish there was something as convenient as maven or gradle for C/C++ dependency management. Pain in the ass to pull down libraries for different Linux OSes.
 
Is maven really convenient though? I know what you mean though. One day this will finally be sorted out.

It's a shit ton better than the alternative of trying to go through dependency hell. Also, Nexus is incredibly simple to get up and running to serve internal libraries so easy enough in the average case to split out modules and included internal library dependencies.
 

Sami+

Member
Hey guys! I'm taking my first semester of programming right now - C++. I'm writing a basic program right now but need a bit of help with one part of it; we're supposed to make the program spit out error messages if the user types in the wrong thing, but I'm not sure how to do that.

Edit - got it
 

0xCA2

Member
Just got a phone interview at my school's research lab for a Software Intern position. Does anyone have any tips? This would be my first phone interview in software development and my second phone interview period.

I really don't want to fuck this up. I'm going to try to ask my professor or TA if we can do a mock interview.
Just did the interview, pretty sure I bombed it even though it turned out it wasn't technical lol. I really have to work on my interviewing/people skills in general. With where they are now I'll never get a job.
 
Just did the interview, pretty sure I bombed it even though it turned out it wasn't technical lol. I really have to work on my interviewing/people skills in general. With where they are now I'll never get a job.

Sorry to hear, although I would say don't write it off until you actually hear back.

What kind of stuff did they ask?

My general, non technical advice for interviews is to imagine you've already got the job, the interviewer is your actual best friend, and you're just going through the motions. It's all about confidence. When you're talking to your friends you're way more open and nonchalant, and that gets jobs.

I mean think about it, if a question is non technical, then the only possible thing it must be trying to answer is "Is this guy going to be pleasant to work with?" That answer will usually be yes if you seem friendly, fun, and confident, neutral if you seem reserved and uncertain about your answers, and no if you seem rude, dismissive, or bossy.

Obviously easier said than done, especially for certain personality types, but that's my advice.
 

Karl2177

Member
scanf() only reads one character at a time with %c so it'll just be the next character. With %s it reads to the first whitespace character, but leaves the whitespace character in the stream/buffer.


If your warnings are set high enough your compiler will either throw a warning or an error for an incompatible type. Why do you want to use a different type?
I'm lazy. Our assignment's specs are to save each dungeon space as a 4 byte structure. The first 3 bytes are 0 if value, anything else if not(terrible, I know, but I'm not in charge of creating the spec. I would just use a single byte for those). The last one said to be an unsigned 8 bit integer for a 0-255 value. For writing to disc, I figured I would be lazy and just have a giant character array. Then when I'm reading, I'd save it into a unit8_t.
You can cast a char to a uint8_t and vice versa without problems.

The difference is that the standard does not define char as being signed or unsigned, whereas uint8_t is always unsigned. This will only become an issue when doing comparison operations with other data types or when casting to a signed data type with > 8 bits.

Code:
void test_overflow() {
  for (char c = 0; c < 128; ++c) {}  // May be an infinite loop.
  for (uint8_t u = 0; u < 128; ++u) {}  // Guaranteed to terminate.
}

void test_comparison(char c) {
  uint8_t u = c;
  bool c_gt = c > 1;
  bool u_gt = u > 1;

  assert(c_gt == u_gt);  // Not guaranteed to be true.
}

void test_expansion(char c) {
  uint8_t u = c;

  assert(u == c);  // Guaranteed to be true.

  int expanded_u = u;
  int expanded_c = c;

  assert(expanded_u == expanded_c);  // Not guaranteed to be true.

}

I figured it would be an issue when comparing signed and unsigned values. Thanks.
 

NotBacon

Member
Anybody got advice for phone interviews? I've been through several interviews in person at various companies and they've gone alright, but I've never done one over the phone.
 

tokkun

Member
Anybody got advice for phone interviews? I've been through several interviews in person at various companies and they've gone alright, but I've never done one over the phone.

Some advice will depend on whether this is a behavioral or technical interview.

-Use a headset. You can keep your hands free and keep your body in a more relaxed position.
-Have a notepad and pencil available so you can take notes or sketch out solutions to problems. Alternatively you can type into a text editor if that makes you more comfortable. Make sure to write down your interviewer's name so you can thank them by name at the end of the interview.
-Make sure you have a quiet spot where you get good phone reception.
-Keep some water at hand.
-Try to narrate your thought process if you are asked a question which requires some though. Pregnant pauses are more awkward over the phone than in person.
-Avoid the temptation to use Google if you don't know the answer to something.
-Don't try to lay out a ton of reference material or notes in advance. Anything more than one page is probably too much.
 

0xCA2

Member
Sorry to hear, although I would say don't write it off until you actually hear back.

What kind of stuff did they ask?

My general, non technical advice for interviews is to imagine you've already got the job, the interviewer is your actual best friend, and you're just going through the motions. It's all about confidence. When you're talking to your friends you're way more open and nonchalant, and that gets jobs.

I mean think about it, if a question is non technical, then the only possible thing it must be trying to answer is "Is this guy going to be pleasant to work with?" That answer will usually be yes if you seem friendly, fun, and confident, neutral if you seem reserved and uncertain about your answers, and no if you seem rude, dismissive, or bossy.

Obviously easier said than done, especially for certain personality types, but that's my advice.

They mainly asked the typical stuff:
- What is your biggest strength?
- What is your biggest weakness?
- What is your biggest accomplishment?
- What is your biggest failure?

Then things like:
- What object oriented paradigms do you know?
- What new technologies have you learned recently
- What's your favorite programming methodology?
- What is your best language and why is it your best language?
- Tell me about a project that you've worked on.

For whatever reason the first four caught me off guard. I kind of knew they were going to ask stuff like that but I didn't prepare. I came up with all of the answers on the spot and they were all kind of shit. There were a lot of pauses and tripping over my words. Welp, you live and you learn. At least I wrote down the questions so I'll know what to expect for future interview.

I think your advice is great, I wish I would've approached it that way. I was so nervous; the guy had spent like 10 min basically explaining how awesome it would be if I got the internship. The situation felt really intense. Then the first question that was asked was "what is your biggest failure", followed by "what is your biggest accomplishment". When I realized that I had no accomplishments and scrambled to come up with a weak answer, I knew it was done.
 
very difficult to do with a mixture of external and internal libraries along with most of the internal stuff being sufficiently complex that header only libraries would be unfeasible to do without impeding readability.
I'll agree that it isn't easy. And I'd agree that internal libraries (e.g. anything you or the company owns) are less important to be header only. But you should be able to statically link those!

Being header only is a huge bonus for a 3rd party C/C++ library. Gives instant credibility to a project that thought far enough ahead to say "wait a minute, how are people going to actually use this?"
 

NotBacon

Member
Some advice will depend on whether this is a behavioral or technical interview.

-Use a headset. You can keep your hands free and keep your body in a more relaxed position.
-Have a notepad and pencil available so you can take notes or sketch out solutions to problems. Alternatively you can type into a text editor if that makes you more comfortable. Make sure to write down your interviewer's name so you can thank them by name at the end of the interview.
-Make sure you have a quiet spot where you get good phone reception.
-Keep some water at hand.
-Try to narrate your thought process if you are asked a question which requires some though. Pregnant pauses are more awkward over the phone than in person.
-Avoid the temptation to use Google if you don't know the answer to something.
-Don't try to lay out a ton of reference material or notes in advance. Anything more than one page is probably too much.

Holyshit thanks!
 

0xCA2

Member
I suspect that was "patterns" rather than "paradigms"?

Hmm, maybe I remembered it wrong. I do remember being confused about it in the interview. I answered "inheritance, polymorphism, and generics" and asked him if he could clarify what he meant. He said I'd gotten it right.
 

Staab

Member
I have a question regarding MYSQL and subtracting values from a table.
Basically I have a table that looks like this :
Code:
Table "liverace"

racelap,   pos,   change,   userid
1            1        0      21
1            2        0      12     
1            3        0      18
2            1        0      18
2            2        0      21
2            3        0      12
There are anywhere from 1 to 30 users per race with a unique user ID ("userid", could be any number really) that each set times for each lap of a circuit(times not shown for clarity and the number of laps varies from one track to the other, specified by "racelap", only the first two laps shown here).
Depending on the time set by the user, I'm attributing them a position (reflected in the "pos" column).
Now what I need to be doing is calculate the change in position on the nex lap, based on the position on the previous lap, then insert that difference in the "change" column.
It should look like this if correctly done :
Code:
Table "liverace"

racelap,   pos,   change,   userid
1            1        0       21
1            2        0       12     
1            3        0       18
2            1        +2      18
2            2        -1      21
2            3        -1      12

Anyone able to help me with that ? (If it's possible at all using a query)

I've been thinking of doing it in PHP, then updating the table, but I'm a total newbie so I haven't been able to figure out how either ;(
 

maeh2k

Member
I have a question regarding MYSQL and subtracting values from a table.
Basically I have a table that looks like this :
Code:
Table "liverace"

racelap,   pos,   change,   userid
1            1        0      21
1            2        0      12     
1            3        0      18
2            1        0      18
2            2        0      21
2            3        0      12
There are anywhere from 1 to 30 users per race with a unique user ID ("userid", could be any number really) that each set times for each lap of a circuit(times not shown for clarity and the number of laps varies from one track to the other, specified by "racelap", only the first two laps shown here).
Depending on the time set by the user, I'm attributing them a position (reflected in the "pos" column).
Now what I need to be doing is calculate the change in position on the nex lap, based on the position on the previous lap, then insert that difference in the "change" column.
It should look like this if correctly done :
Code:
Table "liverace"

racelap,   pos,   change,   userid
1            1        0       21
1            2        0       12     
1            3        0       18
2            1        +2      18
2            2        -1      21
2            3        -1      12

Anyone able to help me with that ? (If it's possible at all using a query)

I've been thinking of doing it in PHP, then updating the table, but I'm a total newbie so I haven't been able to figure out how either ;(

Haven't done this in a while, but I don't see why it wouldn't work in SQL.
You can join the table with itself on userid = userid and racelap = racelap + 1 and then update change based on the respective pos values.

Are you sure you want to store the value in the database? Doesn't seem particularly meaningful and you could just compute it at runtime.
 

Staab

Member
Are you sure you want to store the value in the database? Doesn't seem particularly meaningful and you could just compute it at runtime.
Yeah, that's the kind of thing I'm really bad about, I have no idea how to code properly so I throw in a ton of "hacks" through trial and error.
At least when it's in the database it seems "clean" to me and less prone to errors...
But I see your point and maybe I should just keep it like that!
 

maeh2k

Member
Yeah, that's the kind of thing I'm really bad about, I have no idea how to code properly so I throw in a ton of "hacks" through trial and error.
At least when it's in the database it seems "clean" to me and less prone to errors...
But I see your point and maybe I should just keep it like that!

Try both ways and see how you feel about it then.
 

Husker86

Member
Regarding XML parsing in PHP:

I am working on a podcast app for Android (mostly just to see that I can do it) and am figuring out the server scripts currently.

PHP SimpleXML seems easy to use, but it doesn't appear to grab all of the available tags.

For example, TWiT's feed URL.

The SimpleXML object I get using
Code:
$xml = simplexml_load_file($url);
has none of the itunes tags. Right now, the main thing I'm unable to get without the itunes tags is the episode description. The non-itunes description tag is HTML formatted so I'd rather just be able to grab the itunes one.

Is this something that I'd have to parse manually or are there better PHP XML parsers other than the built in SimpleXML?
 
Top Bottom