Wikipedia:Reference desk/Archives/Computing/2007 October 8
Computing desk | ||
---|---|---|
< October 7 | << Sep | October | Nov >> | October 9 > |
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. |
October 8
[edit]Python
[edit]I have a question about python. I'm trying to write a program to do matrix operations. If I give the program inputs of n rows by m columns, how would I tell it to ask for (m x n) inputs? 68.231.151.161 01:36, 8 October 2007 (UTC)
- Your question is unclear to me, but here's the general idea:
#!/usr/bin/python import sys def read_array(rows, columns): print "Enter a %d row x %d column array of integers," % (rows, columns) print "separated by spaces, one row per line:" print got_rows = 0 array = [] while got_rows < rows: try: print "Row %d: " % got_rows, line = sys.stdin.readline() row = [int(x) for x in line.split()] if len(row) != columns: raise Exception, "I need %d columns per row" % columns array.append(row) got_rows += 1 except Exception, e: print e return array def array_add(a1, a2): if len(a1) != len(a2): raise Exception, "mismatched array sizes" out_array = [] for row in range(len(a1)): if len(a1[row]) != len(a2[row]): raise Exception, "mismatched array sizes" out_row = [] for col in range(len(a1[row])): out_row.append(a1[row][col] + a2[row][col]) out_array.append(out_row) return out_array def pretty_print_array(a): for row in a: for col in row: print '%6d' % col, print array1 = read_array(2, 3) array2 = read_array(2, 3) asum = array_add(array1, array2) pretty_print_array(array1) print pretty_print_array(array2) print pretty_print_array(asum)
Like Sean, I am unclear on the exact question being asked. However, here is a small, idiomatic Python function which can initialize matrices from your "standard input" (which means that it can be used with normal UNIX/Linux I/O redirection, for example).
#!/usr/bin/env python def read_array(columns, rows): """Read rows lines of columns numbers for initializing matrices """ matrix = [] for i in range(rows): this_column = [ float(x) for x in raw_input().split() ] if len(this_column) != columns: raise ValueError matrix.append(this_column) return matrix
if __name__ == "__main__": import sys, pprint if len(sys.argv[1:]): for each in sys.argv[1:]: c,r = [ int(x) for x in each.split('x') ] try: m = read_array(c,r) except ValueError, e: print >> sys.stderr, "Error parsing %s array" % each continue pprint.pprint(m)
This does almost no error checking. However, the "read_array()" function is only eight lines long. It assumes that you want to fill your matrix with floating point (real number) values and that each line will consist solely of numbers separated by white space. The only error checking I'm doing is that the number of values that I can parse out of each line matches the number of columns supplied in our invocation arguments. In any event this function returns a matrix of the specified dimensions or it raises the "ValueError" exception.
Obviously additional error checking could be done inside our function (for example to ignore invalid/unparseable lines) and/or pinpoint any erroneous inputs.
The test engine code at the bottom of this is also pretty crude but is sufficient for demonstrating the calling conventions and a simple test suite can be built around it. For example the following shell script can drive a simple test of reading two 4x4 matrices (where one happens to be an inverted copy of the other, and they just happen to consist only of single digit integers):
#!/bin/sh ./matrix_ops.py 4x4 4x4 <<-EOF 1 2 3 4 2 3 4 5 6 7 8 9 0 1 2 3 3 2 1 0 9 8 7 6 5 4 3 2 4 3 2 1 EOF
(Here I'm just using a shell "here" doc as the the source of our data, which allows me to keep both the command (with the requisite arguments) and the data in the same file).
When I say that this is "idiomatic" Python code I'm referring to the use of "list comprehensions" in the following line:
this_column = [ float(x) for x in raw_input().split() ]
... which returns a list of the results from calling float() (converting text strings into floating point number objects) on each of the strings which results from calling the .split() string method (which by default splits a string on whitespace, returning a list of substrings). I'm calling that method on the results of my call to the Python raw_input() built-in function.
In other words this line is doing most of the work that you were asking about. It's equivalent to the following:
this_column = [] line = raw_input() words = line.split() for each in words: num = float(each) this.column.append(num)
Of course, when we expand the code in this way we can add some additional error checking, such as a try:...except: block around the conversion, and a test for too many values on any given line of input. (My idiomatic code attempts to convert a whole line, which fails on the first non-parseable value on a line --- but could work on converting thousands of values on one long line of input when our improved code could test on the first extraneous value. Alternatively we could ignore all input after the desired number of "words" on each line.
In my test engine code I'm requiring that we be called with a list of command line arguments and that each of those be of the form: MxN (where M and N are the numbers of columns and rows respectively). There I'm splitting each argument on the "x" between them.
Obviously this code could be improved quite a bit. I could, for example add a usage message (if called with no arguments) ... and wrap the argument parsing in its own exception handling code (which, again, could just call my usage function).
More complicated input formats would, naturally, require more sophisticated parsing --- usually best accomplished using regular expressions (included with Python's standard libraries) and possibly (as the requirements rise to new levels of complexity) using any of the lexical parser generators that are freely available for Python).
midi files
[edit]I have collection of midi files from the late '80's. Some will not play using Windows Media Player with the problem being timing or rhythm. At first I thought it might be due to an outdated copy of WMP or the motherboard being configured for use spread spectrum, but no, it happens with all WMPlayers not what else is changed. Most of the midi files that WMP cannot play Quicktime can play so I'm able to listen to almost every file I have. What is the reason for this problem? Is there a difference in midi file format or what? Clem 06:24, 8 October 2007 (UTC)
- If you'd like to email me one (you can do that from my user page) - I'll try to play it with some other MIDIfile players I have...including one I wrote myself(!). Maybe I can figure out what's wrong with these files (or, conversely, what's wrong with WMP). The MIDIfile standard has hardly changed at all - but most players out there are incomplete in one way or another - and the tempo stuff is the hardest to get right. SteveBaker 15:36, 8 October 2007 (UTC)
- Timing and rhythm are no problem for Quicktime with these files. It may also be how WMP runs under Windows XP x64, what thing either uses for the clock. The question I am really trying to answer is whether it may have something to do with the copyright protection mania that WMP has, if midi files have any provision for copyright enforcement. Clem 20:32, 8 October 2007 (UTC)
I really like winamp.--Sonjaaa 02:20, 9 October 2007 (UTC)
To answer your questions, User:kadiddlehopper, yes, there are different MIDI file formats (or alternatively, different "variants" of the MIDI spec). There are various reasons why your MIDI files may not read properly in any given player, none of which necessarily have to do with copyright protection schemes. For example, certain MIDI controller messages or track information may be corrupt. You can find out more by opening your files in a MIDI sequencer, which are designed to handle multiple file formats and fully support view/edit/delete of all controller and track events. If there's corrupt data, you can usually remove it by editing in a sequencer. You can find more information here. dr.ef.tymac 13:51, 9 October 2007 (UTC)
EMail ID - 2nd post
[edit]Earlier Iasked for the email id of Tiffany Taylor and someone gave it to me as dgi.business@aol.com.As planned I sent her a mail but I got a mail from MAILER-DAEMON@n2.bullet.mud.yahoo.com that the mail could not be delivered to that address.The remote host said that 550 MAILBOX NOT FOUND [RCPT_TO].What does this mean?218.248.2.51 08:45, 8 October 2007 (UTC)Hedonister
- Exactly what it says, you were given an invalid email address. JIP | Talk 08:58, 8 October 2007 (UTC)
- See bounce message and RFC 3463. --Kjoonlee 17:20, 10 October 2007 (UTC)
Ripping DVDs
[edit]With libdvdcss installed, MPlayer on Linux will rip the actual movies on DVDs just fine and store them on my hard disk, where I can play them without the DVD. But is it possible to also rip the menus where I choose the movie to play, and have them work in the DVD player?
(Legal disclaimer: libdvdcss is perfectly legal in Finland. These DVDs are commercial, copyrighted content. I have bought them legally and paid for them full price. It is not against any law for me to copy them for my own personal use. I will not redistribute the content in any way.) JIP | Talk 11:32, 8 October 2007 (UTC)
- Here is a common misconception. You only need deCSS to play the movie - you can copy the entire content of your DVD onto another DVD without decrypting it. So deCSS has essentially nothing to do with copy protection. What it mostly does is try to ensure that only licensed players can play DVD's - and that's an entirely different matter. The thing that makes it (maybe) illegal in the USA is the DMCA which makes it illegal to break the DVD encryption mechanism. However, it's a dumb law because you can break the copyright laws without decrypting the disk - and you need to decrypt the data in order to do something (like playing your legally purchased DVD on a Linux machine) that isn't illegal otherwise. I suspect that the main reason for encrypting the content in the first place was to prohibit un-licensed DVD players - because those can let you do things like skipping all of the intro-crap and circumventing the region-encoding (for example to play legally purchased Japanese or European DVD's in the USA). The law in the US is a total mess right now. SteveBaker 15:31, 8 October 2007 (UTC)
- Thanks for the reply, but it did not address my actual question at all. I do know that CSS does not prevent copying, and is only intended to prevent playback by unlicensed players. I merely added the disclaimer to prevent people from freaking out when they saw I am ripping DVDs. My question is, how can I rip the menus as well as the actual movies? JIP | Talk 15:34, 8 October 2007 (UTC)
- You need to use something other than mplayer, I imagine. There are DVD rippers that can rip menus—MacTheRipper, for example, does this readily. My bet is that the easiest way to do this would be to get something that would just create a disk image of the DVD, which would reproduce the menus just the same way. --24.147.86.187 20:00, 8 October 2007 (UTC)
- Neither MacTheRipper or DVD Shrink are available for Linux. I tried making a raw disk image with
dd if=/dev/dvd of=dvd.img
but it stopped at a read error after only a few megabytes. JIP | Talk 20:04, 8 October 2007 (UTC)- The deal is that if you rip the DVD into an unencrypted MPEG or AVI or something - then you've lost all hope of having the menus work. It's got to remain as a copy of the original DVD for that to work. I wonder though - do you actually need a bit-for-bit rip of the DVD? Can't you just copy the files off of it? I believe that DVD's have a proper directory structure - you can mount them and look around the files that are there. SteveBaker 20:29, 8 October 2007 (UTC)
- Yes, I can mount the DVD and look at the files. But Xine (the only player I have found to play CSS-encrypted content) can't play the files directly, it has to go through a DVD driver. Xine can either play the DVD directly from the drive, or the VOB files MPlayer creates from individual titles. I have found k9copy, which claims to copy DVDs with menus. So far I have been successful in creating a copy of an encrypted DVD but I haven't yet tried to play it. JIP | Talk 21:09, 8 October 2007 (UTC)
- Yes, it works. Reading the DVD takes only about ten minutes but writing it to the ISO image takes well over an hour. Xine can't play the resulting ISO file directly, but if I tell it that the DVD device is in fact in that ISO file and not in
/dev/dvd
, then it will play the DVD just nicely fromdvd://
. Now I just need to find a way to tell Xine the driver location from the command line. JIP | Talk 22:25, 8 October 2007 (UTC)- I've found dvdbackup to do a great job of copying DVDs. It produces a simple decrypted copy of the files on the DVD which can be played by xine or burnt with standard dvd+rw-tools. Both should be available as packages on Debian-based distros at least (
apt-get install dvdbackup dvd+rw-tools
). I've never experienced the kind of slowdown you describe either; the only explanation for it that I can think of is that k9copy is actually recompressing the video streams rather than just copying them verbatim. —Ilmari Karonen (talk) 01:46, 11 October 2007 (UTC)- It is recompressing them. One of the DVDs I tried (World Bodypainting Festival 2007 official DVD) has over 6 GiB of material, according to the size of the raw title files that MPlayer writes. However, k9copy wrote it all to a 4 GiB ISO file. JIP | Talk 15:43, 11 October 2007 (UTC)
- I've found dvdbackup to do a great job of copying DVDs. It produces a simple decrypted copy of the files on the DVD which can be played by xine or burnt with standard dvd+rw-tools. Both should be available as packages on Debian-based distros at least (
- Yes, it works. Reading the DVD takes only about ten minutes but writing it to the ISO image takes well over an hour. Xine can't play the resulting ISO file directly, but if I tell it that the DVD device is in fact in that ISO file and not in
- Yes, I can mount the DVD and look at the files. But Xine (the only player I have found to play CSS-encrypted content) can't play the files directly, it has to go through a DVD driver. Xine can either play the DVD directly from the drive, or the VOB files MPlayer creates from individual titles. I have found k9copy, which claims to copy DVDs with menus. So far I have been successful in creating a copy of an encrypted DVD but I haven't yet tried to play it. JIP | Talk 21:09, 8 October 2007 (UTC)
- The deal is that if you rip the DVD into an unencrypted MPEG or AVI or something - then you've lost all hope of having the menus work. It's got to remain as a copy of the original DVD for that to work. I wonder though - do you actually need a bit-for-bit rip of the DVD? Can't you just copy the files off of it? I believe that DVD's have a proper directory structure - you can mount them and look around the files that are there. SteveBaker 20:29, 8 October 2007 (UTC)
- Neither MacTheRipper or DVD Shrink are available for Linux. I tried making a raw disk image with
Solitaire
[edit]This is something I've wondered for years, but when playing Solitaire, are all of the cards given a deck and a value from the beginning of each game, or is the identity of each card only decided once it has been turned over. In other words, is a whole virtual set of cards dealt everytime you click "Deal", or does the computer only assign to each card a value (from the remaining possible values, i.e. those not already face-forward) once it has been turned over? I.e. will two players playing an identical game of Solitaire encounter the same cards at the bottom of each of the piles?
This is something I've wondered since the first time I played Solitaire... which is a long time indeed, and I figured that this would be the best place to ask as I figure one must know what the Solitaire codes and what-have-you contain before being able to correctly answer.
Thanks in advance, Ninebucks 13:10, 8 October 2007 (UTC)
- I don't know, but I do know that Minesweeper "deals" out a whole field of mines but if you end up clicking on a mine for the first click, it will quickly re-deal things so that you don't just end the game. (You can test this by using the XYZZY code to detect where mines are without having them revealed.) That being said, I find it unlikely that Solitaire doesn't deal the entire deck into an array and just use that as a reference to the cards—it would be easier to just do that all at once than do re-calculate it for each card. --24.147.86.187 13:33, 8 October 2007 (UTC)
- It probably depends on the game's implementation, I can't be sure since I don't have access to the source code. But I would assume it'd be like a shuffled and dealt deck of real cards, which, obviously, are pre-defined. For snappier gameplay and the ability to pre-cache images, I bet it'd make sense to define the order of dealt cards. -- JSBillings 14:24, 8 October 2007 (UTC)
- It's hard to know how someone else's program works without seeing the source code - but it wouldn't be a lot more difficult to maintain a list of cards that are 'in play' and a list that are available to be played and to just pick a random card from the 'available' list each time you turned over a card rather than shuffling the deck at the outset. On balance, I suspect they shuffle the deck just once - but it's really impossible to know without reverse-engineering the code or obtaining a copy of the sources. SteveBaker 15:23, 8 October 2007 (UTC)
- To the player, there is no difference. The probabilities are the same. --131.215.166.100 18:17, 8 October 2007 (UTC)
- Yes - certainly. Although quite a few people would be nervous that the computer was somehow 'cheating' by not shuffling the cards first! SteveBaker 20:25, 8 October 2007 (UTC)
- In 2004, parts of the Windows source code were leaked. I'm sure you could find a copy kicking around and see for yourself how they do it. --Sean 21:25, 8 October 2007 (UTC)
It would have to be pre-determined at least partially, because you can tell windows solitare to let you go through the deck multiple times and it retains its order (so the top card turned over will always be the top one turned over until you re-deal). Kuronue | Talk 04:05, 13 October 2007 (UTC)
hot swap able hard disk
[edit]can we load operating system from hot swap able hard disk? —Preceding unsigned comment added by 125.209.115.137 (talk) 15:05, 8 October 2007 (UTC)
- It really depends on the hardware. All the disks in my servers are hot-swappable, in a RAID1 configuration. -- JSBillings 15:40, 8 October 2007 (UTC)
Windows Aero Problems
[edit]I purchased a new computer around 2 months ago and it has Windows Vista Home Premium. At the same time, my brother purchased an identical computer. For the first few weeks all the features of Windows Aero worked perfectly. However, now the window translucency and the "window select" thing still work, but the "live thumbnails" on the taskbar steadfastly refuse to work no matter what I do. My brother's computer works fine. What is going on? 69.205.180.123 16:00, 8 October 2007 (UTC)
- Maybe you turned them off in the taskbar properties. Leave them off, they're a drain on performance --frotht 17:03, 8 October 2007 (UTC)
- My comp can easily handle it, (it has a 2.0GHz AMD dual-core processor and 2GB of RAM) That was the problem i.e. I had it turned off in the taskbar menu. Stupid me. (bangs head on desk)69.205.180.123 00:01, 9 October 2007 (UTC)
Posting not showing up???
[edit]I posted a new article and it doesn't come up in the search function??? It is listed and accessable in "my contributions", so I'm confused!
The title is: Human Capital Integrated
Thank you,
--Mwoodward 16:41, 8 October 2007 (UTC)
- Works for me. Someoneinmyheadbutit'snotme 17:00, 8 October 2007 (UTC)
- The article is there - but I'm going to nominate it for a speedy deletion. Mr. Woodward - it is *NOT* OK to write articles about yourself or promote your own business on Wikipedia. SteveBaker 17:04, 8 October 2007 (UTC)
- Kinda irrelevant, but for future reference, this question would have been more suited for the Help desk. Algebraist 19:15, 8 October 2007 (UTC)
It takes some time after a change for it to be reflected in the search. Graeme Bartlett 22:03, 8 October 2007 (UTC)
Plasma TV break in period?
[edit]I just bought a snazzy new Plasma TV from one of the big electronics stores in the US. The salesperson recommended that I run the set for two months (!) at reduced brightness in order to 'break in' the plasma elements. (In fact, this particular set has a 'low power' mode that reduces the screen brightness dramatically) I've never heard of anything like this. Does this break-in period really prolong the life of the TV screen and reduce burn-in later on? Or he feeding me some crazy pro-LCD propaganda? Do I really need to watch a dim screen for 8 weeks? --24.249.108.133 21:29, 8 October 2007 (UTC)
- When we bought our plasma, the guy said to play it at low brightness for 16-24 working hours, which we took to mean that when we had watched tv for a total of 24 hours since making the purchase, it was safe to turn it up to maximum brightness.69.205.180.123 00:04, 9 October 2007 (UTC)
- Go to www.google.com and type in plasma break in. There are discussions and manufacturers' recommendations[1] out there. I hadn't heard of this either... Weregerbil 11:11, 9 October 2007 (UTC)
- Read about this a while ago (I think it was on these very pages..). Essentially, plasma TVs often have the problem of some phosphors becoming less bright before others - with the ones that usually do not fade being the ones corresponding to black bars on movies, as they are lit up much less often. So essentially they have you dim the entire set so that there's an even burnout pattern - otherwise, the areas usually black will appear brighter than the duller phosphors in the middle when watching TV or properly sized movies. This might be incorrect, but it's what I remember. -Wooty [Woot?] [Spam! Spam! Wonderful spam!] 05:57, 10 October 2007 (UTC)
ancestor to photocopier
[edit]when i was a kid in grades 1 to 3, the school had a machine that you'd turn a hand crank and it would apply special blue paper onto many many copies, each copy would be sligthly fainter than the previous one. They used that for making many copies of tests, etc. (i was born in 1978, so i was ages 5 to 8 at that time). what exactly is this called?--Sonjaaa 00:21, 9 October 2007 (UTC)
- A mimeograph, or it could be a Spirit duplicator. DuncanHill 00:23, 9 October 2007 (UTC)
- Reading through the articles, if the prints were purpley/blueish, and had an interesting smell, then it was a spirit duplicator. I think that when I was a lad, the name "mimeograph" was used rather generically for both types of machine. DuncanHill 00:26, 9 October 2007 (UTC)
It was definitely purply blue, but i don't remember if there was a smell or not.--Sonjaaa 02:21, 9 October 2007 (UTC)
- I agree with Duncan. The process that Wikipedia calls a spirit duplicator was commonly used in the schools I attended in the 1960s and 1970s. Not only do I remember the alcohol smell on freshly made copies -- I would definitely describe the ink color as purple, not blue -- but I prepared some masters myself to be reproduced that way. (As I recall, you had to write fairly heavily, either using a typewriter or pressing hard with a ballpoint pen.) But what we always called them was ditto or mimeograph copies, even though Wikipedia says a mimeograph is something else.
- It is not really correct to describe the process as an "ancestor to the photocopier", since the point of a photocopier is that it can copy any original image. Since the process uses a specially prepared master, it's more like a cheap alternative to printing. But of course it was used in some situations where people would use a photocopier today.
- Incidentally, this seems more like a Science or Miscellaneous question than a Computing question. --Anonymous, edited 04:00 UTC, October 9, 2007.
I use Computing section for Computing and Technology.--Sonjaaa 08:48, 9 October 2007 (UTC)
- You might also want to check Cyanotype - that's another ancient duplicating process, and the origin of the term "Blueprint". SteveBaker —Preceding signed but undated comment was added at 13:07, 9 October 2007 (UTC)
CAS programming on PC
[edit]Hi,
Does anyone know a program I can use to create/edit Ti-89 files (.89p) on my computer? Massive thanks for anyone that can tell me!!! --Fir0002 07:58, 9 October 2007 (UTC)
- See TI-89#Programming and TIGCC. --Sean 16:12, 9 October 2007 (UTC)
Who pays for Internet backbone? How much websites pay?
[edit]We all know consumers pay for bandwidth. But do companies like Google pay for any bandwidth? I assume that the $20 which a Internet subscriber/ user pays to an ISP is for both getting connection in to my house and at the same time, it also pays for my usage for the ISP to laying cables across oceans and deserts. I think that the whole Internet consisting of cables across the world is paid by subscribers of ISPs. How about Google? Do they pay only for uploading data to Internet backbones or do they also share cost of laying backbones across the earth? What is the situation? The Internet consists of both websites and web surfers. Do they contribute equally to the underlying capacity or do consumers pay more? —Preceding unsigned comment added by 59.96.23.251 (talk) 09:00, 9 October 2007 (UTC)
- Generally, you pay your ISP and the ISP pays the telecom companies that own the backbone. Google is too big to use an ISP - so they'll be paying for their bandwidth to the telecom companies directly. Not all companies work like that - the smaller ones typically use an ISP just like you and I do - but everyone pays according to the bandwidth of their connection to the backbone. Indirectly, both you and Google are paying for the bandwidth for the up and downstream data that you exchange with them. Whether that is a 'fair' split is tricky and gets you into the issues of network neutrality. Google (specifically) are starting to buy networking resources - so gradually, they are becoming another telecom company and they'll (presumably) get revenue from selling that bandwidth to ISP's and other companies who need it and cut their own connection costs in the process. Also, many, many websites out there (like mine for example) are paid for by individuals who use a web hosting service (mine costs ~$100 per year[2]). Web hosting services also pay the telecom companies for access. So it costs me $100 per year to give you access to the stuff on my website, my son's website and my car club's website. SteveBaker 13:00, 9 October 2007 (UTC)
- This certainly counts as original research, but I do not believe Google is intending to sell its networking resources to outside parties. In my estimate, they are solely seeking to mitigate their internal networking needs (with such a massive infrastructure and web-crawling, they are using a lot of long-haul bandwidth!) From the rate at which they purchase longhauls, and their marketing strategy, it seems highly unlikely that they will provide network service to end-users (and almost certainly not to residential networks). However, you may get a good laugh from their last April Fool's Joke, [3]. Nimur 22:46, 9 October 2007 (UTC)
- For the love of God, I don't think that original research is an issue on the reference desk. Donald Hosek 00:16, 10 October 2007 (UTC)
- It's more tongue-in-cheek I think --frotht 02:49, 10 October 2007 (UTC)
- Hah, steve's web host looks like the april fool's joke- a fat kid sleeping is their company image :) Nice offer though. (isn't 5TB overkill for a static personal website?) --frotht 02:57, 10 October 2007 (UTC)
- For the love of God, I don't think that original research is an issue on the reference desk. Donald Hosek 00:16, 10 October 2007 (UTC)
- This certainly counts as original research, but I do not believe Google is intending to sell its networking resources to outside parties. In my estimate, they are solely seeking to mitigate their internal networking needs (with such a massive infrastructure and web-crawling, they are using a lot of long-haul bandwidth!) From the rate at which they purchase longhauls, and their marketing strategy, it seems highly unlikely that they will provide network service to end-users (and almost certainly not to residential networks). However, you may get a good laugh from their last April Fool's Joke, [3]. Nimur 22:46, 9 October 2007 (UTC)
Unix question: Getting file name if one exists
[edit]In Unix, how can I get the name of the first file to match a given pattern, or an empty string (0 bytes) if there is no such file? The following sort of works:
ls *.iso | awk "{print \$1}" >filename
The file filename
ends up containing the name of the first .iso
file found or as empty if no such files were found. But if there are no such files, I also get the error message:
*.iso: no such file or directory
How to do this more cleanly? JIP | Talk 09:31, 9 October 2007 (UTC)
- How about
- ls -d *.iso 2>/dev/null | head -1
- or if you want it in a variable
- X=`ls -d *.iso 2>/dev/null | head -1`
- The "2>" makes stderr go somewhere (in Bourne shell; C shell has different syntax). "ls -d" in case there is a directory that matches. Weregerbil 09:45, 9 October 2007 (UTC)
- In a program I would do:
find -maxdepth 1 -name '*.iso' -type f | head -1 > filename
Thanks for the replies. I managed to make this shell script:
#!/bin/bash if [ "$1" != "" ] then filename=$1 else ls 2>/dev/null *.iso | awk "{print \$1}" >/tmp/iso_file_name filename=`cat /tmp/iso_file_name` fi if [ "$filename" != "" ] then xine dvd://`readlink -f $filename` else xine dvd:// fi
This will make Xine play an ISO image of a DVD if one is in the current directory or is given as a commandline parameter, otherwise it will make Xine play a real DVD. JIP | Talk 18:13, 9 October 2007 (UTC)
- Careful with the
awk
bit there. In all versions ofls
that I'm familiar with, if the output is directed to a pipe then you get one filename per line, so if there are multiple *.iso files, /tmp/iso_file_name will contain all of them. With thels
behavior I'm familiar with, I'd use this for the key bit:
ls *.iso 2>/dev/null | sed q
- (
sed q
is a way to select just the first line; usehead -1
if you prefer.)
- This also avoids the problem that if any of the filenames could contain spaces, $1 in the awk code would print only the first word of the name. The final $filename will still go wrong if there are spaces; you should put double quotes around it. --Anon, 22:46 UTC, October 10, 2007.
rename
[edit]![](http://upload.wikimedia.org/wikipedia/en/thumb/f/fb/Yes_check.svg/20px-Yes_check.svg.png)
Can someone logged in rename Viking: Battle of Asgard to Viking: Battle for Asgard. Thanks87.102.87.171 13:57, 9 October 2007 (UTC)
Thanks87.102.18.10 14:06, 9 October 2007 (UTC)
- It's done, but in future, note that this is not what the refdesk is for: the help desk might be more appropriate. Algebraist 14:08, 9 October 2007 (UTC)
Using a VPN for only SOME applications
[edit]I have a direct tcp/ip connection, and then VPN which also has TCP/IP. The VPN is required for work-related stuff, but it's (of course) slower than my home connection. The downside of this is that when I use the VPN, ALL my tcp/ip traffic is slower-- not just the few connections to the work intranet. If I connect to the work server over the vpn, it works. But if I try to watch Youtube in a different window, for example, it doesn't work, because it's trying to send the traffic THROUGH the VPN, instead of just sending it to me directly.
Is there a way I could specify only SOME applications access the internet through VPN? Like maybe have Opera be for the VPN, but Firefox be for the direct connection?
There must be some way-- it's a mega pain having to completely close my VPN connection every time I want to do anything that requires high bandwidth. --Wouldbewebmaster 15:12, 9 October 2007 (UTC)
- Would split tunneling work? That would enable you to access your intranet via the VPN and the internet through your home connection. Instructions for Windows are here. — Matt Eason (Talk • Contribs) 15:24, 9 October 2007 (UTC)
- Skimming the articles, it looks like those solutions decide whether to pass through VPN or not based on destination IP. Unfortunately that won't work, because I will need to connect to SOME websites through the VPN. So, for example, let's say we have site license that allows everyone at work to connect to a database like JSTOR. That traffic needs to go through the VPN, but traffic to Google does not. Since it's impossible to predict ahead of time which IPs are going to need to go through which connection, routing by ip won't work.
- However, I could do some port translation, so if there was a way to "Route by port" or "Route by application"-- those would work if possible. --Wouldbewebmaster 16:36, 9 October 2007 (UTC)
- How about just setting up a web proxy that always uses the VPN for connectivity? Then you could point one browser session at the proxy, and just use that browser for your VPN sites. --Sean 20:22, 9 October 2007 (UTC)
- That's be awesome if it's possible. Is there a way to set up a windows proxy so that it will send all it's traffic to the VPN? --Wouldbewebmaster 22:13, 9 October 2007 (UTC)
UK Television Graphics - Produced How?
[edit]I'm not sure if this should be in the computing or entertainments section but here goes! Does anyone know what software / computer systems are used for producing television graphics in the UK (Channel four / BBC etc, I know ITV stuff is farmed out)? The sort that you find on the news / documetaries and daytime television shows where the graphics have to be produced quickly but still at a very high quality. Somehow, I can't see someone fiddling around in Adobe After Effects for hours! Any information would be very gratefully received. I think Zaxwerks Invigorator is used extensively in the US but UK stuff has a much less sparkly and low key appearance. Weather reports change from hour to hour, again it has to be a pretty fast and easy to use system. Custom software maybe? Thanks. —Preceding unsigned comment added by 82.152.176.45 (talk) 18:40, 9 October 2007 (UTC)
- Chyron is a generic trademark for broadcast CG systems in general. Apparently, in the UK, they're called an Aston. --Mdwyer 19:50, 9 October 2007 (UTC)
- I haven't got a clue about titles for news reports and stuff, but the BBC use Weatherscape XT for their weather reports. — Matt Eason (Talk • Contribs) 19:57, 9 October 2007 (UTC)
- Back in the 90's, Quantel products had a huge presence in UK televisions. Today, I'm not so sure. Desktop computing speed has increased dramatically. I worked in TV news graphics in a major top 10 market for almost a decade. We did everything in Photoshop, After Effects, and ElectricImage. Many of the daily promos were edited with Avids and Final Cut Pro. Most on-air station graphics are reusable background elements with only the text being changed daily. The design company who made the original backgrounds, TVdb, used Lightwave for 3D elements, but everything was run through After Effects after that. --24.249.108.133 16:56, 10 October 2007 (UTC)