That looks suspiciously like someone took a PostScript document and ran it through a translator.
Posts made by Ozru
-
RE: Php pdf creation
-
RE: Difference of two angles without branching
As has been previously mentioned, the trig functions will be your killers here far more than mispredicted branches.
If you want the cosine of the angle between them, you can take the dot product, which is ((axbx) + (ayby)), and divide it by the product of the magnitudes of the two vectors, which would be sqrt((axax + ayay) * (bxbx + byby)).
If you need the sine of the angle, you can take the magnitude of the cross product, divided by the product of the magnitudes of the two vectors, giving you ((axby) - (bxay)) / sqrt((axax + ayay) * (bxbx + byby)).
Of course, if your vectors are already normalized, you can skip the entire divisor in these calculations.
These won't give you the general broad range of results you were looking for. arcsin and arccos each have a total range of M_PI, and you are looking for a range of 2*M_PI.
The sign of the magnitude of the cross product will tell you which vector is to the right of the angle you're measuring. If all you really wanted to do is check that, you don't need to do the division at all (nor take arcsin), since the divisor will never be negative.
The real mantras here are:
1) Know what problem you're trying to solve.
2) Choose an algorithm that solves it sensibly.
3) If it's not running fast enough, profile it to see where to improve it.
4) Only after the first three steps, make that optimization change. -
RE: Supermarket Self-Checkout
Fry's Foods (owned by Kroger, who also own Fred Meyer) does the self-checkout pretty well.
There is no conveyor belt. There is a bagging area with a carousel of bag racks, as well as an additional area to set things.
Barcoded items are simply scanned and then bagged, unless they require age verification, in which case you have to go (right then) and show ID to the clerk who watches over all four self-checkout stations.
Produce without a barcode requires you to hit a "Produce - no barcode" button, then enter the code that's on a sticker on the produce, and place it on the scanner/scale. Once it has been weighed, you get to bag it.
Bakery items without a barcode require you to hit a "Bakery Items" button, enter the code (for which the legend is on the bakery bag) and the quantity, and then place it on the scanner/scale. Once it has been determined to weigh within acceptable tolerances, you get to bag it.
Ready to pay? Hit the "Pay Now" button, then go through the "Do you have any coupons?" menu. "Yes" means you get to give your coupons to the clerk before proceeding.
Now tell it whether you're using cash, check, card, or food stamps. Check and food stamps require more clerk interaction. Cash just slurps it up, and card means you get to deal with a standard POS card reader/pinpad.
Getting change? A loud voice will tell you where the paper money is, if you get any back.
Oh, and there are no sentences constructed of disjointed phrases. All sentences were recorded whole, spoken by a real human.
Some of the stores (in the more-likely-to-be-shoplifted-from areas) have an additional step for every single item. You have to touch it to a yellow panel next to the scanner/scale, so the inventory-control system can note that it's leaving with permission.
All-in-all, it's a good system, unless you have a lot of items. Because you can't be trusted to scan and bag each item quickly without slipping bonus goodies into the bag, you have to go one item at a time. Regular checkout clerks can run huge numbers of items by the scanner much faster, so I go to them if I have a lot to buy. -
RE: Hyper Text Coffee Pot Control Protocol (HTCPCP/1.0)
[quote user="ZeroSum"]
Don't forget 1149: http://www.faqs.org/rfcs/rfc1149.html
[/quote]That one got implemented: http://www.blug.linux.no/rfc1149/ -
RE: Function pointers?
[quote user="makito"]
OK, I have circumvented the problem. I redesigned the GUI so that all boxes are either read only or write only. I should have designed it that way to begin with. I have another question though.
What is the proper usage of the new and delete operators? I understand how they work, but why is
char* PointerToString = new char[10];
any better than,
char ActualString[10];
Thanks for all your help
[/quote]
If the string is expected to live any longer than the scope in which it was declared, then use the new operator. If it is to live only for the life of that scope, and it is not enormous, just allocate it on the stack (the second declaration). Your memory manager will reward you by not destroying your performance through function calls, cache misses, and resource contention on the free list (if you're multi-threaded). Oh, and you'll cut down on fragmentation, too, which would also have led to more cache misses and increased the length of time needed to allocate anything large.
-
RE: Compare RGB values
Assuming SQL; a table with columns red, green, and blue; and input values of r, g, and b...
If you want Euclidian distance:
select red, green, blue from colors order by (red-r)(red-r)+(green-g)(green-g)+(blue-b)*(blue-b) limit 1;
If you want Manhattan distance (extrapolated to three dimensions):
select red, green, blue from colors order by abs(red-r)+abs(green-g)+abs(blue-b) limit 1;
These will, of course, run through the whole table to try to find the answer, but there's not really a decent WHERE clause that would save you any calculation time, especially one that would also guarantee you a nonempty result set.
If you're a real masochist, you can replace the multiplication in the Euclidian distance with pow(red-r, 2) and go through the agony of promotion to float and the time spent for the pow function. -
RE: Fun with casts
[quote user="Tann San"]
[quote user="djork"](and in your case it's only ONE time, probably) the difference would be 0.00006 seconds. Does that really matter? Just suck it up and use casts![/quote]
That snippet comes out of a function that is being used to dynamically resize images pulled out of a db. I'm talking about every single user uploaded image. The framework is being developed this week for 4 companies who will share the site. In Jan it's going to be extended to about 20 companies. They went for the gimmicky "micro-site" idea someone proposed. Each company uploads images for their products, services and corp identity. Instead of using the function at the point of upload it's going to get called each and every time the image is downloaded. I just figured the casting was a wtf as I assumed it would have quite a big performance penalty when used in that context. Guess you showed me otherwise :¬)
[/quote]
That's the sort of system that begs to have some sort of caching built in, to avoid actually resizing the same image repeatedly. If you're generating a bajillion thumbnails, the multiplication and division to determine the dimensions of each thumbnail is trivial compared to the cost of actually generating the thumbnail. If you're just calculating the dimensions so that you can tell the browser to resize the full-size image to thumbnail size, then you're abusing bandwidth.
Best: generate thumbnails at upload
Second best: generate thumbnails the first time they are needed, and delete them when their source images get re-uploaded
Worst: generate thumbnails on every access
-
RE: Binary trees i need a help with making recursive functions non-recursive
While I won't give you the answer since this does look like a homework assignment, I will at least help you go in the right direction.
Search is the easiest one to convert.
Think about the job that function is supposed to do: it starts at the top of the tree and works its way down until it either finds a matching node or determines that the node isn't there.
Look at the wording of that sentence. You're doing something until one of two conditions is met. That often lends itself well to a while loop. In this case, while you have a current node to look at, and it's not the one you're looking for, you advance your current node to either its left child or its right child, depending on how its Element compares to the one you were given in the function call. At any time that your current node is NULL, you know you didn't find what you were looking for, and you return false.
Assuming you get out of the loop and your current node isn't NULL, you found what you were looking for, and you can return true.
All that being said, the design of the Search function is a little light on capability, as it will only tell you whether something is in the tree. If your Type is complex enough to have several fields that don't participate in the comparison operators, you have no way to get to it, because the function returns only a bool and doesn't ever give the caller any kind of reference to the node that was found. If it's really going to do that little (and not change any of the nodes you travel through or look for), then the treenode that's passed into the top of it should be const.
The code for Insert is only a little bit more complicated than Search.
The one that's a real pain is the traversal. There's no easy way to go through the whole tree in order without recursion.
If I really needed to work my way through a whole tree in order like that, I'd probably at least do data recursion, if not code recursion, or else I would use a different data structure. A simple binary tree is built for searching, not for iterating through the whole thing in order. Always choose the right tool for the job. -
RE: Redesigning Paste
[quote user="db2"]Man, I bet Edgar's face would melt if he ever accidentally hit Ctrl-K, Ctrl-D. Ha ha. (This is a keystroke I love, by the way, even if it does make horrible messes of HTML tags.)
[/quote]
For those of us who are old enough to have worked with Wordstar-compatible editors, that's how you save and quit. The real keystrokes from Wordstar are Ctrl-K, D. But some editors also took Ctrl-K, Ctrl-D. -
RE: A Shipment Confirmation when item discontinued
I'm going to go ahead and make a couple assumptions here.
The first assumption I'll make is that you can order more than one item number in a single order.
The second is slightly less probable than the first, but still considerably higher than fifty percent. That assumption is that they might actually send you a different email if everything you ordered was discontinued and no longer available. Such a system would not be unreasonable to encounter.
Until you have a "Shipment Confirmation" email with no items shipped, you really can't rule out the second assumption. -
RE: EXtreme Programming.. ..controversy
This answer's late, but worth the read...
[url="http://www.softwarereality.com/lifecycle/xp/safety_net.jsp"]http://www.softwarereality.com/lifecycle/xp/safety_net.jsp[/url] -
RE: What's the difference between an MP3 player and a HD?
[quote user="RayS"][quote user="Isuwen"]
"The difference between a walrus and Jupiter is that a walrus has two eyes and whiskers. Which concludes that it is not a planet."
But jupiter has an eye. If it had whiskers, would it be a walrus?
[/quote]
Considering that these things are apparently that simple (an MP3 player is a hard drive with a battery and a screen), I don't see why not.
[/quote]Earth has many eyes and whiskers. It too is a planet, I hope. -
RE: Python 2.5 WTF
[quote user="merreborn"]
The performance benefit of that optimization is potentially pretty low. In the provided example, we're talking about a savings of 1 integer operation.
Python is a high level language. Performance is not the highest priority.
[/quote]
One integer operation, plus the overhead of dereferencing two Python integer objects to get the operands for that integer operation, plus creating a new Python integer object (if the number is less than 0 or greater than 100) or of incrementing a reference count on an existing one (if the number is from 0 through 100).
True, the improvement is likely negligible considering the sheer volume of object dereferencing and reference count inc/decrementing going on throughout the rest of your script, but it's still nice to have it.
-
RE: When designing a website for a religious cult...
[quote user="jesirose"][quote user="R.Flowers"]
Yes, it was a misinterpretation. But consider this:
Let's have the meeting next Friday.
Now if this is Wednesday, will the meeting be in 2 days, or 9 days?
[/quote]
I hate that! I always take it to mean the next time that it is Friday, but I know a bunch of people think that means the Friday after the next one. WTF.
[/quote]
"This Friday" is the one that happens this week (defined as seven consecutive days, beginning with Sunday).
"Next Friday" is the one that happens next week.
"Last Friday" is the one that happened last week.