Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
covener
Jan 10, 2004

You know, for kids!

Clock Explosion posted:

and that Java won't let you bind to port 80, they don't notice each other's presence, and thus, the server just stays still, no matter what you do on the HTML page.

java can bind to port 80 just fine. Your java server running on some high port isn't going to "notice" connections hitting some webserver on the same system unless you explicitly connect to it.

quote:

If you need to use sockets on odd ports, I think your only options are PHP(or some other language that you can run server-side like Perl) or a Java applet(which will basically run like poo poo).

the applet security context doesn't permit outgoing tcp connections to other hosts/ports.

Adbot
ADBOT LOVES YOU

tripwire
Nov 19, 2004

        ghost flow
I just realized that an assignment (in C) I have to turn in for class uses libraries which don't exist on the school computers. I'm using perl compatible regular expressions (which seem a billion times better/easier to use than the posix regex.h library) but my code won't compile on at school because pcre.h is missing.

I have a feeling its impossible or at least a huge pain in the rear end to link a compiled pcre library to my code because I obviously don't have privileges to install pcre.

Should I refactor my code to use regex.h or is it possible to compile the pcre library to a personal directory and link it from there? Would I still tell pass gcc the -lpcre argument or would that look different?

csammis
Aug 26, 2003

Mental Institution

tripwire posted:

Should I refactor my code to use regex.h or is it possible to compile the pcre library to a personal directory and link it from there? Would I still tell pass gcc the -lpcre argument or would that look different?

Whether it's worth the refactor trouble or not is just the inverse of the question "Will you be penalized for requiring compilation of pcre locally?" which is a question for your TA. As for gcc, you'll still pass it -lpcre but you'll also pass it -Lpath/to/local/library (reference).

tripwire
Nov 19, 2004

        ghost flow

csammis posted:

Whether it's worth the refactor trouble or not is just the inverse of the question "Will you be penalized for requiring compilation of pcre locally?" which is a question for your TA. As for gcc, you'll still pass it -lpcre but you'll also pass it -Lpath/to/local/library (reference).

Thanks. I just got it compiled locally but I think I'm just going to end up re factoring it because I doubt the TA would want to deal with the hassle of compiling and linking pcre.

csammis
Aug 26, 2003

Mental Institution
Hey, at least you realized that the school computers don't have pcre before turning in the assignment. Developing on personal machines and creating unresolvable dependencies bit many a programming student when I was in college :)

tripwire
Nov 19, 2004

        ghost flow
Blergh, a related question: in perl compatible RE you can group things together but avoid capturing substrings there by putting a question mark and a colon after the left parenthesis.

So if your expression is "(?:abc)(123)" without quotes, and you match the string "abc123" you would expect that it only captures the substring "123".

How do you do this without perl compatible RE? I'm trying to go through the reference for regex.h but I'm just getting dumbfounded and I'm sure someone must know this off the top of their head.

JoeNotCharles
Mar 3, 2005

Yet beyond each tree there are only more trees.

tripwire posted:

Blergh, a related question: in perl compatible RE you can group things together but avoid capturing substrings there by putting a question mark and a colon after the left parenthesis.

So if your expression is "(?:abc)(123)" without quotes, and you match the string "abc123" you would expect that it only captures the substring "123".

How do you do this without perl compatible RE? I'm trying to go through the reference for regex.h but I'm just getting dumbfounded and I'm sure someone must know this off the top of their head.

I don't know, but can't you just ignore \1 and just look at \2?

tripwire
Nov 19, 2004

        ghost flow

JoeNotCharles posted:

I don't know, but can't you just ignore \1 and just look at \2?
I forgot to mention that I'm using nested subexpressions.

I'm trying to match an HTTP request. Part of this request is the URI which is a string that corresponds to a file/resource on the computer. The first character of the URI is always a slash (/) and theres some non-special characters optionally following that. A slash followed by a slash is illegal, as are spaces, line breaks, carraige feeds and other bric a brack you wouldn't want in filename.

In PCRE I was capturing the URI with this pattern:
(/(?:[^\r\n/ ]+(?:/[^\r\n/ ]+)*)?)

It wants a slash first, optionally followed by one or more valid characters, followed by slash with some more characters which can appear many times or not at all.
How do I codify that as a regular expression which doesn't use nested backreferences? I want to apply the * operator (zero or many times) on the nested substring but I don't want to capture the nested substring because that will fuckup later captures I have to do.

tripwire fucked around with this message at 18:33 on Oct 7, 2008

RonniePudding
Oct 18, 2005

*EDIT* SOLVED


Need some big brains to help get my javascript working, specifically setting the focus in Firefox. I got it working in IE but not sure how to get it working in Firefox. I'll continue to google. Thanks for anything.


if(ie4 || ie5)
{
//(this works in IE)
contentFrameDoc.frames['id'].focus();
contentFrameDoc.frames['id'].document.getElementById('text').focus();
}
else
{
//(this doesn't work in Firefox)
contentFrameDoc.*needed document in hurr*. getElementById('id').focus();
contentFrameDoc.*needed document in hurr*. getElementById('id').contentDocument.getElementById('text').focus();

}

RonniePudding fucked around with this message at 18:57 on Oct 7, 2008

csammis
Aug 26, 2003

Mental Institution

RonniePudding posted:

Need some big brains to help get my javascript working, specifically setting the focus in Firefox. I got it working in IE but not sure how to get it working in Firefox. I'll continue to google. Thanks for anything.

Check the web development megathread too

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

tripwire posted:

In PCRE I was capturing the URI with this pattern:
(/(?:[^\r\n/ ]+(?:/[^\r\n/ ]+)*)?)

It wants a slash first, optionally followed by one or more valid characters, followed by slash with some more characters which can appear many times or not at all.
How do I codify that as a regular expression which doesn't use nested backreferences? I want to apply the * operator (zero or many times) on the nested substring but I don't want to capture the nested substring because that will fuckup later captures I have to do.

Do you absolutely have to do this with regular expressions? It's pretty straightforward with strchr and strrchr.

tripwire
Nov 19, 2004

        ghost flow

rjmccall posted:

Do you absolutely have to do this with regular expressions? It's pretty straightforward with strchr and strrchr.

Well it doesn't absolutely have to be done with regular expressions, but how would I validate the URI without them? I guess I could make a big wack of if statements that do roughly the same thing, it just seems kludgy.

JoeNotCharles
Mar 3, 2005

Yet beyond each tree there are only more trees.

tripwire posted:

Well it doesn't absolutely have to be done with regular expressions, but how would I validate the URI without them? I guess I could make a big wack of if statements that do roughly the same thing, it just seems kludgy.

You find a series of if statements more kludgy than (/(?:[^\r\n/ ]+(?:/[^\r\n/ ]+)*)?)? That's crazy talk.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

tripwire posted:

Well it doesn't absolutely have to be done with regular expressions, but how would I validate the URI without them? I guess I could make a big wack of if statements that do roughly the same thing, it just seems kludgy.

That regexp is validating exactly three things: that there aren't any CR or LF characters in the URI (which is probably guaranteed by your parser anyway), that the URI starts with a slash, and that all the components are non-empty. You'll need to do better validation than that anyway (e.g. to invalidate URIs like /mysite/../../../etc/passwd), and that validation will need to look at individual components, so....

The Dissonant
Jul 24, 2008

Just another disposable hero.
Hey guys, a friend of mine makes 3D models in 3DMax. I want to make a game with him, but don't know where to start. Obviously, I'll be doing the programming part. Are there any good basic tutorials for this (C++, C#, or Java preferred)?

LuckySevens
Feb 16, 2004

fear not failure, fear only the limitations of our dreams

I'm working on my programming skills at the moment, all self taught (thank god for a language like python to start with), is it normal at this level of programming skill to frequently hit a wall in understanding a concept? I feel like I'm constantly having to take deep breaths when trying to visualise how stuff is actually working, please tell me it gets easier and less daunting, that this is just a beginner phase thing that wears out after a while! :(

tef
May 30, 2004

-> some l-system crap ->
It depends what you're learning from. If you are constantly hitting a wall it might be that your learning technique and materials aren't suited to you, or that you are trying to learn too quickly.

Learning doesn't normally get easier - it still requires a lot of work, patience and thought in any subject - but once you have the fundamentals nailed down, you don't have to learn as much to understand things.

What I would suggest is:

Be a little more patient - if it takes you longer to understand something you may well come away with a better understanding of it.

Try different materials - look for slides, video lectures, books, exercises to learn from instead of just one source of information. You may find that learning from one is prefferable to the others.

Talk to other people - you could ask for help in this forum rather than asking for reassurance.

csammis
Aug 26, 2003

Mental Institution

The Dissonant posted:

Hey guys, a friend of mine makes 3D models in 3DMax. I want to make a game with him, but don't know where to start. Obviously, I'll be doing the programming part. Are there any good basic tutorials for this (C++, C#, or Java preferred)?

Game development megathread - should find plenty of resources there. Otherwise, this question goes waaaay beyond a single post in a general questions thread. Game development can get very complex.

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!

tripwire posted:

but I don't want to capture the nested substring because that will fuckup later captures I have to do.

Are you sure? In Perl anyway this doesn't apply; each open paren indicates a new capture. As in, open paren in the regex literal. Nesting doesn't create new captures. It becomes really easy to reason about how substrings are being captured once you internalize this.

code:
$ perl -le '"abcdX" =~ /((.)+)(X)/; warn "$1 $2 $3"'
abcd d X at -e line 1.
I think you're expecting it to result in abcd a b. I sure hope it doesn't.

tripwire
Nov 19, 2004

        ghost flow

rjmccall posted:

That regexp is validating exactly three things: that there aren't any CR or LF characters in the URI (which is probably guaranteed by your parser anyway), that the URI starts with a slash, and that all the components are non-empty. You'll need to do better validation than that anyway (e.g. to invalidate URIs like /mysite/../../../etc/passwd), and that validation will need to look at individual components, so....

There is no parser, I'm using a big regex to parse the whole thing. The whole perl compatible regexp looks like this:
(POST|GET|HEAD|LINK|PUT|DELETE) (/(?:[^\r\n/ ]+(?:/[^\r\n/ ]+)*)?) HTTP/(1.[10])\r\n((?:[^\r\n]*\r\n)*)\r\n

This won't work in the posix api because you can't access captured group by name, you have to access them by order in which they appeared. The URI could contain a variable amount of capture groups in it, as could the headers.
Since I don't get to use things like (:? to stop a group from capturing I don't know how to validate the URI directly with regex.


Sartak posted:

Are you sure? In Perl anyway this doesn't apply; each open paren indicates a new capture. As in, open paren in the regex literal. Nesting doesn't create new captures. It becomes really easy to reason about how substrings are being captured once you internalize this.

code:
$ perl -le '"abcdX" =~ /((.)+)(X)/; warn "$1 $2 $3"'
abcd d X at -e line 1.
I think you're expecting it to result in abcd a b. I sure hope it doesn't.
Like I posted earlier, If I was using perl I wouldn't have this problem. I'm forced to use the posix regex.h api which doesn't support captures in nearly as easy a way.

tripwire fucked around with this message at 18:09 on Oct 8, 2008

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!

tripwire posted:

This won't work in the posix api because you can't access captured group by name, you have to access them by order in which they appeared. The URI could contain a variable amount of capture groups in it, as could the headers.

Please reread my post, because this is exactly the point I address.

tripwire posted:

Like I posted earlier, If I was using perl I wouldn't have this problem. I'm forced to use the posix regex.h api which doesn't support captures in nearly as easy a way.

I know. I was just using Perl as an example. Just try it with your regex library. I bet it'll work.

tripwire
Nov 19, 2004

        ghost flow

Sartak posted:

Please reread my post, because this is exactly the point I address.


I know. I was just using Perl as an example. Just try it with your regex library. I bet it'll work.

Sorry I'm an idiot and didn't understand you. It turns out you were completely right. Now I'm having frustrations because when my server serves a file it truncates on binary zero. Programming in C is a painful but educational experience.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

tripwire posted:

There is no parser, I'm using a big regex to parse the whole thing. The whole perl compatible regexp looks like this:
(POST|GET|HEAD|LINK|PUT|DELETE) (/(?:[^\r\n/ ]+(?:/[^\r\n/ ]+)*)?) HTTP/(1.[10])\r\n((?:[^\r\n]*\r\n)*)\r\n

Incidentally, RFC 2616 says you should ignore initial CRLFs in HTTP requests.

Anyway, HTTP is a line-based protocol, and you have to keep reading the header until you get to an empty line, so I assume you're just looping on a read-and-append until this regexp matches — in which case you'll never actually detect failure anyway.

tripwire
Nov 19, 2004

        ghost flow

rjmccall posted:

Incidentally, RFC 2616 says you should ignore initial CRLFs in HTTP requests.

Anyway, HTTP is a line-based protocol, and you have to keep reading the header until you get to an empty line, so I assume you're just looping on a read-and-append until this regexp matches — in which case you'll never actually detect failure anyway.

Nah, I have a method which harvests characters from a socket until it reads two CRLFs in a row, then it passes the string over to the parsing function.

I'm mostly finished now, but If anyone wants to help a c noob out and give me pointers on which things I've mangled up and how to fix it, I've put my web server code up here: http://pastebin.com/m1478ea14

I know for a fact that I've completely hosed up on dynamically allocating; I thought I had it figured out but I was getting hard crashes from double freeing/corruption so I just removed every offending free() until it stopped complaining. If someone can tell me when/how to allocate in the context of that program without causing corruption I'd really appreciate it.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

tripwire posted:

I know for a fact that I've completely hosed up on dynamically allocating; I thought I had it figured out but I was getting hard crashes from double freeing/corruption so I just removed every offending free() until it stopped complaining. If someone can tell me when/how to allocate in the context of that program without causing corruption I'd really appreciate it.

code:
current_request  = xmalloc(sizeof(struct full_request));
current_response = xmalloc(sizeof(struct full_response));
char * output = xmalloc(sizeof(char)*160);
This has nothing to do with your malloc problems, but: you don't need to use malloc here, since you're just creating temporaries for the lifetime of a single function call. Just declare these on the stack.

Aredna
Mar 17, 2007
Nap Ghost
My school had a programming contest yesterday, and I can't seem to think of an efficient algorithm for problem #6.

http://www.cs.mtsu.edu/~zdong/programmingContest/Problems08F.doc

It seems like it would just be the max of all-pairs shortest path, but the worst case have up to 998^2 vertices, and Floyd-Warshall is O(V^3), which would be 1E18 runs of the loop, in addition to 998^4 integers to hold in memory.

I thought about looking at a breadth first search with memoization? This won't alleviate the memory issues, but it should run much faster.

I think there has to be some sort of way to take advantage of this being a 2D graph, since the number of edges will be reduced drastically, but at this point I'm running into a mental wall on the next step.

Does anyone have any suggestions? If so, can you also provide a website link or name of something I can search for to read up on?

Feral Integral
Jun 6, 2006

YOSPOS

Hey, was wondering what kind of software you guys use to plan out your programs before writing (if you ever do)? I'm trying to start a little personal project that involves a lot of network crap like keeping track of packets throughout a series of nodes. So I guess I'm looking for some kind of charting software that'll let me abstract the project before I start coding.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

Feral Integral posted:

Hey, was wondering what kind of software you guys use to plan out your programs before writing (if you ever do)? I'm trying to start a little personal project that involves a lot of network crap like keeping track of packets throughout a series of nodes. So I guess I'm looking for some kind of charting software that'll let me abstract the project before I start coding.

Pencil and paper. A plain text editor if I'm feeling ambitious.

chocojosh
Jun 9, 2007

D00D.

Avenging Dentist posted:

Pencil and paper. A plain text editor if I'm feeling ambitious.

I prefer a whiteboard myself :)

ante
Apr 9, 2005

SUNSHINE AND RAINBOWS

chocojosh posted:

I prefer a whiteboard myself :)

I dream of a whiteboard :smith:

But yeah, nothing beats being able to physically scrawl out your process. Much quicker than notepad or anything.


I'm using C to try and parse some strings.
I've got some statements like this:

sprintf(cFirstPair,"%.2s", cSingleCommand);

cSingleCommand is four characters. cFirstPair returns the first two. Is there any easy method to return the second pair?
Or, better yet, just enter each pair into a function separately, something like this:

function(cSingleCommand[0] + cSingleCommand[1],cSingleCommand[2] + cSingleCommand[3]);

Except you know, actually have it work.

I don't want to have to use a million intermediate variables :(

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

ante posted:

Is there any easy method to return the second pair?

cSingleCommand+2

ante
Apr 9, 2005

SUNSHINE AND RAINBOWS

Avenging Dentist posted:

cSingleCommand+2

I actually tried that, but I realize my problem goes further than that. Take a look at this:

Assume cSingleCommand = ABCD
This code:
code:
sprintf(cFirstPair,"%.2s", cSingleCommand);
sprintf(cSecondPair,"%.2s", cSingleCommand);
printf("(%s,%s)\n",cFirstPair,cSecondPair);
Results in this:
code:
(AB,)
If I do this, however:
code:
sprintf(cFirstPair,"%.2s", cSingleCommand);
sprintf(cSecondPair,"%.2s", cSingleCommand+2);
printf("(%s,%s)\n",cFirstPair,cSecondPair);
This is the result:
code:
(,CD)
Obviously, I'd like (AB,CD).

I hate C style strings so much.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
I can only conclude that you're doing it wrong.

You're probably not allocating space for the null terminator and one string is clobbering the other.

ante
Apr 9, 2005

SUNSHINE AND RAINBOWS

Avenging Dentist posted:

I can only conclude that you're doing it wrong.

You're probably not allocating space for the null terminator and one string is clobbering the other.

You are absolutely right, thank you.


This is what happens when you've been writing code for 7 consecutive hours.

glint
Nov 15, 2004

Dear god, The patient's best intentions have sadly faltered.
I'm not a coder but am trying to bastardise a vb script so please be gentle if I've done something stupid.

I'm trying to store an eventid to report out of system log, I have it working with hardcoded id like

intNumberID = 6008

I have user input working for hy hostname

strComputer = InputBox("Computer Name", "Enter Computer Name you want to report against")

But I want user input like that for my intNumberID

intNumberID = InputBox("Enter the Event ID Number you want to report on", "Event ID")

doesn't work for some reason?

eHacked
Sep 30, 2003

CONGRATULATIONS!!! YOU ARE THE 6,127,436,218TH PERSON TO VIEW THIS USELESS POST. CLICK TO CLAIM YOUR PRIZE!!!
ignore this.

eHacked fucked around with this message at 19:22 on Oct 10, 2008

glint
Nov 15, 2004

Dear god, The patient's best intentions have sadly faltered.

glint posted:

I'm not a coder but am trying to bastardise a vb script so please be gentle if I've done something stupid.

I'm trying to store an eventid to report out of system log, I have it working with hardcoded id like

intNumberID = 6008

I have user input working for hy hostname

strComputer = InputBox("Computer Name", "Enter Computer Name you want to report against")

But I want user input like that for my intNumberID

intNumberID = InputBox("Enter the Event ID Number you want to report on", "Event ID")

doesn't work for some reason?
intNumberID = cint(InputBox("Enter the Event ID Number you want to report on", "Event ID"))

tehclayzor
Aug 9, 2007
clitz?
How would I go about creating a search to look through a server to find a file the user wants and link it back to the user? The files are pdf's but I only want to search it by the file names.

The actual search form would be on an intranet page, on a seperate server from the actual files.

If my wording is confusing let me know, I'm pretty confused by it too and have no other way to explain it.

gold brick
Jun 19, 2001

no he isn't

tehclayzor posted:

How would I go about creating a search to look through a server to find a file the user wants and link it back to the user? The files are pdf's but I only want to search it by the file names.

The actual search form would be on an intranet page, on a seperate server from the actual files.

If my wording is confusing let me know, I'm pretty confused by it too and have no other way to explain it.
You probably don't want to search anything but an index, as that would be too slow.

I've never used Indexing Service (assuming you're on Windows), but I remembered this from Atwood a while back. Maybe it could get you going in the right direction.

Adbot
ADBOT LOVES YOU

tehclayzor
Aug 9, 2007
clitz?
Yeah I meant to mention that i already had links to an index on the intranet page. I'll look through this Indexing Service thing. Thanks!

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply