python – In unit testing, how can I avoid chasing my own tail when testing against complicated return values?

Sometimes there are functions that naturally produce complicated results and cannot be divided any further e.g. in the area of signal processing. How can I test against return values of such a method without using test doubles which are complicated enough to actually deserve their own tests? In the following example I want to test functions that read and write objects from/to disk. The test functions assert against return values and therefore binary data must somehow be provided i.e. hard-coded, generated, loaded from disc etc.

def read(filename):
    """Read any compatible my_package object from disk."""
        # read and do complicated decoding
    return obj_dict

def write(filename, compress=False, **objs):
    """Write any compatible my_package object to disk."""
    # write and do complicated encoding

@patch('my_package.iolib')
def test_read(mock_iolib):
        mock_iolib.read.side_effect = lambda x: stub_binary(x)
        # assert that read objects equal expected objects

@patch('my_package.iolib')
def test_read(mock_iolib):
        mock_iolib.write.side_effect = lambda x: stub_binary(x)
        # assert that written objects equal expected objects

With stub_binary returning a hard-coded bytestring:

def stub_binary(x):
        if x == 'ndarray':
                return (
                b'x93NUMPYx01x00vx00{"descr": "<f8", "fortran_order": False, '
            b'"shape": (1, 3), }                                             '
            b'             nx00x00x00x00x00x00xf0?x00x00x00x00x00'
            b'x00x00@x00x00x00x00x00x00x08@')
        elif #...

Or reading a bytestring from file that was generated with my_package.write:

def stub_binary(x):
        if x == 'ndarray':
                with open(gen_data, 'rb') as f:
                        return f.read()
        # ...

Or mimic or using my_package.read:

def stub_binary(x):
        if x == 'ndarray':
                return my_package.read(path_to_file_for_x)
        # ...used in test_write

Or mimic or using my_package.write:

def stub_binary(x):
        if x == 'ndarray':
                my_package.write(memfile)
                return memfile
        # ...used in test_read

Similar problems arise when dealing with audio/image/signal processing functions that return big and complicated data, escpecially when transforming and inverse transforming. How can I approach these kind of problems without chasing my own tail with writing useles tests?

canon – How to avoid clogging / drying out of an inkjet printer if it is not used over a longer period of time?

I am planning to purchase an inkjet printer: either an a Canon imagePrograf Pro-1000 or an Epson SureColor SC-P900.

During the first few weeks I will have some printing jobs. But then the printer will not be used for 6 to 12 months.

  1. During the shutdown time it will probably not possible to supply the printer with power. How do I avoid the drying out or clogging of the print head and the ink system?

  2. If the printer can be powered, do they automatically clean themself from time to time?

I checked in the manuals and on the internet but I did not find any information on this.

Thanks.

google sheets – Avoid decimal point when integer

Is there a way to use a custom number format in Google Sheets so that decimal point will be visible only when decimals are present?
For instance

9
8,2
10

Is there a newer solution about achieving this without a helper column?

While looking for a solution to the original question, a glitch was discovered in the sheet (Link here):

enter image description here

column AJ is formatted with number format 0.#, as this was obtained running the following Google Apps Script:

function test(){ 
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); 
var cell = sheet.getRange("AJ7"); 
Logger.log(cell.getNumberFormat());} 

Values appear without decimals, when no decimals are present, however if this format is manually applied, it will show integer values with comma. How can it be? Locale is set to Italy, timezone GMT+1.

security – As the Bitcoin price skyrockets, how to avoid getting malware through freeware/FOSS software’s updates?

We have a situation now where the vast majority of software I have installed on my computer (Windows 10, since there are no other supported versions of Windows) are either aging one-man freeware applications which haven’t changed almost at all for the last 20 years, or open source projects of typically similar stagnation. I can sense the frustration from both of these groups, many of which have entirely abandoned/dropped their projects. Countless are in a seemingly perpetual state of very slowly dying, and all too many are what can best be described as “undead”.

As these probably honest idealists watch the years go by with essentially no donations coming in, nobody buying their commercial licenses/support, and big companies just stealing their work without giving any credit and with no regard to the license, then make tons of money from it, and especially now with the Bitcoin price ever increasing to crazy new heights, I can very much imagine that even the most good-hearted but struggling, disillusioned freeware/FOSS developer at the very least has the recurring thought:

Ah! Screw this! Eight million unassigned/unresolved bugs, zero donations for the last 15 years, not one license purchased by any company ever, nothing but demands and rude users… and XYZ has just used my software to make a fortune… I’ve had it! I’m going to push a piece of malware in the next update so that all those bastards will get all their wallet.dat files uploaded to me, of course using proxies! Hah! I estimate that at least a few of them will own Bitcoin and have Bitcoin Core running. And those who don’t won’t ever notice anything anyway! Bwahahahaha! Within a few weeks, I’ll be relaxing on my own tropical island, drinking colorful drinks at the beach! No more slaving away at this keyboard for nothing! You’ll see! Just you wait… rubs hands with a twisted facial expression

You may say that they have a reputation to uphold and people who do this tend to be very honest and would never seriously get tempted to steal. Sure. But it’s still very possible. The more the price goes up, the more scared I become to just see “0.00” balance in Bitcoin Core the next time I look at it. Let’s face it: there is zero security in practice. I’m trusting complete strangers every second my PC is powered on to not steal from me. There is no possible reasonable way for me or anyone else to possibly somehow “go through” others’ programs, if they even provide source at all, and then locally compile everything. It just isn’t reality, even for the most hardcore geeks.

They could even have planted the malware long ago, but are actively waiting until the day Bitcoin is worth over X amount to go through with this. Perhaps they already have detected how many of their users have Bitcoin wallets on their machines, and how much they contain. They can precisely calculate the risk in advance and decide that it’s finally worth it to go through with it. And if ever confronted, they can just give the same excuse that all these companies always do when they leak customer data: it was “a bug/technical glitch/we got hacked/we take your privacy very seriously blablabla…” It’s not like the “gone evil” developer who does this is going to be standing with a black cape, twirling his moustache while mocking his victim with clever one-liners. He would just be gone, just like our coins. They would deny any involvement, even if it’s known exactly who runs the software project or is primarily responsible. (Which is not always the case.)

Even Microsoft themselves (or told by the government) could decide to just have me pay a little “Bitcoin tax” with their next Windows update. And then claim that it was a bug, or that I’m lying. Have you ever tried to get in touch with anyone at Microsoft who isn’t a robot, and who actually understands a single word of English? It’s impossible, even for a developer. Nobody would ever hear me complain, and even less would believe me.

Here’s the problems I have with all predicted solutions:

  • “Use a dedicated computer (maybe Raspberry Pi) running Linux just for Bitcoin Core stuff.” — Very impractical. I don’t have the physical space, plus it would be a horrible pain to actually make any transactions/use it. They also make it impossible in practice to encrypt Linux running on a RPI. (Long story…)
  • “Use a hardware wallet.” — Costs money to buy, difficult to get home, are not as secure as one would think, also very impractical (though less so), and most of all: it is basically hard proof to the authorities (and burglars) that you own Bitcoin. Plus the recent leak of home addresses and other personal data of tons of customers of Ledger makes it impossible for me to ever trust that company…
  • “Print them onto paper and keep the papers in a fireproof safe.” — Again a massive problem with authorities, and once seized, there is zero security since the private keys are right there on the paper. Or if the fireproof safe isn’t as fireproof as expected…
  • “Let a third party store your coins for you! Trust the cloud! Web 3.0! Just log in with your Google account!” — This one doesn’t even deserve a comment…
  • “Use anti-virus and keep your software and OS patched blabla…” — The issue is not trusting those… both in the sense that they might be malicious themselves, or through incompetence allow others to break in to my system via their broken software.
  • “Use an app in your phone.” — Please… don’t…
  • “Use Quebes OS.” — Well, I tried, but it doesn’t even install on my hardware. My experience with that OS is that it’s very frustrating to use, when it does run. Perfect in theory, though. I wish something like that “really” existed, and ran on secure hardware.
  • “Just be careful.” — This is nonsensical advice. There is no possible way to know or prevent if any given EXE is going to do something bad when it’s running unhindered on my host OS. “Being careful” means nothing if, at the end of the day, you are still required to execute a program on your machine which is not completely sandboxed. And sandboxing is apparently the most difficult problem ever to exist, since nobody ever manages to do it properly…
  • “Use a VM!” — Well, I do, for some things which I really don’t trust on my main OS. However, this is extremely cumbersome and tiresome, and I can’t run everything in a VM. I simply have to trust several entities on my host OS which may at any moment decide to “go rogue”. Unless there is something which I haven’t heard of which solves everything neatly and perfectly…

What to do? If I feel this scared at $40k USD Bitcoin, what kind of nervous wreck will I be when it reaches $1,000,000 per Bitcoin?

I just don’t see any solution. I’ve through extremely long and hard about this and tried so many things, both in reality and inside my head, and none of them work out. I know they are either not secure or so cumbersome that life becomes a massive chore. There’s also the problem of having very little physical space and basically only one computer.

design – How to avoid making User a god object?

Consider typical gym trainings tracker app.

User has account related attributes:

User {
  id
  login
  password
  email
  fname, lname
  isBlocked
}

However, the requirements are that an application’s user manages his trainings, trainings history, achievements, profile, etc. All of those entities should be somehow linked with user account.

How do I link it with an account? What is the common way to do it and its pros/cons?


I can imagine two scenarios:

Possibility 1: Making User a large ‘god’ object:

User {
  id
  login
  password
  email
  fname, lname
  isBlocked

  trainings        # one to many
  training_history # one to one
  achievements     # one to many
  /** possibly many more relations */
}

Possiblity 2: Link User with UserProfile, and then UserProfile holds all the relations.

User {
  id
  login
  password
  email
  fname, lname
  isBlocked

  user_profile     # one to one
}

UserProfile {
  user_id          # one to one

  trainings        # one to many
  training_history # one to one
  achievements     # one to many
  /** possibly many more relations */
}

Is the second option really better than the first one? Can I do better?

applications – How to avoid suspended apps getting killed in iOS 14?

I have updated my iPad operating system from iOS 11.4 to iPadOS 14.3. Unfortunately, suspended apps are now immediately killed in the background while in the older version I could keep many apps suspended in the background without need to be restarted when being used again (Even, Safari often refreshes open tabs when I want to use them after a short while during which they were not active; such a thing has also happened on the older OS, but with much less frequency).

One might expect such a bug for non-Apple apps because of non-compatibility with the new OS update, but it really surprised me that such a problem exists with Apple apps such as Safari and Pages.

It is really annoying, especially when you are writing some post on a Stack Exchange network and need to use some other app. I wonder whether this can be avoided somehow.

PS: It is worth saying that my iPad has enough free memory, more than that when running the older OS.

c – How to input eof(Ctrl+z) while letting the scanf have a space before the specifier to avoid getting previous n error?

https://ibb.co/D5D4nMS ( I hit enter)

#include<stdio.h>
#include<stdlib.h>
int main(){
    int target,result;
    while(1){
        printf("Please input your target: ");
        scanf(" %d",&target);
        if(feof(stdin)){
            break;
        }
        printf("testn");       
    }
}

if I chnage the code to: (delete the space)

#include<stdio.h>
#include<stdlib.h>
int main(){
    int target,result;
    while(1){
        printf("Please input your target: ");
        scanf("%d",&target);//no space
        if(feof(stdin)){
            break;
        }
        printf("testn");       
    }
}

it worked

Snipaste-2021-01-03-15-45-22

How do you socialize online and avoid facial recognition and other privacy breaching-tactics

What are some techniques to socialize online, while still maintaining privacy, specifically avoiding facial recognition? The main goal here is to make it to where only humans can recognize/track you, while making it to where computers cannot analyze and mass track you.

For example, many social media sites and dating sites require that you upload a profile picture. While you can put something completely random (like a dog or soda can), it may come off creepy or maybe make people might not want to connect with you. I would like to know if there are any balanced options between anonymity, showing your real face, not being creepy, and socially connecting with people (through imagery of your face/body).

Perhaps techniques of taking a face profile picture and using software editing to blur, distort, or stretch the image. That, or do physical scene manipulations like a shadow effect, zooming, light effect, glass, water, gas, etc., or adjusting the camera.