Wikipedia:Reference desk/Archives/Computing/2010 January 4

Computing desk
< January 3 << Dec | January | Feb >> January 5 >
Welcome to the Wikipedia Computing Reference Desk Archives
The page you are currently viewing is an archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages.


January 4

edit

Vista Sidebar Gadgets in WIndows 7

edit

I used to have some note gadgets in my Vista Sidebar with, what else, notes. Now that I can't run the sidebar in Windows 7, is there a way to import the gadgets or at the very least, run sidebar so I can copy the info? --142.151.182.176 (talk) 05:50, 4 January 2010 (UTC)[reply]


There is no sidebar as such anymore, but the widgets that went in the sidebar are now part of Gadgets, which are similar except can be placed anywhere instead of just to the side of the screen. If you right click your desktop and click Gadgets you should get a screen that lists gadgets, and any sidebar gadgets you have SHOULD appear there if you did an upgrade install, and if not they will work if you download and install them again. Gunrun (talk) 09:35, 4 January 2010 (UTC)[reply]

USB headphone

edit

Are there any reliable USB Headphones ?--yousaf465' 09:29, 4 January 2010 (UTC)[reply]

Why not try Googling around to see if you can find some suitable products. I'm sure there's at least one site somewhere on the web that sells them, or a site with reviews of them. It dosen't really take that much work on Google to find answers. Chevymontecarlo (talk) 14:08, 4 January 2010 (UTC)[reply]

You can also get a small USB audio adapter[1][2][3][4] and plug headphones into it. These might be a better solution, as you can choose the headphones you want to use. —Preceding unsigned comment added by 193.172.19.20 (talk) 17:59, 6 January 2010 (UTC)[reply]

HDTV resolutions

edit

It boggles my mind: why do flat panel TVs come in 1366x768 and worse yet 1024x768. The first one is probably no better than native 720p displays even if the video source has more resolution than 720p due to the quality/sharpness lost in interpolating. The second one is even worse because it has to also interpolate for the non-square pixels. Are there any real advantages to these resolutions over the two native HD resolutions (720p and 1080p)? And also, is the interpolation done hardware or software based? Is it simple nearest neighbour (which produces poor results) or something more advanced, like bicubic or Lanczos3 (which is very computationaly intensive for HD video in real time)? Roberto75780 (talk) 09:59, 4 January 2010 (UTC)[reply]

my understanding is that most TVs the same size as common computer monitors use the same LCD panels as computer monitors. These panels do not have 720 vertical pixels or 1080 vertical pixels but usually have 768 and 1050 pixels along the vertical edge. When you move to larger TV display sizes, you will find native HD resolutions with 720 and 1080 pixels. The non-native resolution isn't ideal for the picture, but those panels are cheaper as they are produced in larger numbers and allow for less expensive smaller TVs. 206.131.39.6 (talk) 18:19, 4 January 2010 (UTC)[reply]

Ghost images

edit

Hello. I've heard of a phenomenon where prolonged still images (paused videos or games) can cause the image to leave a "ghost" image on the television or monitor. I'd like to know what causes this, what types of monitors may be affected and whether there is a way to remove the ghost. Thanks in advance! 88.112.62.154 (talk) 11:40, 4 January 2010 (UTC)[reply]

This effect is known as Screen burn-in - that article should answer your question. :) Ale_Jrb2010! 12:05, 4 January 2010 (UTC)[reply]
Thank you! 88.112.62.154 (talk) 13:48, 4 January 2010 (UTC)[reply]

Makefile

edit

Suppose I have images files in a directory called fullsize and want to put thumbnail versions of them in the directory thumbs. I could use a makefile like this:

thumbs/image1.jpg : fullsize/image1.jpg
    createthumb fullsize/image1.jpg thumbs/image1.jpg

thumbs/image2.png : fullsize/image2.png
    createthumb fullsize/image2.png thumbs/image2.png

However, this requires that I know in advance what images will be in fullsize and even if I do, such a makefile is cumbersome to write if there are many images. What would a makefile look like that would take every image in fullsize and create a thumbnail of it in thumbs if it's not already there and up-to-date? I'm using GNU Make. Thanks! —Bromskloss (talk) 12:00, 4 January 2010 (UTC)[reply]

You probably want a make pattern rule. Here is the appropriate section in the manual. An example make file may look like:
 thumbs/%.jpg: fullsize/%.jpg
    createthumb $< $@

 thumbs/%.png: fullsize/%.png
    createthumb $< $@
Note that you need to appropriately replace regular spaces with tabs for whitespace in order to be a properly formatted Makefile. Also note that the $< symbol refers to the first prerequisite file, and $@ refers to the output. These are called Automatic Variables, and are documented here: GNU make Automatic Variables. Nimur (talk) 12:16, 4 January 2010 (UTC)[reply]
Thanks for answering. Unfortunately, it (GNU Make 3.81) only tells me "make: *** No targets. Stop." when I run your example. Is there anything else I need to specify in the makefile? —(I'm the original poster. Just unable to log in.) 130.237.3.196 (talk) 13:17, 4 January 2010 (UTC)[reply]
Try make thumbs/image1.png. At first I had hoped that make thumbs/*.png would make everything, but unfortunately this will probably not work. There's a work-around, (I have done this sort of thing before, but I can't remember how). I'll check my Gnu Make cheat-sheet when I get into my office later today and see if I can find out what is needed to process everything in your source directory and output everything. In the meantime, you can manually create a make rule that depends on all the expected outputs (thumbnails), e.g. adding this rule to the above makefile:
buildthumbs: thumbs/image1.png thumbs/image2.png thumbs/image3.jpg
Now when you make buildthumbs, you will auto-build all those resources according to the patterned rule. This is only slightly better than a separate rule for every single image - as I said, there's a workaround to auto-detect the prerequisites. Nimur (talk) 14:52, 4 January 2010 (UTC)[reply]
This will build a thumb for everything in fullsize/ automagically:
buildthumbs: $(shell ls fullsize/*.{jpg,png} | sed s/fullsize/thumbs/)
--Sean 15:14, 4 January 2010 (UTC)[reply]
That works as well as anything I've got. Nimur (talk) 19:25, 4 January 2010 (UTC)[reply]
You can avoid using the shell, although it doesn't improve the handling of file names with spaces: $(patsubst fullsize/%,thumbs/%,$(wildcard fullsize/*.jpg) $(wildcard fullsize/*.png)). --Tardis (talk) 23:08, 4 January 2010 (UTC)[reply]
The best answer to the spaces-in-filenames issue is almost always "don't do that". --Sean 16:51, 5 January 2010 (UTC)[reply]

Thanks everyone. I ended up generating targets by a call to ls as suggested here. I was hoping that Make could be driven by the existence of source files rather than targets, but that doesn't seem to be the case. —Bromskloss (talk) 12:06, 10 January 2010 (UTC)[reply]

Animals chewing through ethernet cable

edit

I installed quite a long stretch (25m) of cat5e cable outside the house to get to my dad's office in a separate building. Unfortunately, some animals (probably foxes) have recently decided to complement their diet with my STP wires. Is it worth trying to repair the wires somehow? If I have to re-lay the whole thing, are there certain types of wire that will stand up to this damage better? How can I stop this happening again? I hate animals... Anand(talk) 12:05, 4 January 2010 (UTC)[reply]

  • Yes. If you have a pair of wire strippers (plier or scissor may do) you can match the conductors inside with the coresponding ones on the other broken end and connecth them together. You should sandpaper the wire tips and make sure you get a solid connection for every conductor or else the speed may suffer. The foxes may like your cable but I don't think they would dig it out from underground, or even under a carpet. If you want to replace the cable and the pests are still getting to it, try threading it through a garden hose. Roberto75780 (talk) 12:17, 4 January 2010 (UTC)[reply]
Or you can buy commercial electrical conduit, which may be cheaper than a garden hose. Nimur (talk) 12:19, 4 January 2010 (UTC)[reply]
We used a goopy gunk we called "Gorilla Snot" to coat outside wires when I was in the Marines. It was designed to keep animals from chewing the wires. -- kainaw 14:40, 4 January 2010 (UTC)[reply]
I've been advised to wash my hands before laying wires and cables outside, in order to keep them from smelling edible. I'm not sure how effective that is. --Allen (talk) 18:26, 5 January 2010 (UTC)[reply]
Such a join will probably fail the cat5e criteria, but I doubt that you would care since it will probably work. You may also get UV deterioration in the longer term if you don't bury it. Graeme Bartlett (talk) 23:23, 4 January 2010 (UTC)[reply]
If your joint is in damp conditions, you will get corrosion at the joins, but this post is being made via a cut and joined ethernet cable with the joint outside in a very damp place, and it has been no problem for the last 12 months, though I did solder it and tape round well. As Graeme Bartlett mentioned, I'm probably losing speed, but my connection is not very fast anyway. Dbfirs 09:00, 5 January 2010 (UTC)[reply]
When we built my brother-in-law's office at the end of his garden, we laid 50 m of ethernet and phone cable in a plastic water pipe and buried it about 25 - 50 cm underground. At each end, we made sure the cables were not exposed by ensuring the pipe came inside the building. There has been no damage in 3 or more years; but if there ever was damage, it would be a nightmare to replace. Astronaut (talk) 14:09, 5 January 2010 (UTC)[reply]
If your repair efforts are futile, there is a newfangled technique to running a network connection that is 100% impervious to animals, UV, and water. See this for more information. It's also cost effective compared to just about every construction technique (aside from, perhaps, the 'shove it under the carpet' method). --Jmeden2000 (talk) 19:52, 5 January 2010 (UTC)[reply]

Software to overlap two images?

edit

I have four or five jpg images of parts of a plan that I want to partialy overlap to create a bigger image, preferably while preserving the scale of the originals. Is there any software than can do this easily please? I have searched for quite a while but not been able to find any myself. 84.13.28.161 (talk) 16:36, 4 January 2010 (UTC)[reply]

  • Pretty much any half-decent image editing program should be fine for this. The process in GIMP is: create a new blank image (big enough to contain your final image), then drag each constituent image onto the master image, and move it to where you want with the move tool. If you need to change the stacking (z order) use the layers dialog; once you're done, just save the final image (as a flat image like a PNG or JPG, as appropriate). The process is much the same in Photoshop, and isn't very different in vector programs like Inkscape and Illustrator too. -- Finlay McWalterTalk 16:43, 4 January 2010 (UTC)[reply]
  • What you are looking for is Image stitching. Our article is not the greatest, but you should be able to find something by googling the term. Autostitch may be a useful ink and product. However, I suspect most of these programs assume typical photos with a lot of details - I don't know how well they will cope with line drawings. --Stephan Schulz (talk) 16:48, 4 January 2010 (UTC)[reply]

Software to give x.y coordinates of points within an image?

edit

I'd like to be able to do something like this: I position the cursor at a particular point in an image. I press something, and the xy coordinate gets appended to a text file. I move the cursor to another point and repeat. Is there any software that can do this easily please? I have looked for some but have not been able to find any. Thanks. 84.13.28.161 (talk) 16:42, 4 January 2010 (UTC)[reply]

I wrote one for you:
#!/usr/bin/python

import pygame, sys
pygame.init()

if len(sys.argv) != 2:
    print 'usage: clicker.py foo.jpg'
    sys.exit(1)

img = pygame.image.load(sys.argv[1])
screen = pygame.display.set_mode((img.get_width(), img.get_height()))

screen.blit(img,(0,0))
pygame.display.update()

while True:
    event = pygame.event.wait()
    if event.type == pygame.QUIT: break
    if event.type == pygame.MOUSEBUTTONDOWN and event.button==1:
        print event.pos
You'll need to install Python (programming language) and Pygame. Run it with python clicker.py foo.jpg where clicker.py is the above script, and foo.jpg is whatever image you want. It prints (x,y) coordinates to the standard output (which you can redirect to a file if you want). -- Finlay McWalterTalk 17:30, 4 January 2010 (UTC)[reply]
MATLAB can do this with the ginput command. It can also read and display images in many formats. Nimur (talk) 18:21, 4 January 2010 (UTC)[reply]

Thanks, especially thanks for the code. I've also found some freeware that does this: Plot Digitizer 2.4.1, Enguage Digitizer, and Digitize 2004. There may be more. 92.24.115.153 (talk) 22:37, 5 January 2010 (UTC)[reply]

Segfault in C relating to null string

edit

In a C program, I have a string "line", read from the user with a simple readLine function that I got out of a textbook. So if the user just hits RETURN, then I figure line[0] should be '\n'. And usually that's true. But sometimes, if I fail to initialize certain integers stored in the addresses just before line, AND depending on whether certain other functions in the program have run, something happens that I don't understand:

printf("%d\n",line[0]);

prints "0", as expected. But

printf("%d",line[0]);

(without the newline) results in a segmentation fault. So does

sscanf(line,"%d",&i);

which is my actual goal.

I can fix the problem by initializing my variables, but I want to understand: how could uninitialized variables cause this problem? And what could possibly be stored at line[0] such that it looks like a 0 when printed before a newline, and causes a segfault otherwise?

Thanks! --Allen (talk) 21:18, 4 January 2010 (UTC)[reply]

It's really difficult to understand problems with fragments of C code when we can't see the whole program, and in particular how variables have been declared. If you can show minimum C programs that illustrate the problem (which, for the stuff you're talking about, shouldn't need to be more than half a dozen lines) then we can help. But right now you're asking us to diagnose memory corruption issues but not showing us how the variables that name that memory are defined. -- Finlay McWalterTalk 21:24, 4 January 2010 (UTC)[reply]
I'll take a guess, anyway. line is a pointer (it looks like an array, but really it's a pointer). If line (and I mean line, not line[0]) hasn't been initialised then dereferencing it (which is what line[0] does) will mean examining some unknown (and very often illegal) chunk of memory. Remember that by changing your printf you're reorganising your .text (and perhaps .data) segments, moving things around such that you get a different result. But the underlying problem is that line itself is bad. -- Finlay McWalterTalk 21:33, 4 January 2010 (UTC)[reply]
Agreed with everything above. It segfaults because line is an invalid pointer and by bad (good) luck it might point to an invalid address, but it's quite impossible to fix a problem with your code without seeing it. Enabling and fixing compiler warnings could help if you haven't already. --91.145.72.65 (talk) 21:49, 4 January 2010 (UTC)[reply]
[edit conflict] Thank you. I understand what you're saying, and if I'm able to duplicate the problem with a minimal C program, I'll post it. But right now, the segfault conditions seem to depend on so many other parts of the program I doubt I'll be able to. But that's okay; after all, I know how to fix the problem (by initializing those integers)... I'm just wishing I could understand what's going on. Thanks for the tip about how changing printf reorganizes things. (FWIW, initializing line itself doesn't help; only initializing those integers stored before it.) --Allen (talk) 21:55, 4 January 2010 (UTC)[reply]
I would expect that the reason initialising the integers "fixes" the problem is that C compilers typically store variables one after the other in memory - so if you initialise one, then the next is probably the next memory space. Your string pointer (line) is probably writing over the integers and if they're not initialised then it's hitting uninitialised memory and barfing. You really need to initialise where line is pointing, rather than worrying why it occasionally works by chance. --Phil Holmes (talk) 10:31, 5 January 2010 (UTC)[reply]
Then 91.145.72.65's advice is the thing to do - turn on all compiler warnings, and don't proceed with debugging until all the warnings you're getting are resolved. This won't fix all memory corruption and bad pointer issues, but given C's laissez-faire willingness to compile programs that are objectively bonkers, debugging a program with warnings is wasting your time. -- Finlay McWalterTalk 22:01, 4 January 2010 (UTC)[reply]
And if line is okay at one point, but bad later, then you may have stack corruption. line is (probably) stored on the call stack, adjacent(ish) to other automatic variables in the same block (function). If code addressing one of them mangles the stack, it can overrun into the storage of line, corrupting it. When you later dereference line, you get a bad result. -- Finlay McWalterTalk 22:04, 4 January 2010 (UTC)[reply]
One possible problem is that "%d" in printf (and scanf) expects and int (which will be at least two bytes, probably four), whereas a string is an array of, or pointer to, char (normally one byte). It is possible that the compiler pushes only one byte onto the stack (line[0]) but the printf function tries to read sizeof(int) bytes from the stack and there just aren't that many there to read, so it tries to read beyond the stack, creating a segmentation fault. (Some compilers will issue warnings if printf format and arguments don't match.) This would probably fix the problem:
printf("%d",(int)line[0]);
I don't generally like using type casts - they are the programmer's way of telling the compiler "I'm doing something wrong but I don't want to be warned about it." So this would be better:
int i = line[0]; /* implicit promotion from char to int, no cast required */
printf("%d", i);
I would expect your sscanf to return EOF if line is an empty string. According to K&R2 appendix B1.3, "fscanf returns EOF if end of file or an error occurs before any conversion; otherwise it returns the number of input items converted and assigned", and sscanf is equivalent except that the input characters are taken from the string. The only reason that I can see why sscanf might fail is if i is not an integer, and line actually contains (a text representation of) a number, not an empty string. Eg if i is a char (1 byte), sscanf will try to write an int (eg 4 bytes) to it, which may corrupt your stack. Mitch Ames (talk) 01:22, 5 January 2010 (UTC)[reply]
All arguments to variadic functions beyond the declared parameters (as well as all those to functions with no prototype) are promoted at least to int or double ("at least" because of unsigned int, long int, pointer types, and so on). There is no trouble using %d to format a char argument.
sscanf() will of course return EOF if !*line, but if !line (or it is otherwise invalid) there will be trouble! That case can't happen if line is an automatic or static array, since its address is not data and can't be damaged by stack corruption or so. It's possible, in theory, that an sscanf(...,"%d",...) would read so far off the end of a valid array that it got a segfault, but it seems unlikely that it would encounter neither a 0 nor something it could (or couldn't!) convert to an int along the way. It'd have to be all whitespace, basically, to the end of the page at least. --Tardis (talk) 03:48, 5 January 2010 (UTC)[reply]
Can you provide a reference for your statement that "all arguments to variadic functions ... are promoted at least to int or double"? I know that most (but not necessarily all) compilers will push at least sizeof(int) bytes onto the stack, but that's because it typically generates more efficient/faster code. (This is similar to alignment of an int after a single char in a struct for example.) However:
1) I don't believe the language actually requires it, so one shouldn't depend on it. Eg an compiler for an 8-bit processor, with a 16-bit int to meet minimum ANSI requirements, probably would not. (Don't laugh, I have recently worked with such a compiler.)
2) The extra bytes pushed are not necessarily initialised, ie there isn't any promotion, so if a char is pushed by the caller and an int is read by the function, the value will be undefined.
Mitch Ames (talk) 05:20, 6 January 2010 (UTC)[reply]
This can be inferred from 6.5.2.2p6 "If the expression that denotes the called function has a type that does not include a prototype, the integer promotions are performed on each argument, and arguments that have type float are promoted to double. These are called the default argument promotions." and 6.5.2.2p7 "The ellipsis notation in a function prototype declarator causes argument type conversion to stop after the last declared parameter. The default argument promotions are performed on trailing arguments." The integer promotion applies to types whose range of values can be represented in an int or unsigned int, and so does not apply to e.g unsigned long, as mentioned by Tardis. decltype (talk) 06:43, 6 January 2010 (UTC)[reply]
OK, thanks - I learn something new every day! Incidentally, what book/standard/website etc are you citing here? And is it freely available? I did find the equivalent wording in K&R2 Appendix A7.3.2 Function Calls, but it never hurts to have an extra reference source when I can get them. Mitch Ames (talk) 09:09, 6 January 2010 (UTC)[reply]
The ISO/IEC C language standard. It is not freely available, but the standard drafts are. The most recent draft of the revised C99 standard can be downloaded from http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1336.pdf. I expect it to contain only very minor editorial differences from the actual standard (and its Technical Corrigendums), at least this is the case for C++. decltype (talk) 09:28, 6 January 2010 (UTC)[reply]
Thanks. Mitch Ames (talk) 01:29, 7 January 2010 (UTC)[reply]
Of course, I misspoke slightly: it is only the arguments that actually correspond to the ellipsis (the "variadic arguments" if you will) that undergo such promotion. I knew that, but so often variadic functions just take a pointer or two before their ellipsis that I didn't think about it at all. Thanks for making it precise; I've amended my statement to be completely accurate. --Tardis (talk) 16:05, 6 January 2010 (UTC)[reply]
If this is for a real program, I don't think you'll be doing yourself any favors by papering over the symptoms without understanding the bug. It's generally worth the effort to understand it fully so you know it's really fixed, so you can scan the rest of your code for the same bug, and so that you can grow as a programmer. --Sean 16:23, 5 January 2010 (UTC)[reply]
My thoughts exactly, Sean; I knew that initializing my variables fixed the bug; I just didn't understand why. And thanks everyone for the suggestions. Here's what I think my problem has been: I've been assuming that the program would be stepping through the code line by line, so if it's giving me a segfault before a given line is executed (i.e., a debugging printf), then nothing after that line could possibly be my problem. But I suppose with a compiled program, I have no such assurances. I found a conditional later in my function that would very understandably cause a segfault, and my segfault goes away when I fix it. So somehow the program must be compiled such that this conditional is checked before some perfectly legal printfs above it are executed. Is this plausible? I hope so, even though it will mean I'll have to re-learn how to debug programs. --Allen (talk) 17:52, 5 January 2010 (UTC)[reply]
printf debugging for cases like this can be problematic. printf writes to the stout, which is buffered; at the least you need to fflush() stdout after each printf (otherwise a printf has occurred, but you've not seen it yet). It's much more productive to debug under a source debugger like gdb or the visual c++ debugger. This will halt the program right at the segfault, and will retain the program state so you can go back and inspect variables to see how you got into this mess. -- Finlay McWalterTalk 17:57, 5 January 2010 (UTC)[reply]
Note that stdout is usually not buffered if it's the terminal. --Sean 15:16, 6 January 2010 (UTC)[reply]
and (it may seem like nitpicking but it really isn't) initialising the adjacent variables didn't fix the bug, it hid the bug. The bug isn't the segfault - that's a welcome symptom of it. You'll come to (reluctantly) like segfaults, because many memory corruption bugs leave the program running but with the data scrambled. -- Finlay McWalterTalk 18:03, 5 January 2010 (UTC)[reply]
Excellent; thank you again. The fflush(stdout) did indeed reveal that the printfs were being executed and I just hadn't seen them yet. The buffering hadn't occurred to me. I'll work on learning gdb. --Allen (talk) 18:13, 5 January 2010 (UTC)[reply]
Valgrind is also excellent for finding invalid memory accesses. --Sean 15:16, 6 January 2010 (UTC)[reply]

Restricted characters in Wiki URLs

edit

Is there a list of restricted characters that cannot be used in a wikipedia URL. For example, going to United States takes you to .../United_States and going to 100% takes you to .../100%25

The %25 is the ascii code for %. So the replace for space is an underscore, but for some characters is a hex, and for others is the literal. I would like to find a comprehensive listing of these. Anyone know where that is? PvsKllKsVp (talk) 23:09, 4 January 2010 (UTC)[reply]

Mediawiki changes ascii 0x20 spaces to underscores (as spaces are so common in article names). Non ascii characters are encoded in UTF (UTF-8, I think). Apart from that it just does the standard URI encoding per the relevant RFC. -- Finlay McWalterTalk 23:27, 4 January 2010 (UTC)[reply]
Thanks. That's perfect. MediaWiki respects the RFC, but doesn't implement it fully. For instance, commas, colons, semicolons, parenthesis and other punctuation is permitted in MediaWiki but not in the RFC. PvsKllKsVp (talk) 00:25, 5 January 2010 (UTC)[reply]