Jump to content

Wikipedia:Reference desk/Archives/Computing/2014 April 29

From Wikipedia, the free encyclopedia
Computing desk
< April 28 << Mar | April | May >> April 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.


April 29

[edit]

looking for 404s

[edit]

How can I use Python's standard library to send a HTTP request? I don't want to scrape the content or anything, I only want the response code. —Tamfang (talk) 02:58, 29 April 2014 (UTC)[reply]

Look at the examples for http.client (Python 3) or httplib (Python 2). You probably want the second example, which uses the HEAD method. -- BenRG (talk) 06:34, 29 April 2014 (UTC)[reply]
Hm. It works once and then the second request leads to an exception, ResponseNotReady. —Tamfang (talk) 08:15, 29 April 2014 (UTC)[reply]
If that second request is on the same HTTP connection, you need to finish processing the first request before you can issue a second one on the same (HTTP/1.1) connection:
#!/usr/bin/env python3

import http.client

conn = http.client.HTTPConnection("en.wikipedia.org")

conn.request('HEAD', '/') 
response = conn.getresponse()
print (response.status, response.reason)

response.read() # if you don't have this, the following request will fail with a ResponseNotReady

conn.request('HEAD', '/foo') 
response = conn.getresponse()
print (response.status, response.reason)
You're probably missing the response.read() call. -- Finlay McWalterTalk 10:25, 29 April 2014 (UTC)[reply]
Note that the documentation for getResponse() says "Note that you must have read the whole response before you can send a new request to the server". Even though the response for a HEAD is (well, should be) empty, a call to read() is still necessary to reset the connection's internal state. -- Finlay McWalterTalk 10:31, 29 April 2014 (UTC)[reply]
Resolved
Thanks, it's happy now. —Tamfang (talk) 06:55, 30 April 2014 (UTC)[reply]
If you use the requests module (which isn't part of the standard library, but can be trivially installed with pip) one can do the task like this:
       requests.head('http://en.wikipedia.org').status_code
-- Finlay McWalterTalk 14:46, 29 April 2014 (UTC)[reply]

Find intersecting time periods in less than O(n²) time?

[edit]

I ran into the following problem today at work. I have a list of time periods. I have to find all pairs of intersecting time periods from this array. Can this be done in less than O(n²) time? JIP | Talk 17:55, 29 April 2014 (UTC)[reply]

No, because in the worst case (all intervals overlapping) the size of the output is O(n²). But if you want something that's efficient when the overlap graph is sparse, this should work: add all starting and ending times to an array and sort it. Keep a set of currently active intervals, initially empty. For each time in order, remove the intervals ending at that time from the set, then for each interval starting at that time, add an overlap between that interval and every interval in the set, then add it to the set. -- BenRG (talk) 18:13, 29 April 2014 (UTC)[reply]
If you don't actually need a complete list of intersecting pairs, you may be able to do better, using an interval tree for example. -- BenRG (talk) 22:57, 29 April 2014 (UTC)[reply]
If you don't have too many time intervals, and the overlaps are small, you might consider something like a bin sort. In the first pass you would fill a table of dates with events which occurred on those dates:
1994 F
1995 F
1996 F, ELR
1997 F, ELR
1998 F, ELR, TKoQ
1999 F, ELR, TKoQ
2000 F, ELR, TKoQ
2001 F, ELR, TKoQ
2002 F, ELR, TKoQ
2003 F, ELR, TKoQ
2004 F, ELR, TKoQ
2005    ELR, TKoQ
2006         TKoQ
2007         TKoQ
2008         TKoQ
F    = Friends
ELR  = Everybody Loves Raymond
TKoQ = The King of Queens
The second pass would go through each date and look for more than one entry. Where 2 or more are found, every pair would be stored into a list of overlaps, perhaps using an insertion sort which would check for and refuse to store any duplicates.
This could work if the time resolution was days, or perhaps even seconds, if the total time range isn't too long (you wouldn't want trillions of time intervals to check). StuRat (talk) 00:33, 30 April 2014 (UTC)[reply]

computer programming for beginners !!

[edit]

Hi there , I really want to learn computer programming and i need you guys suggestion because by profession i am an accountant so i do not know much about programming and coding . So i was just wondering if some one can tell me from where to start and what is the easy language to understand the concept and every thing. please suggest me some books for beginners or any website to start with , i do not mind to learn in 2-3 years because its not my main profession .( I have full understanding computer apart from programming , a few years ago i start learning HTML , which was quite easy) any help will be greatly appreciated . thanks — Preceding unsigned comment added by 82.27.211.112 (talk) 18:31, 29 April 2014 (UTC)[reply]

Well, BASIC is designed for beginners (that's what the "B" stands for). Some would argue that bad habits you learn there might carry over if you learn more complex languages, but it doesn't sound like you plan to do that, in any case. COBOL is designed for business/accounting, so you might also consider that. (It's not used so much any more, though.) StuRat (talk) 19:00, 29 April 2014 (UTC)[reply]
Personally, I'd advise you to start with JavaScript - it's the programming language that runs in your web browser - and there are a ton of tutorials available online to help you to learn it. Both BASIC and COBOL are horribly obsolete - and having learned either of them, your very next job would be to unlearn all of the bad habits they'd teach you!
Javascript is a modern language that's in widespread use. Furthermore, you can write Javascript without anything more than the web browser you're using to read this post. Since you already know some HTML, you've already got a bunch of the skills you need to get started. You can begin by creating a text file in "Notepad" or some other text editor. The Javascript is everything between the <script> tags:
<script>
document.write("Hello World!");
</script>
Call it "test.html" (any name will do, so long as it ends in '.html') and you can run it by opening it in your browser, just like you do with your HTML. That's not a very interesting program (it just says "Hello world") - but it's easy to do something fancier:
<script>
for ( b = 99 ; b > 0 ; b-- )
{
document.write("<p>");
document.write(b);
document.write(" bottles of beer on the wall,<br>");
document.write(b);
document.write(" bottles of beer.<br>");
document.write("Take one down, pass it around,<br>");
document.write(b-1);
document.write(" bottles of beer on the wall.<br>");
}
</script>
There are literally hundreds of languages out there - and programmers get very passionate about which ones are their favorites - so I'm sure other people will give you different advice!
SteveBaker (talk) 20:39, 29 April 2014 (UTC)[reply]
I think you mean <br />. Sorry, I'm anal. A Quest For Knowledge (talk) 20:52, 29 April 2014 (UTC)[reply]
Only in XHTML. In HTML5, <br> is correct. AndrewWTaylor (talk) 21:06, 29 April 2014 (UTC)[reply]
Not really. Just because a browser is able to compensate for an error, doesn't necessarily mean that it wasn't an error. A Quest For Knowledge (talk) 21:24, 29 April 2014 (UTC)[reply]
NOT in HTML5. Please follow the link that Andrew kindly provided - which points to the formal HTML specification - which has an example that very specifically shows <br> without the '/'. It's not an error that the browser is ignoring - it's actually the correct way to do things. Anyway, this is off-topic and entirely irrelevant to the OP's question. SteveBaker (talk) 21:38, 29 April 2014 (UTC)[reply]
Yes, I agree that the spec allows for malformed XML and will allow mistakes as valid HTML. A Quest For Knowledge (talk) 22:21, 29 April 2014 (UTC)[reply]
If you expect HTML5 to be an extension of XML, then the problem is your expectations.
HTML traces it's roots not to XML, but to SGML which allowed stand-alone tags.
XML is a different language, that also descends separately from SGML, but disallowed the stand-alones.
Efforts are now underway to unite the two (Since HTML4), but historically they were never the same and they were never supposed to be the same. To suggest (as you have) that HTML5's backwards compatibility is "allowing malformed XML" is a mischaractization. You might as well say that C allows "malformed Java". APL (talk) 22:47, 29 April 2014 (UTC)[reply]
For what it's worth, <br/> has a totally different meaning in SGML than in XML. SGML permits <i/foo/ as a shorthand for <i>foo</i>, so <br/> is equivalent to <br>&gt; with the next / in the text acting as </br>. The failure of all major browsers to parse HTML according to the spec was used to advantage when XHTML was introduced, but strictly speaking HTML and XHTML were not compatible until HTML5. See here for more fun SGML facts. -- BenRG (talk) 23:55, 29 April 2014 (UTC)[reply]
No, I don't expect HTML5 to be an extension of XML, but that doesn't mean that one can't follow best practices. I note that the code above is using semi-colons. A Quest For Knowledge (talk) 05:34, 30 April 2014 (UTC)[reply]
If you go with Javascript sites like jsfiddle.net are an easy way to get started. Just type your code, press run and see the result. No need for external editors compilers etc.--Salix alba (talk): 22:02, 29 April 2014 (UTC)[reply]
What in JavaScript takes:
<script>
document.write("Hello World!");
</script>
would only require this in BASIC:
PRINT "Hello World!"
I think that's far easier to learn and remember. StuRat (talk) 22:36, 29 April 2014 (UTC)[reply]
  • You really haven't told us what you hope to be able to do with knowledge of some language. Yes, BASIC is a good learning tool, but probably not the best choice for trying to do something useful with your first language (unless it is 1989, and you are 12 ;). I would recommend learning a high level language, if you just want to learn how do a few useful tings as soon as possible. Python_(programming language) is highly praised and popular for a wide variety of tasks. (I am no expert in Python, but I was able to pick up bits that I needed for a small project very quickly). Here's the official beginner's guide [1], and here is a powerpoint presentation that might also help [2]. But really, if you want answers that aren't just guesses and opinions (or at least less so), you'll have to explain at least some of your goals. SemanticMantis (talk) 23:08, 29 April 2014 (UTC)[reply]
I recommend Python for several reasons, the most important being that when something goes wrong, Python usually aborts with an error traceback telling you where the problem happened so you can fix it. Many other popular languages, including Javascript, do something totally arbitrary to make the program keep going, such as throwing away any extra function arguments you passed, or throwing away the fractional part of a floating point number if you use it as an integer, or converting the string "abc" to the number 0. This makes the program fail later in some unrelated code, or finish but print a wrong answer, and it's generally very difficult to figure out where the real problem was.
On the whole Python is designed well by people who understand language design, while many other popular languages are inconsistent and poorly thought out by comparison. Python also sticks mostly to standard language concepts that you can retain when learning other languages, which is less true of Javascript. Finally, the standard Python distribution comes with exceptionally clear documentation, including a language tutorial. -- BenRG (talk) 23:23, 29 April 2014 (UTC)[reply]

Thanks guys for the help !!! I think i will come up with another question on JavaScript very soon. And yes i want to learn programming for business related things . I would like to know what kind of language is used in businesses like big stock exchange listed companies and for what purpose. Thanks anyway for your time. — Preceding unsigned comment added by 82.27.211.112 (talk) 00:28, 30 April 2014 (UTC)[reply]

Business communications stuff these days tends to be done in Java, which is a cumbersome language that is probably a hassle for beginners (not conceptually difficult, there's just a lot of crap to deal with). I'll second the suggestion of Python to start with. Realtime stuff like high-frequency trading often uses C (also not for beginners) but sometimes Java or alternatives. Mathematical finance such as risk analysis is sometimes done in Haskell which you might find interesting if you like math. 70.36.142.114 (talk) 01:16, 30 April 2014 (UTC)[reply]

  • If you are an accountant you are probably familiar with Microsoft Excel. This includes a version of the computer language Visual Basic, which is used to record macros, and can also be used to program Excel and other applications. The advantage of starting with this is that it will have immediate benefits in your daily work if you are using Excel, as well as teaching you the basics of programming. A very good way to start is to record a macro in Excel, then examine the code that is created, then try to modify it. Little by little you can learn to do more. The particular version of Visual Basic you learn this way is called Visual Basic for Applications, and is widely used in automating office tasks and processes. (Note that the Visual Basic is not the same as BASIC.) RomanSpa (talk) 06:00, 30 April 2014 (UTC)[reply]

Copying a hard drive

[edit]

Is it possible to copy a 3.2TB hard drive if one doesn't have access to the original computer on which it was used or to any information about the mother board?

What are the risks, if any, in trying to do this?

Thanks, Bielle (talk) 19:18, 29 April 2014 (UTC)[reply]

The motherboard is not really that important. What matters is the actual hard drive, i.e. its interface, file system and form factor. I have successfully copied an 20 GB hard drive from an Amiga 4000 to a Linux PC, even though the motherboards and operating systems are very different from each other. But the technology in the actual hard drive was the same, and I found that there is an "affs" extension to Linux that allows it to read Amiga disks. So, if you have got the actual 3.2 TB hard drive in your hands, and it has a recent interface (preferably SATA, but IDE should work too), and know what operating system the original computer ran, and you are in a position to muck around in your current computer's internals, there's nothing stopping you. There is the risk that you damage the hard drive or your current computer's motherboard, but if you know what you're doing, it is fairly small. JIP | Talk 19:29, 29 April 2014 (UTC)[reply]
You can buy an external hard drive enclosure. Then you don't have to open up or touch the inside of your newer computer. This is what I did when I was in the same situation. A Quest For Knowledge (talk) 18:12, 30 April 2014 (UTC)[reply]
Note that if you don't have USB3, eSATA, Firewire-800 (or higher) or GbE, any external connection is likely to be very very slow (with USB2 you should expect a 3.2TB HD to take a day or more). Of these GbE is the one I expect you're most likely to have but NAS adapters tend to be expensive. USB3 is second most likely, but only one a newer computer. (You can buy a USB3 PCI Express card but then you still have to open up your computer.) If your computer is older you may have eSATA or Firewire-800 if you're lucky, but probably not. It isn't that hard to adapt a SATA port to eSATA but again you'll need to open up your computer for that.
Of course a 3.2 TB hard disk is a little weird anyway. Hard disks tend to be 3 or 4 TB (by which I mean close to 3 trillion or 4 trillion bytes). Even if it's a RAID-0 array 1.5TB will still give 3TB although I think 800 GB did/do? exist so I guess if it has 4. Possibly SSDs may come in 3.2TB. And I guess a hybrid drive may have 3.2TB if the SSD portion doesn't duplicate the HD portion but that's the only other thing I can think of. I guess if you're using some sort of real RAID i.e. some redundancy you may end up with 3.2TB somehow, particularly if you're talking about binary TB. Looking online I also find some very old RAID-0 arrays with 8 400GB HDs [3]. But most of these RAID-0 arrays will already nbe somewhat external. Only the SSD and the hybrid drive if it exists may be internal.
Nil Einne (talk) 13:13, 1 May 2014 (UTC)[reply]
You could try to attach it to your internal motherboard SATA port 118.137.229.230 (talk) 10:15, 6 May 2014 (UTC)[reply]

I want to monitor all traffic on my network.

[edit]

I want to monitor all traffic on my home LAN. In particular, I want to know if I am using any mobile apps that aren't using SSL. My plan is to buy a second router, attach the first router to the second, with a Windows computer in-between. I'm not sure which software I want to run to capture this data, but hardware-wise this should work (or so I hope!). I'm more of a software guy than a hardware guy, so I appeal to my fellow Wikipedians: Does this sound like a valid plan? A Quest For Knowledge (talk) 21:03, 29 April 2014 (UTC)[reply]

Wireshark will monitor traffic in and out of a PC, not sure it could find traffic between a mobile and a router.--Salix alba (talk): 22:05, 29 April 2014 (UTC)[reply]
As most home ADSL/WiFi/Ethernet modems use hubs not routers, all Ethernet traffic coming into one port will go out on all ports. In the second modem, turn off its DHCP and DNS servers, set its HTTP configuration server to the a fixed address outside off the first one's pool (or at the high end if you can't do this). Then connect your MS-Windows machine to one of the router's ethernet ports, and it should see all the traffic between the two routers. CS Miller (talk) 10:48, 30 April 2014 (UTC)[reply]
Where I work we recently set up what is essentially a man in the middle so that we could monitor encrypted traffic in and out of our corporate network. Unless you do something like that, you won't be able to see the contents of encrypted traffic. If all you care about is whether it is encrypted or not, that won't be a problem. Vespine (talk) 22:46, 30 April 2014 (UTC)[reply]
Router? I have a laptop with a built-in network interface and an ExpressCard network interface. I have them bridged so I can connect in between a device and the network and trace with WireShark. Most devices today are not promiscuous, so tracking the whole network is a problem. --  Gadget850 talk 22:58, 30 April 2014 (UTC)[reply]