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
Waltzing Along
Jun 14, 2008

There's only one
Human race
Many faces
Everybody belongs here

Magicmat posted:

ints don't hold decimals, they automatically are truncated to, well, integers. So your statements are compiled as:
code:
const int BIRTH_RATE = 1;
const int DEATH_RATE = 0;
Use floating point numbers if you want to store decimals.

I changed the ints to doubles and it worked perfectly. Thanks!

Adbot
ADBOT LOVES YOU

csammis
Aug 26, 2003

Mental Institution

Waltzing Along posted:

I figured it out. Thanks!

Come on, don't do this. Leave your question in place so others can see the solution.

God Exists.
Sep 26, 2010

by Ozma
Is there a website where you can input a hex color code and it tells you what color it is?

csammis
Aug 26, 2003

Mental Institution

God Exists. posted:

Is there a website where you can input a hex color code and it tells you what color it is?

If you mean the color name there's this: http://www.december.com/html/spec/colorcodes.html

If you mean what #FF046C makes, or something like that, try this: http://html-color-codes.info/

Both of these were found by Googling for "hex color codes"

poverty goat
Feb 15, 2004



I'm working on a standard dynamic linked list assignment for a 200 level computer science class. We had a question on the last test to the effect of "if these cout << ... lines were added to the different constructors, destructor, and assignment operator, what would the output be for these code snippets?" Basically, a roundabout way of asking which bit of code you're dealing with on the back end to do various tasks.

So now, back to the program at hand, I've got things ready to hand in and working gloriously (the assignment was actually to make some modificatins to the author's code from our textbook) but I decided to try adding a cout to the destructor on a whim and it just doesnt loving do anything unless I manually call the destructor, even with the author's code, in either Visual C++ or Bloodshed. It compiles and runs without so much as a warning, and won't compile at all if I comment out the destructor. But no matter what I do, I can't get output from within the destructor to show up unless I call it myself.

Is this a normal thing? Or am I actually possibly doing something wrong?

For reference, it's based on bag3.h/node1.h from here: http://www.cs.colorado.edu/~main/chapter5/.

e: its awesome because I can post from school but edit doesnt work so I hit post by accident with a trailing sentence on the end here yeaahh

poverty goat fucked around with this message at 23:30 on Oct 26, 2010

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
You're at least expecting something wrong. Since this is a linked list, my guess is that you've got a lot of heap-allocated objects and you're not actually deleting them, in which case you've got a memory leak. Although the API in that header kindof suggests that deleting nodes is the responsibility of the callers, except possibility after list_clear.

Duke of Straylight
Oct 22, 2008

by Y Kant Ozma Post
If you don't get output from a print statement in a destructor when you it's called on object destruction, but do when you call it directly... yeah, I'd say the most likely reason is that your objects are not actually getting destroyed. That, or you forgot to flush the output stream :v:.

You'll want to post the actual code you wrote. Being able to see what you're trying to reason about has a tendency to make debugging easier.

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


gggiiimmmppp posted:

I'm working on a standard dynamic linked list assignment for a 200 level computer science class. We had a question on the last test to the effect of "if these cout << ... lines were added to the different constructors, destructor, and assignment operator, what would the output be for these code snippets?" Basically, a roundabout way of asking which bit of code you're dealing with on the back end to do various tasks.

So now, back to the program at hand, I've got things ready to hand in and working gloriously (the assignment was actually to make some modificatins to the author's code from our textbook) but I decided to try adding a cout to the destructor on a whim and it just doesnt loving do anything unless I manually call the destructor, even with the author's code, in either Visual C++ or Bloodshed. It compiles and runs without so much as a warning, and won't compile at all if I comment out the destructor. But no matter what I do, I can't get output from within the destructor to show up unless I call it myself.

Is this a normal thing? Or am I actually possibly doing something wrong?

For reference, it's based on bag3.h/node1.h from here: http://www.cs.colorado.edu/~main/chapter5/. I can post

Is your destructor declared as virtual? If not, add that and see if it fixes the problem.

Morpheus
Apr 18, 2008

My favourite little monsters
I think this is the right thread to put this in:

I'm trying to get a web service up and running, just to learn J2EE stuff, and it seems like the world is trying to stop me from doing this. First, tomcat won't run because of an error that no one seems to know about ([408 prunsrv.c] [error] The system cannot find the file specified.), then I tried the Sun Java System Application Server, and found that it simply wouldn't start any of the domains I created for it. So I'm going a little crazy here just trying to set up a simple drat server.

So I guess I'm wondering if anyone has a very simple, very step-by-step tutorial to these things that takes into the account that something might go wrong.

Scaevolus
Apr 16, 2007

God Exists. posted:

Is there a website where you can input a hex color code and it tells you what color it is?

Not that I know of, but I imagine it would be easy to make one using the data from XKCD's color survey experiment.

It might be a good project for learning to use Google AppEngine.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



God Exists. posted:

Is there a website where you can input a hex color code and it tells you what color it is?

http://www.somacon.com/p142.php may have more colors listed than the one csammis posted - hosed if I'm gonna sit and count them.

PDP-1
Oct 12, 2004

It's a beautiful day in the neighborhood.
I have a project coming up which is going to need some code to read data out of a hardware buffer at least once every 4 milliseconds to prevent overflow. I'm a bit nervous since this will be running on an older XP machine with a single-core CPU.

In my brief investigations (totally new to this kind of tight timing) I've read that the XP thread manager switches between threads with a quantum of 10 to 15 mS depending on hardware configuration. Does this imply that I'm totally hosed in trying to get guaranteed 4mS timing, or is that just a worst-case scenario that means any given thread can run up to 10 or 15 mS before switching. If 10 mS is just an upper bound, is there anything I can do to lower it?

I also assume I'll want to run my own process as high priority and make sure as little other crap as possible is running at the same time. Are there any guides to stripping down an XP system to a minimum?

Thanks.

Zhentar
Sep 28, 2003

Brilliant Master Genius

PDP-1 posted:

I have a project coming up which is going to need some code to read data out of a hardware buffer at least once every 4 milliseconds to prevent overflow. I'm a bit nervous since this will be running on an older XP machine with a single-core CPU.

4ms is shorter than the average disk read latency for even the fastest mechanical drive. In other words, doing your task is flat out impossible in userland. You need something kernel level to read the buffer, and I think DPCs are what you're looking for.

PDP-1
Oct 12, 2004

It's a beautiful day in the neighborhood.
Thanks for the reply. I think I panicked a bit early when I read that the hardware system was going to be sending bursts of 1 megabyte/sec into a 4k buffer. In reading a bit more of the documentation it looks like the interface card sets up a DMA channel that handles the data flow without my program having to be directly involved. That makes a lot more sense, but was non-obvious given that the documentation for this thing is horrible and scattered in a half-dozen random pdf files on the manufacturer's website.

I'd still be interested in any guides as to what stuff I can rip out of an XP system to ensure that there are as few background processes running as possible, if anyone knows of such a thing.

Zhentar
Sep 28, 2003

Brilliant Master Genius
I don't know of any guides offhand, but basically what you want is to recreate TinyXP, using nLite. Even without a guide though, it's easy to figure out a lot of things that can be removed with nLite.

Vino
Aug 11, 2010
I'm trying to do some simple winsock2 stuff. If you want to make fun of me for winsock2 keep it to yourself. The Microsoft sample code says to call send() shutdown(..., SD_SEND) and then go about recv()'ing data. So this works just fine in the debugger, but when I have it run normally the recv() doesn't get any data, returns 0. It only seems to work if there's some time that passes between the send() and the shutdown() call. Otherwise recv immediately returns 0 with no data returned. I'd rather not try any hacks that force the thing to wait one second between send and shutdown. Anybody have a clue?

Vino
Aug 11, 2010
Maybe I'll get more responses to the above question if I post some code:

http://pastebin.com/N1vb2fU0

Here's just the relevant part:

code:
        iResult = send( iSocket, sSend.c_str(), sSend.length(), 0 );
        if (iResult == SOCKET_ERROR)
                return false;
 
        // Works with this sleep in here. Doesn't work without.
        // Sleep(100);
 
        iResult = shutdown(iSocket, SD_SEND);
        if (iResult == SOCKET_ERROR)
                return false;

        std::string sResult;
        do {
                char szBuf[1000];
                iResult = recv(iSocket, szBuf, 1000, 0);
                if (iResult < 1000)
                        szBuf[iResult] = '\0';
                sResult.append(szBuf);
        } while( iResult > 0 );

MrMoo
Sep 14, 2000

You could try setting SO_SNDBUF to 0.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

So I'm using mplayer in my python library for getting info like video resolution and bitrate.

This library will be part of an app that I'm not the main developer on.

As a mainly Windows guy, I'm planning on just including the Win32 mplayer binary and various other files required by the mplayer license, but I'm not positive of what the right way to do this on linux is.

Is it considered "bad" to do this?

The main developer of the app really doesn't want people to have to go installing dependencies on their own.

Zhentar
Sep 28, 2003

Brilliant Master Genius
The right way to do it on linux is to package it and list the dependency in the package, and then let the package manager go install dependencies. Distributing binaries from other projects instead of depending on having shared libraries installed is considered more than a little "bad".

Jonnty
Aug 2, 2007

The enemy has become a flaming star!

Anyone know of a program I can use to see if a certain string could be generated by a given context-free grammar? I don't need to parse anything, I just need to know whether it matches or not.

ToxicFrog
Apr 26, 2008


I don't know of any program specifically for this purpose, but you should be able to whack the CFG into any parser generator or parser combinator of your choice, then feed the string to it and see if it accepts.

litghost
May 26, 2004
Builder

Jonnty posted:

Anyone know of a program I can use to see if a certain string could be generated by a given context-free grammar? I don't need to parse anything, I just need to know whether it matches or not.

I am not 100% sure (correct me if I'm wrong), but I think you just asked a question that is equivalent to "The halting problem". The only way to determine if it matches is to run it.

Mustach
Mar 2, 2003

In this long line, there's been some real strange genes. You've got 'em all, with some extras thrown in.
A parser is what you want.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

litghost posted:

I am not 100% sure (correct me if I'm wrong), but I think you just asked a question that is equivalent to "The halting problem". The only way to determine if it matches is to run it.

Since that is, in fact, a halting algorithm which correctly decides the problem, ACFG is decidable. The formalism does not give bonus points for figuring it out by inspection.

Boz0r
Sep 7, 2006
The Rocketship in action.
I'd like to learn how to write programs like Amplitube that models guitar effects and amplifiers. Does anyone know of any good resources/books on where to begin?

Thrombosis
May 7, 2007
Does anyone have any suggestions for ways/methods of automating numbering in sequence? I'm fairly new to coding so I'm a bit lost as to how to proceed. Basically, I have a large document of several thousand lines in XML that have <l n="x"> in front of each. Each x needs to be changed to the next number in sequence, so <l n="1">, <l n="2"> on the next line, etc etc all the way through.

What's the simplest/fastest way of doing this?

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

Thrombosis posted:

Does anyone have any suggestions for ways/methods of automating numbering in sequence? I'm fairly new to coding so I'm a bit lost as to how to proceed. Basically, I have a large document of several thousand lines in XML that have <l n="x"> in front of each. Each x needs to be changed to the next number in sequence, so <l n="1">, <l n="2"> on the next line, etc etc all the way through.

What's the simplest/fastest way of doing this?
While you could certainly use an XML parser to find all the l tags and change the n attribute, it's almost surely going to be easier to just use a regular expression to make the substitution. Here's how you'd do it in Perl, for example:

code:
Bender:~ ntaylor$ cat foo.pl 
use strict;
use warnings;

my $count = 0;
while (my $line = <STDIN>) {
    while ($line =~ '<l n="x">') {
        $line =~ s/<l n="x">/<l n=$count>/;
        $count++;
    }
    print $line;
}
Bender:~ ntaylor$ cat foo.txt 
<l n="x"> <l n="x"> <a b="foo">
<l n="x">
foo
bar
Bender:~ ntaylor$ cat foo.txt | perl foo.pl 
<l n=0> <l n=1> <a b="foo">
<l n=2>
foo
bar

tef
May 30, 2004

-> some l-system crap ->

Jonnty posted:

Anyone know of a program I can use to see if a certain string could be generated by a given context-free grammar? I don't need to parse anything, I just need to know whether it matches or not.

Well you need to build a recognizer, which normally involves writing a parser, but sometimes you can skip the construction of the parse trees, but in a sense, you're still having to parse the string, even if you're not producing a parse tree, you still need to keep track of (some) resolutions.

Dealing with *any* context-free grammar will require generalized parsing. GLR (edit: I was being confused about sub optimal behavious on nullable rules, but yeah GLR is actually pretty good but most of them are parser-generators)

Anyway, i'd recommend earley parsing for a number of reasons:

It works on all context free grammars in cubic time, but works in linear time for many simpler grammars.
And if you're that way inclined there are ways to make it linear time for a crazy amount of grammars (lr-regular) (see the marpa parser...).
Earley parsing doesn't *necessarily* require any preprocessing or grammar re-writing, so many implementations are
parsing libraries rather than parser-generators.
It doesn't build any parse trees until it has read in the entire file, so you should be able to eliminate this step if you need to.

There should be an Earley Parser written in your language of choice, although I would be wary as many implementations are buggy (as the original paper has a few flaws)

(If you want to write it yourself (for some reason) go and get 'parsing techniques 2nd ed', or use this version of the parser: Graham, S. L., Harrison, M. A., and Ruzzo, W. L. An improved context-free recognizer. ACM Trans. Prog. Lang. Syst., 2(3):415–462, July 1980)


ToxicFrog posted:

I don't know of any program specifically for this purpose, but you should be able to whack the CFG into any parser generator or parser combinator of your choice, then feed the string to it and see if it accepts.

Except most parsers/combinators do not support arbitrary context-free grammars, without some heavy re-writing.

tef fucked around with this message at 06:24 on Nov 1, 2010

FamDav
Mar 29, 2008
So, I'm writing quicksort in assembly and I have my partitioning done. My problem comes in actually performing the recursive calls.

http://www.pastebin.ca/1978570

Looking specifically at 54-64. As far as I can tell, the rest of the code is correct.

Anybody want to explain to me how to make this recurse correctly :)?

FamDav fucked around with this message at 11:22 on Nov 1, 2010

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
Your prologue/epilogue assume that the caller pops the arguments, but your calls assume the callee pops the arguments.

vote_no
Nov 22, 2005

The rush is on.
This will probably be an answer I should have figured out, but Google used to parse literal strings, and now it just guesses what you meant. I want to search for things like "ADD.B" or "(car (cdr" and it never works anymore. I couldn't find anything in the Google documentation, and I figure this thread would be full of people trying to search Google for function references. It used to handle logic too, now I can't seem to search for -- say -- "Barney" NOT "Dinosaur" either.

ufarn
May 30, 2009
After I run some git commands, I can't get back to my prompt.

I've tried Ctrl+C+C, but that won't do it. What's the command in git (Windows Git Bash)?

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?

vote_no posted:

This will probably be an answer I should have figured out, but Google used to parse literal strings, and now it just guesses what you meant. I want to search for things like "ADD.B" or "(car (cdr" and it never works anymore. I couldn't find anything in the Google documentation, and I figure this thread would be full of people trying to search Google for function references. It used to handle logic too, now I can't seem to search for -- say -- "Barney" NOT "Dinosaur" either.

For NOT you can use -, as in "Barney" -Dinosaur
For the exact strings, it looks like it tends to ignore special characters, which is annoying.

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
I have a question about XML validation. I'm playing with Schemas with some success, but I'm wondering--do people actually use them?

In this case I'm working in C# and finding the output to be a little vague. For example, I have noted that one of the elements needs to occur at most once. If it shows up twice, the error I get is pretty much "I wasn't expecting this element that has a perfectly legal name. I was expecting something else." Is there anything more specific it could do about it? Otherwise I expect users to submit crap XML, get a vague error, and come running to me. I guess at least now I'll now it's an XML problem rather than having my code make bad assumptions and try to run with it. It did also reduce what would be 5 pages of code for checking stuff into a one page XML file.

Assuming Schemas are worth using, I have a question about denoting groups. I know about xs:sequence and xs:choice, but I wonder if there's something that marks a group of stuff that can come in any order. A sequence requires elements to appear in the given order, and a choice seems to mean only 1 of the many is available. I have some elements that conceptually have no real reason to be one before the other, so I wanted to keep it that way in the validator.

ToxicFrog
Apr 26, 2008


ufarn posted:

After I run some git commands, I can't get back to my prompt.

I've tried Ctrl+C+C, but that won't do it. What's the command in git (Windows Git Bash)?

What commands? Are you sure you aren't in an editor that it's waiting for you to exit or something?

Assuming you're not...

If you're in the msys shell, ctrl-C is interrupt and ctrl-D is EOF. If neither of those work ctrl-Z should background the current process and give you the shell back. If nothing produces any output it's possible you've stopped the terminal itself by pressing ctrl-S at some point - try ctrl-Q to start it again.

If you're in windows cmd.exe and are just using git from there, ctrl-C is still interrupt and ctrl-Z <enter> is EOF and I have no suggestions beyond that.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

HappyHippo posted:

For NOT you can use -, as in "Barney" -Dinosaur
For the exact strings, it looks like it tends to ignore special characters, which is annoying.

It's actually especially annoying, since it ignores nearly all punctuation and symbols. So searching for "test@thing.com" seems to be the same as "test thing com". The problem is that many of these symbols used to be/are quite contextually useful for reducing search confusion. Wish there was a string literal style search command, though I don't even know if they store/process non-alpha characters any more.

Jonnty
Aug 2, 2007

The enemy has become a flaming star!

This is sometimes useful for codingy search queries

http://www.google.com/codesearch

Eox
Jun 20, 2010

by Fluffdaddy
I've been interested in learning to code for a fair while now, but it's only recently that I've gotten off of my rear end and tried something out. Currently, that means loving around and making .bat files, which I understand is something a mentally challenged 6 year old could do. I've made the requisite helloworld.bat, but something I tried today struck me as interesting. I copied a basic Conditional Shutdown code, which I kind of understand, but I have a few questions as to how things generally work.

BEFORE
code:
@echo off
color 3
title Conditional Shutdown
set /p name=enter a name:
:start 
cls
echo Hi, %name%
echo. 
echo 1.Shutdown
echo 2.Quit
set /p choice=enter your choice 1,2: 
if %choice%==1 goto shutdown
if %choice%==2 exit
 
:shutdown
cls
set /p sec=enter the number of seconds that you wish the computer to shutdown in: 
set /p msg=enter the shutdown message you wish to display: 
shutdown -s -f -t %sec% -c "%msg%"
echo shutdown initiated at %time%
set /p cancel=type cancel to stop shutdown 
if %cancel%==cancel shutdown -a
if %cancel%==cancel goto start
AFTER
code:
@echo off
color 4
title Conditional Shutdown
set /p name=STATE YOUR NAME, MORTAL:
:start 
cls
echo GREETINGS, PUNY %name%. WHAT WILL YOU DO?
echo. 
echo 1.ATTEMPT TO ESCAPE
echo 2.SHUT DOWN YOUR COMPUTER
echo 3.DO A SILLY LITTLE DANCE
set /p choice=MAKE YOUR CHOICE: 
if %choice%==1 goto shutdown
if %choice%==2 goto shutdown
if %choice%==3 goto shutdown
 
:shutdown
cls
set /p sec=WHAT IS YOUR FAVOURITE NUMBER: 
set /p msg=WHAT IS YOUR PERSONAL MOTTO: 
shutdown -s -f -t %sec% -c "%msg%"
echo LETS ALL LAUGH, LAUGH WITH ME
set /p cancel=HAHAHAHA 
if %cancel%==cancel shutdown -a
if %cancel%==cancel goto start
So far I've managed to fool a couple of my friends with this. As I said before, I understand the general functions of each line, but this:
code:
shutdown -s -f -t %sec% -c "%msg%"
Is a complete mystery to me. I know that it causes the shutdown, but I don't know how.

Second, I want to learn some ways to make this thing more assholeish. Nothing approaching a virus or worm, so no deleting any files. Just more of an annoyance.

Third, I know that what I'm doing now is about as basic as you can get. What language should I learn first, and what are the key concepts that I should understand before I dive headlong into this?

TL;DR Some idiot is screwing around with .bat files and wants to know more

Adbot
ADBOT LOVES YOU

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Eox posted:


code:
shutdown -s -f -t %sec% -c "%msg%"
Is a complete mystery to me. I know that it causes the shutdown, but I don't know how.

shutdown is just a dos command like "dir" or "copy awesomefile toawesomeplace".

Type it on the commandline.

code:
set /p sec=enter the number of seconds that you wish the computer to shutdown in: 
set /p msg=enter the shutdown message you wish to display: 
That part "remembers" (the "/p" makes it ask you to type them in) the seconds and message in a variable (temp place in memory) called "sec" and "msg" respectively.

When you get to the shutdown line, the %sec% and %msg% parts recall those parts from memory.



Eox posted:

Third, I know that what I'm doing now is about as basic as you can get. What language should I learn first, and what are the key concepts that I should understand before I dive headlong into this?

TL;DR Some idiot is screwing around with .bat files and wants to know more

Python is a good choice. There's a megathread for it, and lots of good beginner-quality tutorials.

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