Wikipedia:Reference desk/Archives/Computing/2020 March 15

= March 15 =

Save a live stream on Facebook
Is it somehow possible to save a live stream on Facebook to disk as an .mp4 file or something, so it can be watched again later? J I P &#124; Talk 17:50, 15 March 2020 (UTC)
 * I guess you could record it in a screen recorder Thegooduser   Life Begins With a Smile :)  🍁 20:00, 15 March 2020 (UTC)

very simple database
Simple question: What is the easiest way to use a file as a Python dictionary?

One of my projects involves a time-consuming computation that could potentially be repeated many times, so I'd like to save (keyword,result) in a file. I don't think I've ever before had occasion to look for something in a file and then, if it's not there, generate it and add it to the file. —Tamfang (talk) 19:30, 15 March 2020 (UTC)


 * If it's modest size (where, given the size of modern computer memories, is still fairly vast) use shelve. If it's very large, sqlite3. -- Finlay McWalter··–·Talk 23:02, 15 March 2020 (UTC)


 * Well, I should say that the sqlite3 volume doesn't give you the dictionary syntax. It's pretty simple, but not thatsimple. -- Finlay McWalter··–·Talk 23:06, 15 March 2020 (UTC)


 * Thanks. —Tamfang (talk) 00:47, 16 March 2020 (UTC)

On second thought, my question was too narrow in one way, too broad in another. The algorithm that I have in mind only needs to read or write one entry for each run, and an entry can easily be expressed in plain text, e.g.
 * 17-DAS: 1 1 2 2 4 12 8 40 16 176 512 672 1088 2752 2176 5504 28784

so shelve may be overkill. Perhaps oddly, I've never had occasion to read from and write to the same file in one program! —Tamfang (talk) 00:47, 16 March 2020 (UTC)
 * Well you have to pick some storage format. I see there's a CSV module; I'd use that if you want the file to be human-readable. If you use a flat file format (as opposed to a database format like sqlite), to search for something in it you have to read through the file until either you get a hit or reach end-of-file. --47.146.63.87 (talk) 02:00, 16 March 2020 (UTC)


 * You really aren't going to get a simpler solution than shelve - it's just 2 more lines of code than the volatile python, and because shelve uses pickle, you can store Python data directly and it takes care of parsing:


 * -- Finlay McWalter··–·Talk 10:50, 16 March 2020 (UTC)


 * Yes, shelve is the easiest way. It basically pickles dictionary entries into a DBM database using Python's dbm module, last I looked.  If you're doing something serious you might be better off with something like sqlite, but it means you have to work a little bit harder to fit your data into SQL data.  There are of course various ORMs you can use, but they tend to cause more problems than they solve.  They are an example of abstraction inversion. 2601:648:8202:96B0:386A:A40C:EBB1:ACC0 (talk) 19:15, 17 March 2020 (UTC)

question

 * If someone has a corrupted bios, can it be fixed by removing the cmos battery? -- Thegooduser  Life Begins With a Smile :)  🍁 19:59, 15 March 2020 (UTC)
 * Obviously not. Only by re-programming the flash memory. Ruslik_ Zero 20:05, 15 March 2020 (UTC)
 * It depends on what is corrupted, and the age of the system. If it's the settings or time and date, then perhaps yes, removing the battery, if you have one, for 30 seconds or so will erase what's in there. But if it's the BIOS code itself that is corrupted, then no. BIOS code used to be stored in ROM; now it is in flash memory like the settings are as well. On a high-quality motherboard, there is a jumper to reset CMOS settings, you can short that instead of removing the battery for the same effect. Elizium23 (talk) 20:55, 15 March 2020 (UTC)
 * What if you changed the entire motherboard? Or replaced the bios chip? Thegooduser   Life Begins With a Smile :)  🍁 21:30, 15 March 2020 (UTC)
 * If you replaced the entire mainboard then it will depend on the replacement mainboard. It's a little weird that there will be 2 mainboards with corrupted BIOSes but if someone incorrectly flashed one, replaced it then did the same with the replacement then I guess it's possible. As for replacing the chip, if you replace it with a compatible type of chip which has been correctly flashed/programmed with the BIOS for the mainboard then you will fix the problem of a corrupted BIOS. This means you will either neither a suitable programmer for the chip, or someone else will need to have done it for you. In the past, hot flashing used to be common where someone would try removing the BIOS from a mainboard that was on, but frankly with AliExpress etc and cheap programmers, or the ability to get a BIOS chip pre-flashed for cheap, I'm not convinced it makes sense to do that anymore. Also if the mainboard does not have a socketed BIOS chip, replacing it is no trivial task. Note that all this assumes the the BIOS is actually corrupted. If it's simply the settings that are corrupted then replacing the BIOS chip makes no sense as mention by Elizium23. Likewise if the fault has some other cause. If a computer simply doesn't work, it doesn't make sense to assume BIOS corruption. Nil Einne (talk) 06:14, 16 March 2020 (UTC)


 * Please consider using a title with more content than "question", unless yours is the only question on this page. —Tamfang (talk) 00:35, 16 March 2020 (UTC)
 * Following on from 's replies, to the questioner: please describe the issue you're trying to resolve, if there is one. There might be some aspect you're missing that we can pick up on. The issue might not have anything to do with a BIOS. Remember, we have more experience with this stuff; that's why you came here. --47.146.63.87 (talk) 07:11, 16 March 2020 (UTC)

Recursive Binary Search Terminating Condition
I am attempting to make a recursive binary search algorithm in Java. What I have so far looks like this:

If the given element does not exist in the array, the method is supposed to return -1. I am struggling to determine what the terminating condition should be. I have tried   and every combination thereof. What is the correct condition to use that will avoid an infinite recursion, while not returning -1 when the value exists in the array? Yes, I am aware that there is a binary search method in the Arrays class, I am a student and I'm trying to learn how to do this myself. -- Puzzledvegetable Is it teatime already?  20:03, 15 March 2020 (UTC)
 * Problem Resolved Whoops, forgot to add and subtract from guess as is needed. low > high works just fine. -- Puzzledvegetable Is it teatime already?  20:16, 15 March 2020 (UTC)


 * I hope you realize the recursion is not necessary here and an iterative algorithm to narrow down the search area would do as well:
 * CiaPan (talk) 13:14, 18 March 2020 (UTC)
 * This was for a school assignment. We're learning about recursion, and we're required to include recursion in the program. Cheers -- Puzzledvegetable Is it teatime already?  16:31, 18 March 2020 (UTC)
 * Now I'd like to say 'change the school, then'. Teaching the recursion on problems which can be solved easier, shorter, faster and often safer with iteration is probably the reason why many programming beginners consider recursion difficult and obscure. Anyway, I don't say your approach is bad. Surely, it works, and it does not cause any substantial additional costs. What I tried to say is just that in this problem an iterative solution is a bit simpler than the recursive one. --CiaPan (talk) 17:24, 18 March 2020 (UTC)
 * Well, what would be a non-obscure problem where there recursion is the simplest answer? Merge sort or minimax are already a bit complex and easy to fail for reasons that have little to do with recursion.
 * IMO the binary search example is good: its only steps of importance are modifying the input for the subcall and testing the termination, which is what you want to teach in a recursion programming class. (That, plus the fact that the stack trace rarely tells you anything useful when infinite recursion occurs, a lesson the OP presumably learnt.) Tigraan Click here to contact me 10:57, 19 March 2020 (UTC)
 * IMO the binary search example is good: its only steps of importance are modifying the input for the subcall and testing the termination, which is what you want to teach in a recursion programming class. (That, plus the fact that the stack trace rarely tells you anything useful when infinite recursion occurs, a lesson the OP presumably learnt.) Tigraan Click here to contact me 10:57, 19 March 2020 (UTC)