Wikipedia:Reference desk/Archives/Computing/2013 March 19

From Wikipedia, the free encyclopedia
Jump to: navigation, search
Computing desk
< March 18 << Feb | March | Apr >> March 20 >
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.

March 19[edit]

Pipe command-line output to Python instead of Perl[edit]

If I got something like

find -type f -name "*.txt" -print0 | perl -nle ...

can I pipe the output to Python instead of Perl? How would Python deal with the list it's getting? OsmanRF34 (talk) 00:39, 19 March 2013 (UTC)

Yes, and you would receive the input from the "sys.stdin" file-like object. The easiest way to deal with the input would probably be to slurp the entire input into a string, and then split it on the null characters. e.g.'\0'). That will give you a list of the entries (as well as a final empty string). As far as I know, there isn't a generator version of split (one that will yield entries as they come in, rather than all at once after the find command has exited), though you can write a simple one (See [1] for examples). - Note that in most cases, unlike perl, a python one-liner probably isn't going to work for you, so you'll probably have to write a small script to a file before you can use it in a pipe. -- (talk) 03:03, 19 March 2013 (UTC)
And what makes Python less appropriate for one-liners than Perl? OsmanRF34 (talk) 13:58, 19 March 2013 (UTC)
If nothing else, the rule that only one colon may appear on a Python line. The off-side rule would also be confusing, at least. You can, however, write multi-line "one-liners" with one of a few tricks:
$ python -c "if 1:
>   print 2"  # or single quotes
$ python <<EOF
> if 1:
>   print 2
$ python -c $'if 1:\n  print 2'
$ nl=$'\n'; python -c "if 1:${nl}  print 2"

(Only the last two are literally single lines, of course.) These are written for bash (shell); most can be modified to work with tcsh. --Tardis (talk) 14:47, 19 March 2013 (UTC)

While the syntactic use of newlines and indentation would likely be the primary technical limitation, there's a social component that also shouldn't be overlooked. Piping input to a command line one-liner is one of the core use cases of Perl. There are websites out there dedicated to collecting and indexing useful Perl one-liners. If a Python site talks about a one-liner, it's usually regarded as a linguistic curiosity or the use of an esoteric language feature. Additionally, if you ask a group of helpful Perlites for help in transforming your program into a one-liner, they'll likely try to one-up each other for the shortest/most elegant/most "one-liney" version of the program. In contrast, a group of helpful Pythonistas would probably question why you need a one-liner in the first place. It's not just getting help with one liners - the culture also influences language development. If you went to the Perl maintainers with the argument "if you added this new feature, it would make writing one-liners easier for these use cases", they'd probably seriously consider your proposal (in part because of TIMTOWTDI). If you did the same to the Python maintainers, they'd (perhaps vehemently) disagree that one-liners are a use case that deserves consideration in language design, demanding other rationales for adding things to the language (c.f. The Zen of Python). As such, Perl has more features that are helpful for one-liner writing than Python does. -- (talk) 21:13, 19 March 2013 (UTC)

How do I contact someone on Wikidoc[edit]

IP Address[edit]

I have just done a geolocate on an IP address on a question on the Lingo desk, and the website I use first tells me my own, before I can input the one I am asking about. Today, it said my IP geolocated to Poland. I am in the UK. Why would this happen? I am not using a proxy. KägeTorä - (影虎) (TALK) 02:42, 19 March 2013 (UTC)

Does the site correctly identify your ISP? - Cucumber Mike (talk) 10:11, 19 March 2013 (UTC)
Strange. It only happens when I am using the Opera browser. It must be something in the browser itself, then - maybe the Turbo settings or something. Firefox correctly says UK. KägeTorä - (影虎) (TALK) 11:58, 19 March 2013 (UTC)
Yup, you've got it. Turbo mode uses Opera's servers to pre cache sites - effectively they suck the data in at high speed at their data centre and compress them, then you download the sites from them. The sites therefore see your location as that of Opera's servers. I'm not sure if this happens for all sites, or just frequently visited ones. Funnily enough I haven't been able to find confirmation of the effect on IP geolocation from Opera themselves, but there is plenty of anecdotal evidence out there on 'tinterweb. - Cucumber Mike (talk) 15:05, 19 March 2013 (UTC)

Is it possible to create a n-body pertubation simulation app with the Blender (software)?[edit]

I want to allow the user to enter input data from the keyboard and to copy data from clipboard. (talk) 09:33, 19 March 2013 (UTC)

Anything is possible... Blender is scriptable in Python. You can even create custom GUIs. Is it the best way to implement an n-body simulation? Probably not; you're cornering yourself into limiting the simulation accuracy and performance by explicitly tying the simulation to its 3-D animation. But, you know your application needs better than anyone else. Nimur (talk) 11:47, 19 March 2013 (UTC)
Also, you may like VPython better than Blender, if you're aiming for simplicity in physics simulation and animation. Nimur (talk) 12:01, 19 March 2013 (UTC)

Problems compiling[edit]

Hi all, I'm hoping for some general advice on pesky compiles, and specifically some how-to on hunting the bugs. I am attempting to compile software written in C and Fortran, using gcc and gfortran on a Mac. The software has several dependencies, including Hierarchical Data Format (4 and 5), and Message_Passing_Interface, which I believe are all installed correctly. Anyway, when I ./, I get errors like "Can't find file: mpif.h" and "make[1]: *** No rule to make target `rconstants.mod', needed by `consts_coms.o'. Stop. make: *** [all] Error 2"

So, I conclude that I haven't properly setup my makefiles to point the the correct directories for includes, headers etc. My main question: how can I find *where* it was looking for e.g. mpif.h? How do I determine which makefile and line # was being processed when the error was given? This kind of info should theoretically help me track down and fix the problem, right? I am somewhat Unix conversant, but don't usually do much compiling (outside of Macports, which always works fine). Any specific or general advice is welcome. Thanks in advance! SemanticMantis (talk) 14:45, 19 March 2013 (UTC)

The makefile should pass lists of include file directories to gcc with the -I dir directive; you may need to first look at the trace of the compile run to determine that, and then find the corresponding rule in the makefile. In some cases these will be direct (from makefile variables) and in other cases they may result from the output of a program like pkg-config. GNUmake has a -d option to get it to show it's workings, but it's usually not very helpful. -- Finlay McWalterTalk 15:28, 19 March 2013 (UTC)
If all else fails, you can do debugging by putting a print between every line. The bug which stops the compiler should occur between the last line to print and the first line not to. If there are just too many places to put prints, you can do it in steps. For example, in a 1000 line file, you could put in 10, evenly spaced ("Trace 1" - "Trace 10"). Try to compile, and that will get you to a 100 line chunk where it fails. Then add 10 prints there, evenly spaced, to get it down to 10 lines (say "Trace 3.1" - "Trace "3.10"). Finally, add prints on every line in that 10 line chunk (say, "Trace 3.4.1" - "Trace 3.4.10").
If all else fails, you can do debugging by putting a print between every line. The bug which stops the compiler should occur between the last line to print and the first line not to. If there are just too many places to put prints, you can do it in steps. For example, in a 1000 line file, you could put in 10, evenly spaced ("Trace 1" - "Trace 10"). Try to compile, and that will get you to a 100 line chunk where it fails. Then add 10 prints there, evenly spaced, to get it down to 10 lines (say "Trace 3.1" - "Trace "3.10"). Finally, add prints on every line in that 10 line chunk (say, "Trace 3.4.1" - "Trace 3.4.10").
A few things to watch for doing this, though:
1) There are cases where, due to flushing of different buffers, the prints are not synchronized with the error messages. So, you could get:
 Trace 1.2.3
File not found
 Trace 1.2.4
But this doesn't necessarily mean the line between those two prints produced the error. However, if the compiler actually stops, then the last trace print should be a legit way to find the error.
2) The place where a bug manifestation occurs is not always the cause of the bug. For example, the "File not found" error could mean some previous command to define the search path failed.
3) Prints inside loops with many iterations can be excessive. Try to avoid putting prints in such places, unless you have determined the bug to be inside that loop. Even then, you might want to first set a counter, to determine how many runs of the loop succeed, and then only do prints after that number of runs of the loop. (If it fails after a variable number of runs of the loop, you're screwed. You'll just need to wade through the massive output file.) StuRat (talk) 15:36, 19 March 2013 (UTC)
Thanks, Finlay. First, can you clarify what you mean by "trace of the compile run"? Is it just the standard out stream of text, or something else? In this case, I know where mpif.h is (/usr/local/include), and the makefile has MPI_PATH=-I/usr/local/include/ -- but I still get "Can't find file: mpif.h" which is repeated about 20X. Does that mean it's looking in 20 places and failing all of them? I'm sure I'm betraying some ignorance here, but I do appreciate the help.
Stu, that's an interesting idea. But I'm not sure where you mean to put print statements. I don't think I'm even getting to any "real" compiling, just failing on dependencies (your second option). So, do you mean to put print statements within the makefiles? I really thought there would be a way to get it so spit out something like " mpif.h not found in foo-dir... mpif.h not found in bar-dir", etc., so that I can tell which paths and path variables it is working in. (In this case, I suspect it is looking for mpif.h in places other than what is declared by MPI_PATH=) SemanticMantis (talk) 15:53, 19 March 2013 (UTC)
Yes, I was talking about putting prints in the makefile. If it calls other makefiles, you can then add prints to those, once you determine which of those is the problem.
One things you can try for "file not found" errors is copying the file into the current directory, which is often included in any search path. StuRat (talk) 15:58, 19 March 2013 (UTC)
Stu, your debug-printing advice is a bit strange for a makefile, since it's declarative and doesn't really contain a sequence of operations, much less loops. Moreover, the most obvious way of printing in a makefile would involve lots of different processes, in which case the flushing issue isn't really relevant. --Tardis (talk) 05:03, 20 March 2013 (UTC)
Sorry, I was thinking of the script which calls the makefile. StuRat (talk) 05:45, 20 March 2013 (UTC)
Make typically prints a command before running it — if it's not, look for @ signs in the makefile that suppress this (or -s, --silent, or --quiet options that do it globally), or just use make -n to print (all the) commands without running them. Next, you should know that the f in mpif.h means Fortran, so narrow your search to those source files. Finally, you should know that .mod files are generated by side effect when compiling modern Fortran (90 or newer); it seems like a makefile bug that it knows that the .o files depend on them but doesn't know how to generate them. (What I've done in this case is have the .o files depend on one another, since make does know how to build those.) If it's not overly long, just post the full output from a normal make (from a clean start) here… --Tardis (talk) 05:03, 20 March 2013 (UTC)

Problems connecting to the Internet with new computer[edit]

I have a brand new computer that I am unable to connect to the Internet with. It's not a hardware problem with the ethernet cable nor the modem itself, as I can use the cable on the laptop and have no problems. The modem is a "Surfboard Digital Voice Modem" (picture of it here), and my setup for all the hardware seems to be (Computer + Cat5) > modem > (component that splits, one line coming from the television, one from the modem) > wall jack. My ISP is Cox Communications, if it helps. Could my cable modem be blocking the second computer, and if so, how can I fix it? -- Tohler (talk) 18:16, 19 March 2013 (UTC)

Yes, it could be. Modems and routers sometimes do something called 'MAC filtering' - basically only allowing certain computers to connect; it's a little like a gate that only opens for cars with a certain registration. To check if that's the case, try this: connect the cable to your laptop, and then open a web browser on the laptop. Click here -> and, if a password is requested, enter username admin and password motorola. Do you get a configuration page? If so, have a hunt around in the menus for MAC filtering and turn it off. Now try connecting the new computer.
If you can't get to the configuration page, post back here and we'll try and think of something else. - Cucumber Mike (talk) 19:48, 19 March 2013 (UTC)
Scrub that, I've just had a thought. Try this: Unplug the Ethernet cable from your laptop. Switch off the modem (i.e. turn the power off) and wait 30 seconds. Now plug the Ethernet cable into your new computer and, finally, turn the modem back on. Any joy? - Cucumber Mike (talk) 20:01, 19 March 2013 (UTC)
Attempted that already. No joy. I will check for the MAC filtering that you mention. -- Tohler (talk) 21:45, 19 March 2013 (UTC)
Fair enough, it was worth a go. First rule of tech support: If in doubt, turn it off and on again! - Cucumber Mike (talk) 22:01, 19 March 2013 (UTC)
  • "I am unable to connect to the Internet" is a useless problem report. What specific action did you take, what result did you expect, and what result did you observe? In other words, what is the observation that tells you that you are failing to connect? (Also, what kind of computer is it and what OS is it running?) Looie496 (talk) 21:05, 19 March 2013 (UTC)
In order: Attempting to set up a connection in Network and Sharing Center. Expecting a successful connection. Not observing a successful connection. Error message saying the modem returned an error (or something similar; I'm not currently at home to check precisely), as well as no connectivity with web browsers, IRC, etc. Alienware Aurora, Windows 7. -- Tohler (talk) 21:45, 19 March 2013 (UTC)
If the steps above fail, can you describe in detail how you 'attempt to set up a connection in Network and Sharing Center'? As far as I'm aware, you should just be able to plug the cable in and away you go. Maybe something's going wrong at this stage. - Cucumber Mike (talk) 22:05, 19 March 2013 (UTC)
Attempted to just plug in an "away I went"; after that failed, I tried setting it up manually to no avail. I'm still away from home; I'll explain my precise steps once I get back. -- Tohler (talk) 22:49, 19 March 2013 (UTC)
Try to run the computer with a Live USB, that will at least discard a hardware problem (or not). OsmanRF34 (talk) 23:02, 19 March 2013 (UTC)

running two OSes in parallel[edit]

I know I can dual boot my harddrive so I can choose between running either, for example, linux or windows when I load up, and I can have dual screen and be doing two different things at once, but is there any way of combining these and running a different OS on each screen?

Kitutal (talk) 20:44, 19 March 2013 (UTC)

If you have a powerful enough computer you could run one OS in a Virtual machine. However it does need quite a lot of computing power (if you think about it, you'd effectively be running two computers on the same machine), so you might find it quite slow if you are trying to complete two tasks at once. - Cucumber Mike (talk) 21:02, 19 March 2013 (UTC)
It doesn't require much computing power, especially if you have a recent CPU with hardware virtualization support. It is a good idea to have a lot of RAM, though. -- BenRG (talk) 22:43, 19 March 2013 (UTC)
(ec) You'd want two different computers to do that, or each O/S would compete with the others for resources. I have two different computers (with a switch-box) running here, just like that. I find it's a good way to put old computers to good use. Each computer can be dedicated to do just one thing, so they don't get bogged down. StuRat (talk) 21:05, 19 March 2013 (UTC)
  • See VMware, a system that allows you to do just that -- but it's not nearly as easy to set up as a dual boot, and might cost substantial money. Looie496 (talk) 21:09, 19 March 2013 (UTC)
Also check VirtualBox, which can also be quite tricky to implement, but is for free. OsmanRF34 (talk) 22:02, 19 March 2013 (UTC)
A lot of VMware's products are free too these days (though not open source). -- BenRG (talk) 22:43, 19 March 2013 (UTC)
coLinux is closer to what you asked for, but it only works with 32-bit Windows as the host OS and Linux as the guest, and it's not very actively maintained, so you're probably better off with VMware and company.
There are also "bare-metal" hypervisors, which are stripped-down OSes designed only for running VMs. You then run your two operating systems as guests on top of that. But the host-and-guest setup will be a lot easier to set up. -- BenRG (talk) 22:43, 19 March 2013 (UTC)
The OP doesn't say if he has any familiarity with Linux. If he does then using (say) Linux Mint or Ubuntu as the host should be almost a walk in the park. Linux is far more suited to this sort of set-up. [Youtube: setting up dual screen linux]. I have often had image processing software running on one OS or even two, whilst I do other less resource hungry activities like surfing, word processing and dealing with email on the host. There is no noticeable slowing down when doing these activities. To make installing VirtualBox less troublesome, it would help to peruse the Ubuntu help forums, because sometimes one might need to download a dependency that is not included in the Distro (but in practice I find this a whole lot easier than messing around with Microsoft as host). Also, to make VirtualBox of any practical use you need to remember to down load the “ VirtualBox extension pack” from here. [2]. I no longer have any microsoft OS running on its own physical-machine as Linux is a lot more reliable and easier to maintain. Linux today, is easer to use (once you have become familiar) than microsoft.--Aspro (talk) 11:43, 20 March 2013 (UTC)
If the reason for running Windows is to play Windows games or something else that requires GPU support, Windows should probably be the host. Otherwise, if one OS (probably Windows) is supported by the OEM and the other isn't, the supported one should probably be the host. Otherwise I don't think it matters. Linux isn't intrinsically any better at being a host. -- BenRG (talk) 23:50, 20 March 2013 (UTC)
The OP really needs to state his need to run two or more OS's to answer this properly. If by OEM you mean the hardware manufactures, I don't see your point (other than for some GPU issues). Yet, if the OP wants to run Valve games, then the frame rate on Linux is blisteringly fast. Microsoft is justifiably worried by this turn of events. [3]. It is also simpler to write software for Linux because the software-house doesn’t have to jump through all the hoops to get microsoft approval. So, it would be in the OP's interest to become familiar with a OS's (Linux flavours) as host, that allow him control over the computer (that he owns) rather than using an OS (microsoft's ) that tries to take that complete control away from him. Unless, the OP is running just Autocad or something, he should find Linux as host a better long term bet. Microsoft has always been chasing virtual machine technology so isn't it better to use a OS that's a leader in the field? --Aspro (talk) 00:21, 21 March 2013 (UTC)
So it would have to be through some virtual machine, rather than getting the computer to run both at once, even if it was powerful enough and had perhaps duplicates of some hardware as well? And I'd want to run a wide range of different tasks on both, I use my computer a lot for many different things. Kitutal (talk) 16:05, 21 March 2013 (UTC)
Exactly. With dual (triple, etc) boot, one only has the option to boot in to one OS at a time, which is thus given over all control of the hardware. A “virtual machine” however, is a software container in which you can run a different operating system and its applications inside of it. The host has overall control of the hardware but lends the other operating system(s) some of its spare capacity. Best thing to do is just try it and with that experience so gained, you will be able to configure something to your liking. Take it and chew it in small mouthfuls and it will be easier to digest. Don't worry about over-all power at this stage. The application your actively using on the host will tend to have priority over the guest and so you will not really notice much difference. And if you are actively using a guest then you wont be using the host so much, so again you wont really see any slow down. You can easily run several guests at the same time on the the average Linux desktop. Microsoft is a rather bloaty monolithic OS and you may find thing going slower and slower. Linux was designed from the outset to be modular, multi tasking, so it runs a ruddy sight faster.--Aspro (talk) 18:21, 21 March 2013 (UTC)
Incidentally, since you can have multiple desktops on a single screen with Linux, you can try out (say) VirtualBox (as its free) and have a different OS running on as many different 'Desktops' as you want. You may find you don't need to purchase a second screen, as it is quick to switch between desktops with a click of the mouse.--Aspro (talk) 18:37, 21 March 2013 (UTC)
Another advantage of Linux is that you can employ 'compiz'. 6 Monitor Linux workstation using Ubuntu and Compiz If microsoft came fresh to the software market today, it would just be left on the shelf as too primitive and difficult to learn and use...--Aspro (talk) 00:34, 22 March 2013 (UTC)