Jump to content

Wikipedia:Reference desk/Archives/Computing/2010 June 29

From Wikipedia, the free encyclopedia
Computing desk
< June 28 << May | June | Jul >> June 30 >
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.


June 29

[edit]

help with a simple shell script

[edit]
Resolved

Hi All,

I need help on a bash script. Here's what I need to do: I have this folder, which gets filled with .wav files (recordings) daily, and I want to segregate /move them into subdirectories based off a couple of factors.

This is basically what I want to do

pattern1 = ^OUT[0-9]{4}
pattern2 = ^g[0-9]{4}
default= any pattern not matched above, will be moved to a MISC folder (step 4)

  1. loop over each file in the directory (assuming /var/test as the working directory)
  2. create date dir (yyyymmdd -- current system date) if not exists
  3. if filename matches regex pattern1/2, create subfolder based on matching part (if does not exist) and move there (ex mv /var/test/OUT1234-32134381-31358438.wav -> /var/test/20100628/OUT1234/)
  4. if filename does not match regex pattern1/2, create subfolder 'misc'(if does not exist) and move there (ex mv /var/test/32134381-31358438.wav -> /var/test/20100628/misc/)


That is it basically... I hope someone can help me out. TIA PrinzPH (talk) 01:26, 29 June 2010 (UTC)[reply]

PS- I intend to put this in the crontab if it matter... PrinzPH (talk) 01:28, 29 June 2010 (UTC)[reply]

This is untested, and requires a relatively modern bash: —Korath (Talk) 01:51, 29 June 2010 (UTC)[reply]
#!/bin/bash
SOURCEDIR=/var/test
TARGETDIR=/var/test
PATTERN1='^OUT[0-9]{4}'
PATTERN2='^g[0-9]{4}'
TODAYDIR="$TARGETDIR/$(date +%Y%m%d)"
cd "$SOURCEDIR"
for i in *; do
    if [ -f "$i" ]; then
        if [[ "$i" =~ $PATTERN1 ]] || [[ "$i" =~ $PATTERN2 ]]; then
            THISDIR="$TODAYDIR/${BASH_REMATCH[0]}"
        else
            THISDIR="$TODAYDIR/misc"
        fi
        mkdir -p "$THISDIR"
        mv "$i" "$THISDIR/$i"
    fi
done
Thanks Korath! It's giving me an error though: Line [10], =~ binary expression expected? PrinzPH (talk) 03:26, 29 June 2010 (UTC)[reply]
what version of bash are you using? vesrion 3.0 seems to have no problem. Graeme Bartlett (talk) 04:22, 29 June 2010 (UTC)[reply]
bash --version tells me im running 3.2. But its My bad... apparently when I pasted the code over on putty, the PATTERNS inadvertently ended up with escaped braces and parenthesis. Thanks for the help! :) PrinzPH (talk) 05:53, 29 June 2010 (UTC)[reply]

Help With Simple Ruby Program

[edit]

Hi, I want to make a program in Ruby that will allow a friends computer to connect with mine, and then allow us to play tic tac toe. Unfortunately, I have no idea how to go about connecting the two computers, or how to manage input/output between them once they are connected, can anyone give me a few tips regarding this or point me to helpful, but simple, information on how to accomplish this? Thank you:) 66.202.66.78 (talk) 04:26, 29 June 2010 (UTC)[reply]

OP here, I wrote the above when very sleepy; essentially, I know how to use ruby, I'm just not very aquainted with networking stuff. Ultimately, I want to be able to write a program that when open on two computers, will designate a given computer as in "control", when that computer gives input to it's instance of the program it will put it into a given state, then transmit data over to the other program putting it in the same state and putting it in "control". I really only need to do this using a small number of computers, hence, I'm hoping that a fairly simple means can be used to accomplish it. Any help would be greatly appreciated:) 66.202.66.78 (talk) 09:41, 29 June 2010 (UTC)[reply]

You'd typically have one program, the server, that takes care of managing the game state, and several clients (the players) that connect to it to exchange move information. Such communication is usually done on a TCP socket, which most languages (including Ruby) have much the same API (essentially a wrapper around Berkeley sockets). An example of doing simple client-server communication over TCP is given in this IBM developerworks article - you're probably going to be doing something quite like the "building a ruby chat server" section. You'll have to decide what your application-layer protocol will look like (that is, the tic-tac-toe specific messages you're going to be sending back and forward over the wire) - I imagine the server will mostly send messages that mean "the board now looks like ---|-X-|-O-" and clients send messages that say "place my mark at position (1,2)". -- Finlay McWalterTalk 09:54, 29 June 2010 (UTC)[reply]

Gmail Password changes by itself!

[edit]

My pop gmail account, which worked OK a few minutes ago is giving problem. The Outlook Express client is asking for the password (this happens when password fed is not correct, but password is there alright ) Even if I fill up the correct password it does'nt help. The other gmail account is OK (as of now), what the hell is wrong ?  Jon Ascton  (talk) 07:15, 29 June 2010 (UTC)[reply]

In my experience with POP problems (unrelated to Gmail), when Outlook repeatedly ask for authentication or passwords, even when clearly correct, that usually means that it is having trouble connecting to the e-mail server for problems on the server's end. I would wait a little while ("a few minutes ago" is kind of quick to jump the gun) and try again. --Mr.98 (talk) 11:48, 29 June 2010 (UTC)[reply]
You are right, 98. Now it works all right... Jon Ascton  (talk) 01:05, 30 June 2010 (UTC)[reply]
Resolved
I ran into this problem recently, and it turned out to be because I was trying to send an executable file. Gmail doesn't allow executable files to be sent, but I guess whatever error message the server might have been sending, Outlook Express interpreted it to mean it should ask for my password. I finally discovered the problem by logging into the Gmail website and trying to send my message there. The website gave me a more useful error message. --12.25.104.8 (talk) 17:11, 29 June 2010 (UTC)[reply]

Userscript navigate to random page

[edit]
Resolved

A few days ago I asked if a greasemonkey userscript could scan a given webpage, pick a link on the page at random, and then navigate to that link. People said I would be too complicated, so I have a new question: Could a greasemonkey userscript randomly pick a url from a list of urls I specify, then navigate to it? For example:

http://example.com/123
http://example.com/456
http://example.com/789
http://example.com/abc
http://example.com/def
http://example.com/ghi

82.43.90.93 (talk) 10:32, 29 June 2010 (UTC)[reply]

Sure. Put them all in an array, get the size of the array, then generate a random number between 0 and the size of the array and replace your current location with that url. Example:
var urls = ["http://example.com/123", "http://example.com/456", "http://example.com/789",
            "http://example.com/abc", "http://example.com/def", "http://example.com/ghi"];

window.location.replace(urls[Math.floor(Math.random()*urls.length)]);
Honestly, if you wanted to, it would be fairly easy to do the same on any random webpage. Just scan for all "a" objects with hrefs, dump the href into an array, then select a new page to go to randomly using the same method. —ShadowRanger (talk|stalk) 15:32, 29 June 2010 (UTC)[reply]

Thanks! 82.43.90.93 (talk) 20:03, 29 June 2010 (UTC)[reply]

Using an ActiveX control module in C++

[edit]

Hello all,

I'm trying to figure out the usage of an SDK provided by a thermal camera company and unfortunately I'm entirely unclear on how to proceed. As of yet, internet searches have yielded no results, and the documentation for the SDK itself is rather sparse (at least, in my opinion; I have a decent amount of experience with the use of C++ for scientific computing purposes but no experience with ActiveX, so perhaps if I did the documentation would make more sense to me). At any rate, the SDK apparently takes the form of an "ActiveX Control Module". The SDK documentation lists three files: a license file (.lic), a binary load file (.ocx), and a type library (.tlb). I believe these form the SDK runtime needed to run applications made using the SDK, but I'm not sure. It also says that the ActiveX Control Module includes one interface (which it provides the name of) and gives the object name that is exposed to applications. The rest of the documentation focuses on object properties and methods.

So, my question is: given the information detailed above, how do I use this SDK in C++? Should I #include or #import certain files? Can I use this SDK in C++ IDEs that aren't from the Microsoft Visual Studio/C++ family (some sources I've seen seem to indicate that ActiveX controls can be integrated into C++ code in Visual Studio/C++ only)?

Any suggestions would be appreciated, as I've pretty much hit a wall. Thanks for taking the time to read this.

Hiram J. Hackenbacker (talk) 15:08, 29 June 2010 (UTC)[reply]

Not convinced this is going to be a helpful answer, but IIRC this is going to be hard. I've tried to do the same with .COM interfaces and in the end I gave up. There's lots of really complicated stuff to do with getting the interface handles that was too much hassle. When I was looking at it (quite a few years ago) I gave up and used Visual Basic 6, where you just import the .tlb and off you go. If you have access to VB6 I'd suggest trying with that. Failing that, I think it'd be lots easier with the latest Visual Studio. --Phil Holmes (talk) 15:42, 29 June 2010 (UTC)[reply]
Thanks for the response, Phil. I don't have access to Visual Basic 6, but I do have Visual Studio 2008. Is there a way to import the necessary files into VS 2008? I've tried adding some of the SDK files to a project, but they don't seem to be recognized as anything special (Visual Studio doesn't generate a wrapper class or anything like that when they're added). --Hiram J. Hackenbacker (talk) 23:48, 29 June 2010 (UTC)[reply]

JIRA SOAP question: getting issue comments

[edit]

I've been given the task to work on a external customer front-end to our company's internal JIRA system. The front-end uses SOAP to connect to JIRA. I've already run into one problem: if the front-end user logs in as a JIRA user who only has external user privileges to a project, he/she can only see his/her own comments to the project's issues, while the specification states that he/she should be able to see all comments to the issues. But it looks like the JIRA SOAP method getComments(String issueKey, String user) is actually implemented to only return the user's own comments if the user only has external user privileges. Is there a way around this? JIP | Talk 18:49, 29 June 2010 (UTC)[reply]

Computer too hot?

[edit]

I am in a hot room. A computer sensor - on the chip I think - says its temperature is 39 degrees centigrade. The HD temperature is 34 degrees centrigrade. Are these acceptable temperatures, or are they too hot? I have an old computer. Thanks 92.29.119.46 (talk) 18:55, 29 June 2010 (UTC)[reply]

These seem like acceptable temperatures to me. My CPU is 37C and my HDD 39C, and this is running at low usage in a moderately hot room. It's not even hot enough to make the computer start its main heatsink fan up. 82.43.90.93 (talk) 20:07, 29 June 2010 (UTC)[reply]
It has been widely known for decades that high temperatures reduce mean time between failure (i.e., increase the failure-rate), though a recent scholarly publication by Google Labs, Failure Trends in a Large Disk Drive Population, refutes that claim with modern data. This ACM report, Hard-disk drives: the good, the bad, and the ugly, the author states: "In my conversations with numerous engineers from all the major HDD manufacturers, none has said the temperature does not affect head reliability, but none has published a transfer function relating head life to time and temperature." Nimur (talk) 22:17, 29 June 2010 (UTC)[reply]
The temperature range around 40 is acceptable, if borderline. The problem occurs if it's maintaining a temperature around 45-50°C, as that usually means there's either not enough heat dissipation, causing the keyboard to feel warm (in addition to the degradation in laptop lifetime.) --Sigma 7 (talk) 18:11, 4 July 2010 (UTC)[reply]

Wireless question

[edit]

I have a Intel celeron M 380 1.6GHz laptop and have just had the internet for the first time. I have gone wireless and have to plug a 802.11g usb into my laptop. I keep losing the connection to the internet and wandered if it was because of a 'dodgy' usb. I have the laptop about 3 years. Should I buy a new 802.11g usb or another better one? <span style="font-size: smaller;" class="autosigned">—Preceding unsigned comment added by 78.150.70.39 (talk) 19:46, 29 June 2010 (UTC)[reply]

That's just one possibility. Check that your signal is strong (or move next to the wireless router). You should also check that the router is functioning correctly, and that your internet service provider is providing a reliable service. I have all of these problems from time to time. If your laptop has a network socket (RJ45, like a phone socket, bigger than USB), then you should try connecting direct to the router with a patch cable. Dbfirs 20:23, 29 June 2010 (UTC)[reply]
I used to have a wireless adapter and it was unreliable; that's how the cheap ones are. --Chemicalinterest (talk) 16:39, 30 June 2010 (UTC)[reply]

DMA to PIO

[edit]

Is an IDE drive (on a dell dimension) in XP that keeps reverting to PIO mode after a few weeks (reset to UDMA5 by uninstalling driver and rebooting) more likely to be a faulty HDD or faulty IDE controller? Would swapping the HDD and DVDR IDE cables on the mobo tell me if it was the IDE controller, or are both channels potentially controlled by the same faulty chipset? —Preceding unsigned comment added by 128.151.32.169 (talk) 21:13, 29 June 2010 (UTC)[reply]

Have you considered the possibility it's a faulty cable? That would be the first thing I would check. I'm presuming we're talking PATA here, in that case I'd also look carefully at the middle pins, there's one which can be damaged if you put the cable in the wrong way (yes there's also the plastic key but from my experience it's not that effective and it's still quite easy to insert it the wrong way) and it has a keyed socket (i.e. the pin hole is closed) so the pin is pushed in. If looks pushed in, try pulling it out again carefully. If it isn't, you may want to wriggle it slightly to see if it seems loose (e.g. if someone did this before and fixed it). This particular pin is used by the controller to decide whether to use UDMA so if it's damaged it can cause this problem Nil Einne (talk) 21:43, 29 June 2010 (UTC)[reply]

Software to display and sort a multi-column list?

[edit]

I'm looking for some freely available software that can display a multi-column list, and sort the whole list (keeping rows coherent) by just clicking on the top of a column. Rather than doing a lot of clicking to say its a global sort or having to highlight everything and so on.

The freeware 'List Squared' can do this, but is there any other software that can do the same, such as a spreadsheet or simple database, while offering more functions? I've alrerady done a lot of searching. Thanks 92.24.183.236 (talk) 23:16, 29 June 2010 (UTC)[reply]

Sorry if this is 1000x overkill, but since you did not rule it out, I'm obliged to suggest OpenOffice.org Calc, which is free but similar to Microsoft Excel. Comet Tuttle (talk) 00:05, 30 June 2010 (UTC)[reply]

The important thing is only requiring one click on the top of the column to sort everything (while keeping rows coherent) which I do not think Calc can do. 92.29.114.87 (talk) 09:38, 30 June 2010 (UTC)[reply]

Script to rename same-filename files while copying

[edit]

What would be the best language for a beginner to write a program or script that merges two file trees including combining folders with the same name, but automatically renames same-filename files to prevent overwriting? I've never found any software that can do this. Thanks 92.24.183.236 (talk) 23:24, 29 June 2010 (UTC)[reply]

cp with --backup. --194.197.235.240 (talk) 23:44, 29 June 2010 (UTC)[reply]
But if the task was to practice / learn scripting, you might find perl a good choice. It has very nice platform-independent file and directory management that is portable to dozens of different kinds systems. Nimur (talk) 00:17, 30 June 2010 (UTC)[reply]

cp could be perfect, but I presume it does not run under Windows? Is there a Windows version anywhere? Thanks 92.29.114.87 (talk) 09:41, 30 June 2010 (UTC)[reply]

I'd recommend cygwin, but you can get just a cp.exe from google. --194.197.235.240 (talk) 15:18, 30 June 2010 (UTC)[reply]