Wikipedia:Reference desk/Archives/Computing/2010 October 1

= October 1 =

Long delay after first right click
The first time I right click something after initial booting up, the big hour glass comes up and it takes a looooong time for the menu to drop down--as much as 3 minutes. After that first right click everything is back to normal; the menu drops down immediately. What causes this delay?

I use XP.

Thanks,

Norm Strong —Preceding unsigned comment added by 71.231.141.223 (talk) 04:03, 1 October 2010 (UTC)


 * If it's the first right-click on the desktop or a file-explorer window, then I'd suspect a Shell Extension is being loaded. These are programs that add items to the context (right-click) menu of explorer. Explorer also provides the desktop (and the taskbar). However, I'm not sure about that best way to temporarily disabling an program from the menu, to help track down what is causing it. Have you installed a program recently? —Preceding unsigned comment added by Csmiller (talk • contribs) 06:05, 1 October 2010 (UTC)


 * I would be cautious; it could be malware infecting a shell extension, and was probably installed recently. Run virus scans, check for malware with a malwate scanner like Malwarebytes' Anti-Malware and maybe run Autoruns to check what is loaded at startup.  Astronaut (talk) 07:22, 1 October 2010 (UTC)
 * I have seen this happen due to bad drive mappings causing all sorts of incredible slowness including when using the rightclick menu anywhere in the system. If you have any drives mapped try removing them and see if it speeds up.  The other big culprit I have had do this is WinZip (or similar file archive tools) that use shell extensions for all files; if the program is misbehaving (not uncommon for WinZip) it can cause slowness.  I once had it fail so bad that every right click caused the WinZip installer to try to start up, which took a fair bit of time and eventually exited with an error message.  I had to manually delete all the references from the hard drive and registry before it would go away.  Now, I use 7-zip and while slower to do file operations the shell integration works without issue. --144.191.148.3 (talk) 14:41, 1 October 2010 (UTC)

Spanish Accents
Right, this is going to be a tester. To get Spanish accents I usually hold down Ctrl and Alt at the the time, and while holding them I press the vowel of my choice. That results in á, é, í, ó and ú. I get ñ by holding down Alt and typing 0241 on the number pad. That's all well and good when I'm using a QWERTY keyboard and Windows. I'm in France at the moment and am using an AZERTY keyboard and Ubuntu. The Ctrl + Alt method doesn't work and nor does Ctrl + 0241. Does any one have any idea - except for cutting and pasting - how to get these accents? — Fly by Night  ( talk )  08:01, 1 October 2010 (UTC)
 * See our Compose key page. Basically, press Shift+AltGr (press AltGr last, release first), release both keys, press and release ', press and release the vowel. CS Miller (talk) 08:06, 1 October 2010 (UTC)
 * I've just tried that and I got 'e as the output. I did the following:
 * Press and hold Shift
 * Press and hold Alt Gr
 * Release Alt Gr
 * Release Shift
 * Press '
 * Press e
 * Are you sure it works on Ubuntu? — Fly by Night  ( talk )  08:18, 1 October 2010 (UTC)
 * Odd. It works for QWERTY keyboards on Ubuntu, but not on AZERTY. Apologies. CS Miller (talk) 08:37, 1 October 2010 (UTC)
 * Add a keyboard layout (System --> Preferences --> Keyboard --> Layouts --> Add). Then click on Layout Options --> Layout switching to create a keyboard shortcut for changing layouts. This is also the better way to type Spanish words in Windows, by the way. In Windows, I created keyboard shortcuts for switching to Spanish, Greek, and Russian keyboards by going to Start --> Control Panel --> Regional and Language Options --> Languages -> Details... --> Add.... The semicolon key types an N with a tilde. The left-bracket key adds an accute accent to any vowel you type afterward.--Best Dog Ever (talk) 08:32, 1 October 2010 (UTC)


 * Great, thanks for that! — Fly by Night  ( talk )  09:13, 1 October 2010 (UTC)


 * If you use an international layout, you can use dead keys, which is going to be the least painful way (no layout switching required). ¦ Reisio (talk) 18:49, 3 October 2010 (UTC)


 * I always use charmap instead of key combinations. Comet Tuttle (talk) 16:29, 1 October 2010 (UTC)
 * But Ubuntu is a Linux based operating system and doesn't have anything to do with MS Windows. — Fly by Night  ( talk )  19:59, 1 October 2010 (UTC)


 * in Ubuntu, hold alt gr, then press #. Release both keys then press a.  Do you get à? For me, ñ is alt gr and ], then n, and I can get most accented characters simlarly. 129.67.37.143 (talk) 22:36, 1 October 2010 (UTC)

Recursively Search a Directory to Find and Replace Contents of Files Using the Command Line
I'm trying to write a small shell script on OS X that will recursively search through a directory and replace all the instances of 'foo' in files with 'bar'. I assume that grep and sed are the best way to do this, but I can't quite figure out the syntax to make them work together.

Thanks for any help. -- CGPGrey  (talk)  08:20, 1 October 2010 (UTC)


 * grep -rl foo . | xargs sed -i backup s/foo/bar/ This will also create backups of the files it modifies (the original filename, plus a .backup extension) —Obeattie (talk) 12:42, 1 October 2010 (UTC)


 * Thanks for that, unfortunately, I'm on OS X, which does not allow the use of the -i switch. Is there another way?  -- CGPGrey   (talk)  13:10, 1 October 2010 (UTC)


 * I too am on OS X, which seems to allow -i, I just tried it. What OS version are you using? —Obeattie (talk) 13:16, 1 October 2010 (UTC)


 * Perhaps you have installed the GNU utilities? This page says GNU sed supports -i but that the BSD one that ships with OS-X does not. -- Finlay McWalter ☻ Talk 13:27, 1 October 2010 (UTC)


 * Anyway, this isn't quite so nice, but it can be done faily easily just using a for loop. This removes the dependency on the -i flag:
 * for f in $(grep -rl foo .); do mv $f $f.backup; sed s/foo/bar/ $f.backup >| $f; done
 * —Obeattie (talk) 13:24, 1 October 2010 (UTC)
 * This looks to be getting me the closest, but I'm getting a ton of 'no such file or directory' errors when I run it and it produces lots of empty files in the directory that I run it from. Perhaps it's because I have spaces in the names of my folders and files?  -- CGPGrey   (talk)  15:05, 1 October 2010 (UTC)
 * Yes, that's the reason. I would respectfully suggest that if you are planning to perform more scripting jobs like this, you rethink the naming conventions of your files so that they do not involve spaces. As you can see, it is nothing but a constant source of headaches. You can try
 * grep -rl foo . | while read f; do mv "$f" "$f.backup"; sed s/foo/bar/ "$f.backup" > "$f"; done
 * (inspired by Tardis' answer to your previous question).—Emil J. 16:08, 1 October 2010 (UTC)
 * Actually, there is one more subtle problem: all the sed commands above will fail to work properly if there are more occurrences of foo on the same line. You should use .—Emil J. 16:25, 1 October 2010 (UTC)
 * (e/c) This suggests an explicit -e might fix it: .—Emil J. 13:26, 1 October 2010 (UTC)
 * I find it preferable to just backup the whole directory tree, rather than individual files. Then you don't have to write another script to restore things back to the way they were. --Sean 14:22, 1 October 2010 (UTC)


 * "A programmer had a problem and decided to work on it by using regular expressions. Then the programmer had two problems."  Comet Tuttle (talk) 18:57, 1 October 2010 (UTC)


 * Regular expressions are the crack of programming. Shadowjams (talk) 20:21, 2 October 2010 (UTC)

Avoiding Javascript timeouts.
I have a complicated JavaScript program and in Firefox, I get a popup that says: "A script on this page may be busy, or it may have stopped responding. You can stop the script now, or you can continue to see if the script will complete." I know you can have users set: dom.max_script_run_time to make this timeout longer - but this is for general use. I'm putting a 'progress meter' into the script so people can tell when it's going to finish.

Does anyone know what criteria Firefox is using to calculate this timeout? Is there something I could do in my script to reset the timer periodically? (eg Is it enough to stop running - but with a timerevent set that would set things running again a few milliseconds later?) 70.112.128.105 (talk) 17:37, 1 October 2010 (UTC)


 * Every so often (say every N loops around your main loop) you a) schedule a timer event (setTimeout) to call yourself, and then b) call yield -- Finlay McWalter ☻ Talk 17:45, 1 October 2010 (UTC)


 * To phrase it another way: Redesign your algorithm so it does a little work and then goes to sleep. Put the work done in a function.  If the function finishes and there is more work to do, use the setTimeout to call the function again.  This way, the web browser will see each function call as a separate script running and not one never-ending script. --  k a i n a w &trade; 19:22, 1 October 2010 (UTC)


 * Actually you don't need (js1.7) keyword (my bad, not a function) yield; you just store state in a global variable and return. Here's a simple example that calculates fibonacci numbers without jamming the processor for too long.  The key is that it only goes through its main loop itercount times before yielding back to the main event loop (in practice itercount would be a much larger value, probably tens or hundreds of thousands).


 * This is a slightly poor example, as we overflow ints long before running into the timeout problem. Can someone think of a very simple algorithm that we can use instead of fib, that will take a modern computer a few tens of seconds to do, and that won't require bignums or too much code? -- Finlay McWalter ☻ Talk 19:48, 1 October 2010 (UTC)
 * Thanks! I get the idea. 70.112.128.105 (talk) 00:32, 2 October 2010 (UTC)

VLOOKUP in Excel
I'm working with Excel 2007 (on Windows Server 2003, if that matters...). I'm performing a series of VLOOKUP functions using a formula like this: =VLOOKUP($A3,mattd!$A:$U,16,FALSE) Nothing too unusual there and it works just fine as it's written. What I would like to do is, instead of typing in "mattd" there (the title of one of the worksheets), I'd prefer to lookup that name in a cell. For example, if cell A1 was "mattd" =VLOOKUP($A3,A1!$A:$U,16,FALSE) would lookup the relevant data on the mattd worksheet and if cell A1 was "barts", that same formula would look up the relevant data on the barts worksheet. When I do that, though, Excel is not expecting it and opens a search for another file to look in. Is there a way I can make Excel read the text of a cell and treat it as part of a formula in this way? Matt Deres (talk) 18:10, 1 October 2010 (UTC)


 * You need the INDIRECT function: VLOOKUP($A3,INDIRECT(A1&"!$A:$U"),16,FALSE), or with A$1 if you intend to copy the formula down the sheet. Bear in mind that as this is an indirect reference, the link will break if you move the lookup table away from the $A:$U range. AspidistraBaby (talk) 19:19, 1 October 2010 (UTC)


 * Great! That's exactly what I need. Thanks very much! Matt Deres (talk) 20:10, 1 October 2010 (UTC)

Third and fourth hardware questions
This question is slightly related to the two questions I asked above. I switched from the Asus motherboard that I planned to purchase to this one from ASRock. The only problem is that the computer has two PATA/IDE devices -- a hard drive and CD/DVD drive -- and only one port. Yet everything I've read said the one port supports two devices, but nowhere can I find something that tells me how I can plug two devices into the one port. Any suggestions? I thought of ignoring this and buying a $10 IDE-to-SATA bridge. If I did that, would I need to buy an extra length of SATA cable? Please excuse my n00biness, Xenon54 (talk) 23:41, 1 October 2010 (UTC)


 * All PATA ports support two PATA devices. Make sure you get a PATA cable with three connectors (one for motherboard, one each for the two devices). Typically you use jumpers on the devices to designate one "master" and one "slave" (you can often just use cable select, but some older devices don't do this properly). Plug em in, power up, make the BIOS search for them, then you'd done. -- Finlay McWalter ☻ Talk 23:49, 1 October 2010 (UTC)