Jump to content

Wikipedia:Reference desk/Computing: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Scsbot (talk | contribs)
edited by robot: adding date header(s)
Line 189: Line 189:


What exactly in this program do I actually need to fix in order to eliminate this error message--and just how exactly do I fix the relevant part of this computer program of mine? Any thoughts on this? [[User:Futurist110|Futurist110]] ([[User talk:Futurist110|talk]]) 22:53, 2 March 2020 (UTC)
What exactly in this program do I actually need to fix in order to eliminate this error message--and just how exactly do I fix the relevant part of this computer program of mine? Any thoughts on this? [[User:Futurist110|Futurist110]] ([[User talk:Futurist110|talk]]) 22:53, 2 March 2020 (UTC)


*It looks like you are passing an empty string to the int() function, maybe because of badly formatted input data. Rather than try to debug it for you, I'll suggest a way to debug it yourself: put try/except around the line where the error is happening, and print the relevant values in the event that the exception triggers. So in this case, replace line 41 with:
<syntaxhighlight lang="python">
try:
numSec.append([int(lyst[i][0])*3600, int(lyst[i][1])*60, int(lyst[i][2])])
except ValueError as e:
print (e, i, list[i])
raise
</syntaxhighlight>

Use the printed info to either figure out what is wrong, or figure out what other info you need to diagnose the error, then modify the program again to get the additional info. It will often take quite a few iterations of that to diagnose a bug. Debuggers can avoid some of that, but print-based tracing is something every programmer has to do some of the time.

Unrelated: I notice in your findMean function, you sort the list unnecessarily. I'd have just written sum(list) / len(list). [[Special:Contributions/173.228.123.39|173.228.123.39]] ([[User talk:173.228.123.39|talk]]) 01:58, 3 March 2020 (UTC)


= March 3 =
= March 3 =

Revision as of 01:58, 3 March 2020

Welcome to the computing section
of the Wikipedia reference desk.
Select a section:
Want a faster answer?

Main page: Help searching Wikipedia

   

How can I get my question answered?

  • Select the section of the desk that best fits the general topic of your question (see the navigation column to the right).
  • Post your question to only one section, providing a short header that gives the topic of your question.
  • Type '~~~~' (that is, four tilde characters) at the end – this signs and dates your contribution so we know who wrote what and when.
  • Don't post personal contact information – it will be removed. Any answers will be provided here.
  • Please be as specific as possible, and include all relevant context – the usefulness of answers may depend on the context.
  • Note:
    • We don't answer (and may remove) questions that require medical diagnosis or legal advice.
    • We don't answer requests for opinions, predictions or debate.
    • We don't do your homework for you, though we'll help you past the stuck point.
    • We don't conduct original research or provide a free source of ideas, but we'll help you find information you need.



How do I answer a question?

Main page: Wikipedia:Reference desk/Guidelines

  • The best answers address the question directly, and back up facts with wikilinks and links to sources. Do not edit others' comments and do not give any medical or legal advice.
See also:


February 24

Download all images on webpage

I'm using a long, long webpage containing around 300 images, each one on a new line. They're the pages of a book so the order is important. Is there a tool I can use to download them all at once but keep them in order (eg by naming them 'image1', 'image2' etc) so I can then form them into a PDF that reads like the book? Most of the 'download all images' add-ons I've found just give arbitrary names which isn't helpful. Amisom (talk) 07:40, 24 February 2020 (UTC)[reply]

If it's someone else's site, this is called web scraping and there's no one-size-fits-all method or tool. You often end up developing a custom script, though that is pretty quick once you've done a few. It is harder for some sites than others. Can you say what site it is? 2602:24A:DE47:B270:A096:24F4:F986:C62A (talk) 09:09, 24 February 2020 (UTC)[reply]
It seems odd that a scraper would rename the files, though. It's very likely that the pages are already named in the correct order, even if the names themselves might seem a little weird, so it seems the easiest solution would be to find the option that's causing the renaming and uncheck it. Matt Deres (talk) 14:33, 24 February 2020 (UTC)[reply]
As the IP said, it's certainly doable - if the web browser can display them in order, then they can be retrieved in order. It might be worth to take a look at the web sites source code or just at the URLs of some of the images. Often one can then guess the pattern and just use wget or cURL to grab everything. Of course, with modern web pages importing about a billion frameworks to display "Hellp World", it may be more difficult... --Stephan Schulz (talk) 14:53, 24 February 2020 (UTC)[reply]
"Hellp World" indeed! (:  --Lambiam 16:57, 24 February 2020 (UTC)[reply]
Is there such a thing as a Freudian typo? ;-). --Stephan Schulz (talk) 17:20, 24 February 2020 (UTC)[reply]
  • This is a programming task, and not a difficult one (It's the sort of thing I'd teach as an example in a 'Learning Python' course for older schoolkids). There are three broad approaches:
  1. Find a gadget that already does it, as a command-line utility, such as wget.
  2. Find a browser extension that does it. Often more convenient. There are many of these and they're hard to keep up with. "DownThemAll" [1] is one I've used for FireFox.
  3. Write some code. In a modern language (like Python) there are many pre-existing modules to do the hard work of this, even things like Beautiful Soup which will handle awful markup. There are also many examples of how to do this, pre-written for almost exactly what you need. This will be the most flexible way, especially for a repeated task, and may not require as much effort as you think. Andy Dingley (talk) 17:29, 24 February 2020 (UTC)[reply]
When you say they give "arbitrary names", I suspect those are the actual file names the Web page uses, meaning the downloaders aren't renaming them. Many Web sites, especially ones that are dynamically generated, can use things like Base16 encoding for filenames; if the file names are some alphanumeric gibberish, that's why. To find out, try right-clicking on one of the images in your browser and looking for something like "View Image Info" (that's what it's called in Firefox). Or, you can look at the HTML for the page with the "View Source" option. If this is the case, then you actually want the files renamed. Some download managers can do things like name each file in sequential order ("1.png, 2.png, 3.png"). You have to look at the documentation for whatever tool you use to figure out how. Also, not important, but making a PDF will just give a PDF with the image files embedded. This seems kind of pointless to me, although I suppose it could be useful in some cases, like if you have reader software you like using and it only supports formats like PDF. --47.146.63.87 (talk) 20:29, 24 February 2020 (UTC)[reply]

Registry entry

I consider Kasperskiy a Russian spy malware. At one point I helped a friend of mine to get rid of it by expunging the registry, but he installed it previously since it was offered for free. Spyware is always free as we know. Today, much time later I decided to check if my registry might have a trace of it. My OS is Win 10 Pro. This is what I found:

HKEY_CURRENT_USER\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\Kasperskiy-antivirus
HKEY_CURRENT_USER\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\EscDomains\Kasperskiy-antivirus

Is there any harm of having it there? That Domain section has hundreds of domain names, including variations of my favorite SpyBot Search and Destroy, like spybotcom.com, etc.

Thanks, - AboutFace 22 (talk) 18:29, 24 February 2020 (UTC)[reply]

For the allegations against Kaspersky Lab, see Kaspersky bans and allegations of Russian government ties. As long as not more specific information is supplied, I am far from convinced by the spyware allegations. The registry entry looks suspect to me insofar as it uses the spelling "Kasperskiy" while the company itself uses the spelling .  --Lambiam 19:50, 24 February 2020 (UTC)[reply]
including variations of my favorite SpyBot Search and Destroy, like spybotcom.com… Looks like you have or had malware on your computer. Those entries are Internet Explorer/Microsoft Edge's list of "Trusted Sites", which are allowed to bypass the browser's security controls. Those domains are "fake" domain names meant to look like legitimate ones (hence also the "Kasperskiy" misspelling). Malware would have put them in that list as part of hijacking the browser. If you're confident they're from a past infection that was removed, just delete the entries. It's always good practice to make a backup before editing the Registry; you can do this from within Registry Editor. --47.146.63.87 (talk) 22:52, 24 February 2020 (UTC)[reply]

Then why to remove only Kaspersky. Look at the small part of my registry:

Registry Entries

What shall I do? There are hundreds of them. AboutFace 22 (talk) 23:11, 24 February 2020 (UTC)[reply]

Yes I also have the kasperskiy-antivir.com entry. It's not Kaspersky's real domain, it's a fake download page to trick people who don't know which spelling is used by the company. The registry key containing all these malware domains is a list of stuff that goes in IE's trusted and untrusted zones. These are standard untrusted zone entries and contain a 0x04 value meaning that the domain in the subkey belongs to the untrusted zone. To put it in clearer's terms, it's something between an ad blocker and a hosts file for IE's internal use, and it's been in Windows since at least XP. Removing these entries might leave you open to malware but if you don't use IE then it doesn't really matter if you remove it or not. Lastly a disclaimer: if you consider Kaspersky Russian government spyware, it shouldn't come to you as a huge surprise that many consider Windows 10 commercial spyware and adware (which I think is in terms of dollars at least, a lot worse than getting spied on by a country you'll probably never even visit). 93.136.117.148 (talk) 00:01, 25 February 2020 (UTC)[reply]
Ugh, okay, I jumped to a conclusion. I assumed IE/Edge did something similar to other browsers for malware protection, downloading an internal list. Thanks for correcting. --47.146.63.87 (talk) 06:27, 25 February 2020 (UTC)[reply]

Registering and maintaining a domain name costs money, sometimes a lot of money. Who is paying for all those untrusted domains? AboutFace 22 (talk) 16:15, 25 February 2020 (UTC)[reply]

Not for a .com. Anyone doing this sort of stuff is probably paying less than $1 a year. So depending on what they're being used for, one successful scam victim can probably pay for tens to thousands of domains or maybe even more. Nil Einne (talk) 07:35, 26 February 2020 (UTC)[reply]

February 25

Putting an App Icon on the Home Screen

I have a Samsung Galaxy J7, running Android version 8.1.0. What I want to do is to add another application icon to the home screen. The icon for it is currently in the Applications window that I can open by clicking on the Applications window icon, but I want to display it on a page of the home screen. At this time the application is Spotify, and I want to be able to launch Spotify and Maps conveniently at the same time. However, I think that my question is more general, and is how to put an icon for an application on the home screen that is installed but isn't on the home screen. Robert McClenon (talk) 01:15, 25 February 2020 (UTC)[reply]

You should be able to move the app to your home screen by dragging it. Long-press if necessary or tap, hold, and move your finger; the home screen(s) should appear and allow you to release your finger and drop the app onto it. Elizium23 (talk) 01:18, 25 February 2020 (UTC)[reply]
Yep, long press and hold the icon in the start menu (I guess that's what's called the Applications window). After a second or two the home screens should appear in the background, then you can drag the icon where you want it. You can also long press an empty space on the home screen and you'll get a popup menu allowing you to add stuff like app shortcuts. 93.136.117.148 (talk) 02:29, 25 February 2020 (UTC)[reply]
Long-press (hold down) was it. Thanks. Robert McClenon (talk) 15:14, 26 February 2020 (UTC)[reply]

February 26

Brother DCP-7030 driver for ubuntu

After following the installation instructions over and over again, I can't seem to install it Thegooduser Life Begins With a Smile :) 🍁 00:51, 26 February 2020 (UTC)[reply]

Problems using the wikipedia dump bz2 file

Please see this post on the Miscellaneous desk. 2606:A000:1126:28D:8095:BB24:F64A:E5FC (talk) 03:21, 26 February 2020 (UTC)[reply]

February 27

Opening different URLs using different browsers in Windows 10

In Windows 10, is there an easy way to implement a solution so that different URLs can be opened using different browsers based on configured rules? This only needs to be done when URLs are opened using the default handler. — Preceding unsigned comment added by 134.242.92.97 (talk) 22:41, 27 February 2020 (UTC)[reply]

You can read about some options here. Ruslik_Zero 20:25, 1 March 2020 (UTC)[reply]

February 28

MediaWiki back up

Sorry, this is a run on from my previous question here (now archived) but I wondered if there was a relatively simple way of doing the above? I mean, I'd really like the answer to be something in the realms of "Yeah, copy the folders to an external" or something; but things are rarely that easy  :) and i'm prepared to not understand the answer. But any advice would be greatly appreciated! Happy Friday, all. ——SN54129 11:04, 28 February 2020 (UTC)[reply]

Is this (mw:Manual:Backing up a wiki) any use? - X201 (talk) 11:29, 28 February 2020 (UTC)[reply]
Well, yes, X201, thanks  :) it rather says complicatedly what I hoped could be spelt out more simply! Have a good weekend! ——SN54129 12:00, 29 February 2020 (UTC)[reply]

February 29

Short descriptions, Wikidata, and SQL/SPARQL

Hi, I would like to know how to search for items on Wikidata with descriptions longer than, say, 150 characters; I've noticed that the very long ones tend to be unsuitable for use as short descriptions on Wikipedia. (example example) I've tried writing something based on the quarry query for descriptions of length 1, but had absolutely no success. (My knowledge of SQL is very minimal.) I would be grateful for any assistance or pointers. Cheers, gnu57 15:34, 29 February 2020 (UTC)[reply]

Doesn't LENGTH(term_text) > 150 work? 2602:24A:DE47:B270:A096:24F4:F986:C62A (talk) 00:49, 1 March 2020 (UTC)[reply]
I tried that a while ago; when I submit the query, it runs for a long time and eventually times out without completing. Cheers, gnu57 01:04, 1 March 2020 (UTC)[reply]
There is probably no index on the term length, i.e. it's doing a linear scan. Your options: 1) create index or ask someone to create one (it will be even slower than the linear scan, but will allow future such queries to run fast); 2) get your timeout increased or get someone with higher limits to run the query for you; or 3) download the db to your own machine and run the queries on your own db instance. The last is the best if you want to muck with the data a lot, but of course it's more work and takes resources (your own machine or VM, basically). 173.228.123.39 (talk) 00:56, 2 March 2020 (UTC)[reply]

March 2

(Web) development novice

I'm a CS dropout with a bit of programming experience but not much. It's also been years since I coded anything. I consider myself pretty good at working out the logic side of things but I usually get stuck when trying to figure out the best way to do something or if there is a standard way of achieving a certain result. I want to get back into coding by starting a web development project and already I am unsure how to achieve a desired result.

A basic website usually has for example a logo/home page link, a navigation bar, a footer, and the content of the particular page. So a basic way of doing this would be to include the logo, navigation bar, and footer on each page. However, for a (dynamic) site that is constantly adding content this seems less than ideal.

So I was thinking maybe of having a template php page which includes the logo, nav bar, etc. but then would also have some php code that would include the required content.

I don't want to be given the answer (at least for now) as I'd rather figure it out for myself but am I along the right lines? If not maybe a bit of a nudge in the right direction. What sort of problems would this approach present?

--Polyknot (talk) 05:33, 2 March 2020 (UTC)[reply]

Are you using a PHP-dependent content management framework or system such as Drupal or WordPress? If not, than now is perhaps a good time to switch to Django/Python. The learning curve is not very steep, there are excellent tutorials, the community is very helpful to novices, and in the end you will probably enjoy the greater flexibility.  --Lambiam 08:01, 2 March 2020 (UTC)[reply]
You can use the include function in PHP to include whatever you like. So, you can create a file that makes the navigation bar, such as "nav.inc". Then, include it where you want it: include("nav.inc"); You can have files that include other files. For example, all the stuff that comes before the main contant might be in a file named "top.inc". That file includes the header, styles, css, title bar, nav, etc... Then, everything after the content might be in "bottom.inc". So, your web page becomes include("top.inc"); include("mycontent.inc"); include("bottom.inc");. The content one is where you handle dynamic content. Normally, you query a database, get content, and format it properly. But, you could just as well include a text file. Warning: You will find zealots that claim switching from one programming to another programming language will solve all your problems, including obesity, acne, and erectile dysfunction. The rule is always the same: The language you know is the best language to use. 135.84.167.41 (talk) 12:41, 2 March 2020 (UTC)[reply]

How do I eliminate this standard error?

Here is a kata/programming practice exercise that I recently did:

https://www.codewars.com/kata/55b3425df71c1201a800009c/train/python

Here is my own solution to this kata:

def findMedian(list):
    list = sorted(list)
    length = len(list)
    if length % 2 == 1:
        halfLen = int(length / 2)
        median = list[halfLen]
    elif length % 2 == 0:
        num1 = int(length / 2) - 1
        num2 = int(length / 2)
        median = int((list[num1] + list[num2]) / 2)
    return median

def findRange(list):
    list = sorted(list)
    range = list[-1] - list[0]
    return range

def findMean(list):
    list = sorted(list)
    sum = 0
    for i in range(0,len(list)):
        sum += list[i]
        i += 1
    mean = sum/len(list)
    return int(mean)

def convertFormat(num):
    num = int(num)
    hours = int(num / 3600)
    minutes = int((num % 3600) / 60)
    seconds = ((num % 3600) % 60)
    return format(hours,'02d')+"|"+format(minutes,'02d')+"|"+format(seconds,'02d')

def stat(strg):
    lisst = strg.split(', ')
    lyst = []
    for item in lisst:
        lyst.append(item.split('|'))
    numSec = []
    for i in range(0,len(lyst)):
        numSec.append([int(lyst[i][0])*3600, int(lyst[i][1])*60, int(lyst[i][2])])
    numSecTotal = []
    for i in range(0,len(numSec)):
        numSecTotal.append(numSec[i][0]+numSec[i][1]+numSec[i][2])
    numSecTotal = sorted(numSecTotal)
    formattedMedian = convertFormat(findMedian(numSecTotal))
    formattedRange = convertFormat(findRange(numSecTotal))+" "
    formattedMean = convertFormat(findMean(numSecTotal))+" "
    str = "Range: "+formattedRange+"Average: "+formattedMean+"Median: "+formattedMedian
    return str

This website actually accepted my solution as valid--which is why this solution of mine (by Futurist110, aka myself) is visible here:

https://www.codewars.com/kata/55b3425df71c1201a800009c/solutions/python/all/newest

However, when I clicked on the "Train Again" button and attempted to once again submit this solution with minor modifications, I got this error message in spite of my program passing all of the tests for it on this website:

 STDERR
Traceback (most recent call last):
  File "main.py", line 75, in <module>
    randomTests()
  File "main.py", line 73, in randomTests
    test.assert_equals(stat(a), stat1221(a))
  File "/home/codewarrior/solution.py", line 41, in stat
    numSec.append([int(lyst[i][0])*3600, int(lyst[i][1])*60, int(lyst[i][2])])
ValueError: invalid literal for int() with base 10: ''

What exactly in this program do I actually need to fix in order to eliminate this error message--and just how exactly do I fix the relevant part of this computer program of mine? Any thoughts on this? Futurist110 (talk) 22:53, 2 March 2020 (UTC)[reply]


  • It looks like you are passing an empty string to the int() function, maybe because of badly formatted input data. Rather than try to debug it for you, I'll suggest a way to debug it yourself: put try/except around the line where the error is happening, and print the relevant values in the event that the exception triggers. So in this case, replace line 41 with:
try:
    numSec.append([int(lyst[i][0])*3600, int(lyst[i][1])*60, int(lyst[i][2])])
except ValueError as e:
    print (e, i, list[i])
    raise

Use the printed info to either figure out what is wrong, or figure out what other info you need to diagnose the error, then modify the program again to get the additional info. It will often take quite a few iterations of that to diagnose a bug. Debuggers can avoid some of that, but print-based tracing is something every programmer has to do some of the time.

Unrelated: I notice in your findMean function, you sort the list unnecessarily. I'd have just written sum(list) / len(list). 173.228.123.39 (talk) 01:58, 3 March 2020 (UTC)[reply]

March 3