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
Dauq
Mar 21, 2008

Plastic Jesus posted:

I thought about this, but the byte of interest will be part of an integer (and in a register already), not a string of characters.

On a related note, does anyone know if Microsoft's implementation of things like strlen() and strchr() make use of the REP SCAN instructions? I suppose that if I wasn't so lazy I'd just open in up in IDA right now. But I am.

Ok, i misunderstood i thought you were just trying to find the zeros in an array of bytes (your "puc" pointer).

If your integer is in a register the best i can think of is to use shift to right, and compare the byte-sized "low" registor to 0.

;integer in eax
...
mov ecx, 4
test_loop:
cmp al, 0
jz found_zero
shr eax, 8
loop test_loop
found_zero:
...
;position of byte (1-4) in ecx

As for the strlen question, sorry i never checked. :effort:

Adbot
ADBOT LOVES YOU

Z-Bo
Jul 2, 2005
more like z-butt

Professor Science posted:

isn't tenenbaum basically a source walkthrough of minix, though? that seems kind of silly.

zootm posted:

I don't think it is. I seem to recall it gives a pretty detailed overview of the construction of various popular kernels.

(I realize I am replying to something a month old, but wanted to share my thoughts.)

Tannenbaum has three systems books. Two general operating systems books, and one distributed systems book. He also has a networking book. Both of Tannenbaum's OS books are referred to as the Minix book, even though only one of them is "The Minix Book" while the other is a more conceptual overview of OSes. If you read Modern Operating Systems, then The Minix Book can probably be replaced by something like Advanced Unix Programming by Marc Rochkind and Advanced Programming in the UNIX Environment by Richard Stevens. Rochkind walks through building a fully featured shell, and Stevens is simply the standard bearer of Unix systems programming writing.

Silberchatz has two systems books. They are both called the Dinosaur Book. One uses Java for examples, though. They both have the majority of the same content. Personally, I hated the Java book; all the examples are toys you cannot do anything with. The regular book is a bit better, but fills your head with stupid metaphors just like the Java book. Don't presume if you know Java really well, "Oh, it's in Java, it will make learning it so much easier".

Z-Bo fucked around with this message at 05:04 on Mar 25, 2008

mister_gosh
May 24, 2002

In Java 1.4 or lower, I need to write something that acts sort of like a multi-dimensional String array, but I have no idea how to do it. I'd prefer to use a HashMap which accepts multiple/infinite values. In other words key|value|value|value. I realize that doesn't make sense, let me illustrate.

I have an unpredictable amount of names (of files) and multiple locations that file is stored.

code:
NAME        LOCATION       LOCATION  LOCATION
buyingShoes /en/loc/pub /es/loc/van 
install     /en/ppp     /en/loc      /es/loc
flyGuide    /en         /en/loc/van  /es
If I come upon another location of buyingShoes, I want to be able to find that key and add on an additional location.

In addition, I want to cycle through the entire result set at some point and process each key (name). So I will need some type of foreach loop that cycles through each name and lists each location.

Does anyone have an idea how to do this?

JoeNotCharles
Mar 3, 2005

Yet beyond each tree there are only more trees.
What's wrong with storing a List (or Vector, or whatever Java calls it) as the value for each key of the HashMap?

mister_gosh
May 24, 2002

JoeNotCharles posted:

What's wrong with storing a List (or Vector, or whatever Java calls it) as the value for each key of the HashMap?

Thank you captain obvious. No, really, thanks! I was thinking in terms of Strings, but I think I've been too much Perl lately that I forgot I can throw these in any type of object.

zootm
Aug 8, 2006

We used to be better friends.
The Commons Collections library also has a MultiMap object which does this sort of thing, but it doesn't seem to use generics. I did also find this library which refactors them to use generics though.

N.Z.'s Champion
Jun 8, 2003

Yam Slacker

ShoulderDaemon posted:

And you have got to explain why you're asking this question.

:siren: I can now reveal that :siren:

N.Z.'s Champion posted:

This is a bit of a weird question but what programming languages use :: (double colon) as part of their syntax and for what?

This was about Microsoft's push for OOXML approval at the ISO and a particularly dumb part of the specification that required implementors to implement Microsoft OLE2 with particular method calls that contained :: (double colon) within them.

Within the specification there's Part 4: 3.18.49 ST_OleUpdate (OLE Update Types) which is used by Part 4: 3.3.1.59 oleObject (Embedded Object). This part of OOXML remains as it was in ECMA-376 so you can read the description here on OpenISO.org. It requires implementors to call "IOleObject::Update" or "IOleLink::Update" as method calls (which are the MS Windows OLE method calls) which effectively limits the implementation programming language as :: (double colon) means different things in different languages and may be unusable in some.

This made it into a report I wrote for Standards NZ on OOXML so thanks for your help everyone (especially ShoulderDaemon, tef and 6174 :) )

(Oh and psssst goons... it's me. I'm da Matthew Holloway in the op)

N.Z.'s Champion fucked around with this message at 23:03 on Mar 25, 2008

Triple Tech
Jul 28, 2006

So what, are you quitting to join Homo Explosion?

mister_gosh posted:

Thank you captain obvious. No, really, thanks! I was thinking in terms of Strings, but I think I've been too much Perl lately that I forgot I can throw these in any type of object.

Uhh, what does your exposure to Perl have to with it? You could have done the exact same thing, storing an anonymous array as the value of each key.

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!

Triple Tech posted:

Uhh, what does your exposure to Perl have to with it? You could have done the exact same thing, storing an anonymous array as the value of each key.

That doesn't really work. In Perl, hash keys aren't real scalars, they're just strings. This means that if you do:
code:
$hash{ [1, 9] } = 1;
print @{ (keys %hash)[0] };
Perl will complain because (keys %hash)[0] is the string ARRAY(0x........) and not a real array reference. And if you're storing objects you have to be careful about string overload.

You can still store references as hash keys (and I do it occasionally) but it has some heavy caveats. This is what mister_gosh meant.

If you're set on doing it though, use Tie::RefHash or Tie::RefHash::Weak which will actually do what you want.

Filburt Shellbach fucked around with this message at 16:21 on Mar 27, 2008

Triple Tech
Jul 28, 2006

So what, are you quitting to join Homo Explosion?

Sartak posted:

This is what mister_gosh meant.

Clearly not.
code:
$VAR1 = {
          'buyingShoes' => [
                             '/en/loc/pub',
                             '/es/loc/van'
                           ],
          'flyGuide' => [
                          '/en',
                          '/en/loc/van',
                          '/es'
                        ],
          'install' => [
                         '/en/ppp',
                         '/en/loc',
                         '/es/loc'
                       ]
        };

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!

Triple Tech posted:

Clearly not.

Oh. I misunderstood. You guys keep saying "the value for each key" and I took that to mean "each key", not "each value". English! :argh:

Anyway, keying by object is useful, and I do wish Perl supported it better.

_aaron
Jul 24, 2007
The underscore is silent.
This is more of a general practice question instead of specific code stuff, but I assume this is an okay spot for it.

I have some user input that needs to be validated. This input will be stored in member variables in some model class. Is it better to call a validation method that will return a bool based on whether the data is valid, or should I throw an exception from the member variable's setter method? Basically this:
code:
if (validate(someData))
   myObject.SetSomeValue(someData);
or
code:
try {
   myObject.SetSomeValue(someData);
} catch (SomeException) {
   // handle something
}

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
Generally speaking, exceptions should be for "exceptional" things. I'd say bad user input isn't all that exceptional, and it's probably better to validate explicitly. It really depends on your own preferences though.

Incoherence
May 22, 2004

POYO AND TEAR
Alternative answer, which might work for some applications:
code:
if (!myObject.SetSomeValue(someData)) {
  // handle error
}

Tots
Sep 3, 2007

:frogout:
In sed I am trying to take a string where a single quote occurs inside a set of single quotes, pinpoint the middle quote, and do something with it.

Here is where I am at.
code:
echo "This is 'Tot's' sample string" | sed "s|\(*'*\)\('\)\(*'*\)|\1\2\2\3|"
I would expect the output for this to be,
code:
This is 'Tot''s' sample string
but it's not. So now I'm here for help.

da 2pacolypse
Sep 21, 2005

analofficer
This isn't a question about code but I was wondering if anyone knew a free/open-source text editor like codeblocks but for assembly. I’m asking this because I tend to get lost in the code whenever I code in metapad and was wondering if there was a editor that makes assembly code pretty colors and etc.

Tots
Sep 3, 2007

:frogout:
I really like Notepad++ for all my coding needs.

One of the selling points for me is the build in console plugin. Great for quick compiling and execution.

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!

Tots posted:

code:
echo "This is 'Tot's' sample string" | sed "s|\(*'*\)\('\)\(*'*\)|\1\2\2\3|"
Regex are not shell globs. * is only a quantifier, it doesn't mean anything on its own. Replacing * with .* might do it. You can also remove some clutter from your code:
code:
sed "s|\('.*\)'\(.*'\)|\1''\2|"
I sure hope you aren't using this to quote-escape a string for a database..

tef
May 30, 2004

-> some l-system crap ->
You might be better off using \(\[^'\]\) over .*.

\[...\]is a character class, so \[abc\] matches a,b, or c.

\[^...\] is the negation, so \[^abc\] matches anything but a,b, or c.

Presa Canario
Feb 15, 2008
Forum member since 37308 A.D.
I'm trying to write an AI game search tree with a depth-first search in java. I already have a recursive version that works, but this seems like it would be a lot faster. The problem is it needs to iterate somehow so that I can stop it at a maximum depth, and so that I can do min/max at certain levels. I tried doing this:

code:
depth = 5;
s = new stack();
leaves = new queue();
State current = (current state);
s.push(current);
while(s not empty)
{
    current = s.pop();
    depth--;
    nextMoves = (possible moves from current)
    for(move in nextMoves)
    {
         State new = transitionState(current, move);
         if (depth==0)
         {
              leaves.push(new);
              depth++;
         }
         else s.push(new);

    }
}
...but depth never goes back up once it hits the bottom two levels. It there a better way or should I stick with recursive?

csammis
Aug 26, 2003

Mental Institution

Presa Canario posted:



It doesn't look like you're ever popping from leaves, is that correct?

edit: It's been a while since I've done this, but wouldn't a stack-based DFS look more like this? A single stack, no leaves.

code:
Stack<Node> s = new Stack<Node>();
s.push(GetTreeRoot());
while(s.size() > 0)
{
  Node current = s.pop();
  // Process current node
  if(current.HasChildren)
  {
    // Push all children onto s so they get visited
  }
}

GT_Onizuka posted:

It would probably be better to store the depth of nodes, along with the nodes themselves, so you don't have to handle any incrementing.

This too, I think the depth calculation is where you're getting messed up.

csammis fucked around with this message at 18:34 on Mar 28, 2008

defmacro
Sep 27, 2005
cacio e ping pong

Presa Canario posted:

I'm trying to write an AI game search tree with a depth-first search in java. I already have a recursive version that works, but this seems like it would be a lot faster. The problem is it needs to iterate somehow so that I can stop it at a maximum depth, and so that I can do min/max at certain levels. I tried doing this:

code

...but depth never goes back up once it hits the bottom two levels. It there a better way or should I stick with recursive?

You seem to be increasing the 'depth' value based on the number of children the node at depth = 0 has, which I don't think is what you want to do. The difference between the depth of the current value, and the next value on the top of the stack is what is going to change the depth. It would probably be better to store the depth of nodes, along with the nodes themselves, so you don't have to handle any incrementing. If you had a tree like this:



And your last node by depth would be node 7, your code will only increment the depth by 1, rather than returning to depth 1 (where nodes 2/3 are).

defmacro fucked around with this message at 18:41 on Mar 28, 2008

Presa Canario
Feb 15, 2008
Forum member since 37308 A.D.
Ah thanks adding a depth variable to the State class worked. Now each state starts with depth=0, then the transition() method adds one to it each time.

csammis posted:

It doesn't look like you're ever popping from leaves, is that correct?
Well the idea was that it would store all the leaves in a queue and then go back later looking for the best one.

Presa Canario fucked around with this message at 19:59 on Mar 28, 2008

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...
Maybe this is less of a programming question and more of a programming tool or programmer question but: can anyone suggest alternatives to Trac?

We're a small bioinformatics lab, rolling our own software and libraries for use by ourselves and sometimes other people. For a while, I've felt that we should be more disciplined about our code and knowledge: have all the code committed to central repositories and backed, have a single place for logging issues, writing down common knowledge and going to for downloading the latest version of our releases. Trac seemed to be the obvious choice - everyone uses it - and I delegated the job to one of my colleagues. However, he's been having terrible problems getting it configured, stumbling over one problem after another and has been roadblocked for a week trying to get it to talk to the database. (The db is running, the connection details are correct, but Trac just keeps reporting that it is unable to connect.) From mailing lists and googling, it looks like our experience isn't uncommon.

Naturally, I wonder what the alternatives are. Any suggestions? For what it's worth, we mainly work in Python, with some Javascript and Java sidelines.

Allie
Jan 17, 2004

outlier posted:

Maybe this is less of a programming question and more of a programming tool or programmer question but: can anyone suggest alternatives to Trac?

We're a small bioinformatics lab, rolling our own software and libraries for use by ourselves and sometimes other people. For a while, I've felt that we should be more disciplined about our code and knowledge: have all the code committed to central repositories and backed, have a single place for logging issues, writing down common knowledge and going to for downloading the latest version of our releases. Trac seemed to be the obvious choice - everyone uses it - and I delegated the job to one of my colleagues. However, he's been having terrible problems getting it configured, stumbling over one problem after another and has been roadblocked for a week trying to get it to talk to the database. (The db is running, the connection details are correct, but Trac just keeps reporting that it is unable to connect.) From mailing lists and googling, it looks like our experience isn't uncommon.

Naturally, I wonder what the alternatives are. Any suggestions? For what it's worth, we mainly work in Python, with some Javascript and Java sidelines.

Trac's pretty amazing, I can't imagine why you'd want to throw away such a great piece of software. Are you trying to use MySQL or PostgreSQL with it? It's really meant to be used with SQLite, and there really isn't any good reason not to use SQLite, and that's painless to set up.

If you are using SQLite, make sure the user running Trac has read/write permissions to the Trac instance folder and the database file. Beyond that, there isn't really much that could go wrong with the database.

da 2pacolypse
Sep 21, 2005

analofficer

Tots posted:

I really like Notepad++ for all my coding needs.

One of the selling points for me is the build in console plugin. Great for quick compiling and execution.

Oh poo poo notepad++ does assembly? I didn't know that, thanks!

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...

Milde posted:

Trac's pretty amazing, I can't imagine why you'd want to throw away such a great piece of software. Are you trying to use MySQL or PostgreSQL with it? It's really meant to be used with SQLite, and there really isn't any good reason not to use SQLite, and that's painless to set up.

Apart from the whole "not working" bit? Admittedly none of us are sys-admins, but it's been fighting back for over a fortnight now. It might be great, but at this stage it's only natural to wonder how much more time we have to devote to just setting it up.

We started with SQLite, had no luck and swapped to PostgresSQL, largely to see if that would isolate the problem. Still no dice - there's a non-informative failure at the connect stage.

quote:

If you are using SQLite, make sure the user running Trac has read/write permissions to the Trac instance folder and the database file. Beyond that, there isn't really much that could go wrong with the database.

Thanks! That might be worth a look - we installed Trac as its own user but maybe one of the perms has gone astray.

axolotl farmer
May 17, 2007

Now I'm going to sing the Perry Mason theme

This is a bash/shellscript question:

I have file with lots of DNA sequences in them. Missing letters are replaced by -s. They look like this:

-----AACGCT--TTGGT--
-GG-TAACGCT--TTGGT--
TGG-AACGCT---TTGGTCC


I want to replace the leading and trailing, but not internal, -s of each line with ?s to get this result:

?????AACGCT--TTGGT??
?GG-TAACGCT--TTGGT??
TGG-AACGCT---TTGGTCC


Finding the leading and trailing -s is an easy regexp ( ^[-]* and [-]*$ ), but is there an efficient way to replace them with the same number of ?s ?

Now I'm using a horrible and slow sed script to do that.

code:
sed 's/^-/\?/' myfile >leadingdeleter1
var0=0
while [ " $var0" -lt "$LIMIT" ]
do
        sed 's/\?-/\?\?/' leadingdeleter1 > leadingdeleter2
        sed 's/\?-/\?\?/' leadingdeleter2 > leadingdeleter1
let "var0 += 1"
done
I prefer to stay in shellscript, but if perl would be much more efficient, I'll try that.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
I don't know sed, but in Perl, the following should work:
code:
$foo =~ s/(^-+|-+$)/"?" x length($1)/eg;
The "e" option specifies that the second half of the regex should be evaluated as code.

JawnV6
Jul 4, 2004

So hot ...
What's a good resource for learning how to implement a hashing algorithm?

I'm looking at making a Bloom filter in verilog, I can find a few thousand descriptions on the error rate calculation but apparently programmers can just sneeze out random hashing algorithms on command and don't need any training.

Shastings
Nov 14, 2005

E: Disregard this post, I figured out another solution.

Shastings fucked around with this message at 05:14 on Apr 1, 2008

6174
Dec 4, 2004

JawnV6 posted:

What's a good resource for learning how to implement a hashing algorithm?

Have you looked at TAOCP vol 3?

6174
Dec 4, 2004
I've got some Fortran code I'm working on and I'm trying to find an automated way to find a class of bugs I've just come across. Basically if you're trying to specify a double precision constant and don't explicitly mention that they are double precision, some compilers will interpret them as single precision and throw off the calculations. An analogous error in C would be not putting "L" after a constant if needed.

It seems to me that I should be able to come up with a regexp that would identify such constants. But I don't seem to be getting anywhere.

What I'm looking for is numbers that look like XXXX.YYYY (with the . and Y optional) that are not of the form XXXX.YYYYDZZZ. The futzing I've done with grep/egrep haven't come up with anything that doesn't generate way too many false positives. A few false positives are fine as I need to sort through by hand anyway, but any false negatives would be bad.

Does anyone know of a good way to find these constants?

(Unfortunately the compilers I've got don't have warning flags that indicate if it truncates constants like this)

poofactory
May 6, 2003

by T. Finn
I'm trying to set up a web site to take credit cards through authorizenet using the AIM system.

I'm slightly familiar with perl so I'm trying to implement their sample code.

http://developer.authorize.net/samplecode/

They've hard coded all of the values like cc number, name, address into the script and I am able to set the script up on my web site and it works fine so I know all my passwords and permission settings are ok.

The problem I have, and it is probably because I have to training at all in comp sci, is editing the script to accept the values from a form and pass those values to the gateway.

For example, one value in my form:

<input id="FormsEditField1" type="text" name="Amount" style="white-space:pre" value="50.00" size="10" maxlength="10">

I have the form set up to post this value to the perl script.

The original perl script says:

x_amount => "12.23",

So I changed that to

x_amount => "Amount",

x_amount being the value that the gateway recognizes as the total charge and Amount being the data from my form.

But I get an error that says no valid amount supplied.

Am I supposed to write some actual code to get it to process the form data or can I just change this or another section somehow?

Hopefully someone can give me an answer. I know perl isn't the most popular language right now.

tef
May 30, 2004

-> some l-system crap ->

6174 posted:

What I'm looking for is numbers that look like XXXX.YYYY (with the . and Y optional) that are not of the form XXXX.YYYYDZZZ.

This seems to work for me: /(\b(\d{1,4}(?!\.)|\d{1,4}\.\d{1,4})(?!D\d{3})\b)/

Although you may want: /(\b(\d{4}(?!\.)|\d{4}\.\d{4})(?!D\d{3})\b)/

code:
$ cat > numbertest                                              
1
1.0
1.02D1   
3D1
$ cat numbertest |  perl -p -e  'if (/(\b(\d{1,4}(?!\.)|\d{1,4}\.\d{1,4})(?!D\d{3})\b)/) {print "matched: $1 - "}else{print"fail: "}'
matched: 1 - 1
matched: 1.0 - 1.0
fail: 1.02D1
fail: 3D1
$ 

tef
May 30, 2004

-> some l-system crap ->

poofactory posted:

Hopefully someone can give me an answer. I know perl isn't the most popular language right now.

You realise that "Amount" is a string and "$Amount" is the string containing the variable $Amount ?

I would suggest continuing this over in the perl thread here

6174
Dec 4, 2004

tef posted:

This seems to work for me: /(\b(\d{1,4}(?!\.)|\d{1,4}\.\d{1,4})(?!D\d{3})\b)/

Although you may want: /(\b(\d{4}(?!\.)|\d{4}\.\d{4})(?!D\d{3})\b)/

This looks like it will work. This should be much better than trying to wade through 20K LOC, thanks.

JawnV6
Jul 4, 2004

So hot ...

6174 posted:

Have you looked at TAOCP vol 3?

I don't know what that is. "The Art Of C Programming" is coming up with several hits with different authors.

6174
Dec 4, 2004

JawnV6 posted:

I don't know what that is. "The Art Of C Programming" is coming up with several hits with different authors.

TAOCP is The Art of Computer Programming by Knuth.

edit: Since posting in the first place I've read (but not personally verified) that there is some discussion about hashing in the Dragon book as well (Compilers: Principles Techniques and Tools by Aho et al).

6174 fucked around with this message at 18:39 on Apr 2, 2008

Adbot
ADBOT LOVES YOU

StumblyWumbly
Sep 12, 2007

Batmanticore!
Hey, I'm a hard/firmware guy who only writes in C, Verilog and VHDL.

I need a simple language I can use to write scripts to manipulate text files. About the most complicated thing I'll do is read in a text file, strip out some stuff, and convert the ASCII into hex.

What language or tool would be best for this kind of stuff? It would have to run on a Windows XP system.

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