shaders – How to convert from frag position to UV coordinates when my viewport doesn’t cover the screen?

So, I’m implementing SSAO as part of my rendering pipeline using OpenGL/GLSL. It works pretty well when I have a camera that takes up the entire screen. However, when my camera is smaller than the full screen size, the SSAO texture doesn’t get sampled correctly. Here is the relevant GLSL shader code:

// Convert from clip-space
vec2 fragCoords = (fragPos.xy/ fragPos.w); // fragPos is MVP * worldPosition
vec2 screenCoords = fragCoords * 0.5 + 0.5; // Convert from (-1, 1) to (0, 1) to sample UV coordinates

// Sample texture
float ssaoFactor = texture2D(ssaoTexture, screenCoords).r;

I know that there is some funkiness going on with the viewport, but the fixes that I’ve tried haven’t worked. My first thought was to scale fragCoords by normalized size of my viewport (e.g. vec2(0.5, 0.5) for a viewport with half of the width and height of the screen), but that just produced a very strange result. Any thoughts?

headphones – Lower half of Apple watch screen doesn’t respond to touches any more

I’ve had this Apple Watch 3 for almost three years. Earlier this year a hairline crack appeared diagonally across the glass and the bottom half of the screen no longer responds to my touches. Also, the display doesn’t light up when I look at the watch anymore like it used to. The top half work and I can control the watch for touches to the top half, but most buttons are on the bottom and I can’t dismiss screens. For example, I used to have a pair of wireless Anker earbuds but it broke and the Apple Watch keeps searching for it and won’t let me change to my new wireless earbuds. Any one know how to control the watch from the iphone for example, like changing settings and such?

I am going to get a new Apple Watch 6 in a few weeks but trying to make do with a beloved watch that I’ve had 3 years now.

Why doesn’t a simple Http request to display a remote web page violate the Same Origin Policy?

On a w3schools page, I found that HTTP requests work like this:

  • A client (a browser) sends an HTTP request to the web
  • A web server receives the request, and runs an application to process it
  • The server returns an HTTP response (output) to the browser
  • The client (the browser) receives the response.

On the same page I found that an XMLHttpRequest works like this:

  • A browser creates an XMLHttpRequest object and sends it to the server
  • The server processes the request, creates a response and sends data back to the browser
  • The browser processes the returned data using JavaScript and updates the page content.

The above two processes appear pretty much the same to me. However, the latter one violates the Same Origin Policy (SOP) if the server runs on a remote domain. This question on stackoverflow about the url in the open() method says that

As we can only send requests to our own web server, I assume that we don’t have to rewrite the website’s name in the URL.

Applying the same logic to the first case (Http requests) would mean that I couldn’t open a web page if it is not on my own computer. Luckily, this is not the case.

So, why doesn’t an Http request to display a remote web page violate the SOP? What is the key point/difference here?

I assume it’s about the fact that the second process (XMLHttpRequest) is initiated from a script, while the first one is triggered by the user. However, isn’t the Http request sent from a script when I click a hyperlink on a web page? And how can a web server distinguish between requests coming from a script and coming from a user?

pgp – Import secret key into GnuPg doesn’t work?

I would like to import a private key into GPG so I did:

gpg --allow-secret-key-import --import /path/to/key/key.asc
gpg: key 51D5DF493ECAFF88: "John Doe <john.doe@acme.com>" not changed
gpg: key 51D5DF493ECAFF88: secret key imported
gpg: Total number processed: 1
gpg:              unchanged: 1
gpg:       secret keys read: 1
gpg:  secret keys unchanged: 1

But then, the key is not listed :

$ gpg --list-secret-keys | grep 51D5DF493ECAFF88
(nothing)

What’s wrong?

$ gpg --list-packets /path/to/key/key.asc | grep dummy
(nothing)

$ gpg --version
gpg (GnuPG) 2.2.4
libgcrypt 1.8.1

sql server – sqlcmd command doesnt work in bat file

I have a strange problem.
I want to do backup of my data bases via sqlcmd command.
If I write all command directly at cmd, everything works properly.
If I save it as bat file and run I have error. Why?
Command: sqlcmd -S localhostsqlexpress –i C:SQLScriptsbackup-full-insertnexo.sql
error: click
Okay: okay
I would like to add, on 2 laptops works properly and two bad :/

Thanks,
Krystian

kernel – USB port doesn’t work only for the mouse after hibernation on laptop

dmitry@chicago:~$ uname -a
Linux chicago 5.4.0-48-generic #52-Ubuntu SMP Thu Sep 10 10:58:49 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

Hello everyone!
My HP laptop has 3 USB ports. After hibernation a brand new mouse doesn’t respond. When I change port from 3 to 2 or 1 the mouse works perfect. When I attach USB-Flash drive in port 3 it also works. Only mouse doesn’t want to work on port 3 after hibernation.

Which commands outputs should I present to give you more info?

functional programming – Doesn’t “Always test through the public interface” contradict testing of individual composed functions?

I’m currently reading “Composing Software” by Eric Elliott, which is about functional programming in JavaScript. He states that if you compose multiple functions together, and that these functions have been fully tested in isolation – then you don’t need to unit test the composed function (as that can be done using an integrated test that performs all the side effects.)

But isn’t simply testing the individual functions violating the core TDD principle of “always test the public inteface, and not the implementation”? Arguably the composing of the smaller functions is an implementation detail. As long as my service performs the action that it says it will do, we shouldn’t really care about the small “private” functions being composed in order to get the right behaviour.

I’m trying to reconcile the two ideas but I’m struggling. The only way around this (that I can think of) is to mock the dependencies that my service needs so that it can be tested through the public interface, but going functional was my attempt to stop using mocks in the first place.

c++ – Why doesn’t my code to solve the Kattis sim problem work?

I submitted this code to solve the Kattis Sim problem, but it fails on the 14th test with a runtime error without specifying why it failed. Why doesn’t my code work for all the examples? How would I begin to debug code if there are no error messages.

Kattis output: https://github.com/vader-coder/Kattis/blob/main/simOneFile/Sim%20Submission%206283978%20%E2%80%93%20Kattis%2C%20Kattis.pdf
Link to code: https://github.com/vader-coder/Kattis/blob/main/simOneFile/sim.cpp
Link to copy of error message on submit page: https://github.com/vader-coder/Kattis/blob/main/simOneFile/Sim%20Submission%206283978%20%E2%80%93%20Kattis%2C%20Kattis.pdf

Full .cpp file:

//class definition:

#include <deque>
#include <list>
#include <string>
#include <iostream>
using namespace std;

class Line {
   public:
    Line(string& s);  //construct the line
    ~Line();
    void print();  //start from head, go to tail.
    void buildOutputCharPtr();
    void add(char& c);                 //add char to current element
    void backspace();                  //does backspace on current que.
    void front();                      //put cursor to back
    void back();                       //put cursor to front
    int strcomp(char* s, int length);  //compare content to string
    int strcomp(string s);
    char* getCharPtr() {
        if (this->printWasCalled) {
            return this->characters;
        }
        else {
            cout <<"ERROR: getCharPtr() called before char pointer allocated."<<endl;
        }
    }
   private:
    list<deque<char>> nodeList;
    list<deque<char>>::iterator currentElement;  //set to first element by default
    int cursorIsAtFront = 0;                     //either at front or at back
    char* characters;                            //to be built
    int size = 0;
    int printWasCalled = 0;
};

//test
//we must change this so we take in input, calculate answers, then print them, not print as answer.
void kattis() {
    string tests;
    string test;
    getline(cin, tests);
    Line* line;
    int testNum = stoi(tests);
    Line** lines = new Line*(testNum);
    //calculate output 
    for (int testIndex = 0; testIndex < testNum; testIndex++) {
        getline(cin, test);
        line = new Line(test);  //    Line* list = new Line(input);
        line->buildOutputCharPtr();
        lines(testIndex) = line;
    }
    //print output
    for (int testIndex = 0; testIndex < testNum; testIndex++) {
        lines(testIndex)->print();
        if (testIndex < (testNum - 1)) {
            cout << endl;
        }
        delete lines(testIndex);
        lines(testIndex) = nullptr;
    }
    line = nullptr;
    delete lines;
    lines = nullptr;
}
int main() {
    kattis();
    return 0;
}

Line::Line(string& s) {
    this->nodeList.push_back(deque<char>());        //push empty deque to serve as beginnig and tail.
    this->currentElement = this->nodeList.begin();  //assign current element to first one.
    for (char& c : s) {
        if (c == '<') {  //do a backspace
            this->backspace();
        } else if (c == '(') {  //move cursor to front
            this->front();
        } else if (c == ')') {  //move cursor to back
            this->back();
        } else {  //if it is any other character, add it to the line
            this->add(c);
        }
    }
}
Line::~Line() {
    if (this->printWasCalled) {
        delete() this->characters;
        this->characters = nullptr;
    }
}

//add char to current element
void Line::add(char& c) {
    this->currentElement->push_back(c);  //add new character to iterator
    this->cursorIsAtFront = 0;           //cursor isn't at front anymore.
    this->size++;
}
//does backspace on deque in current node
void Line::backspace() {
    if (this->currentElement->size() > 0) {  //current element doesn't have empty deque
        this->currentElement->pop_back();    //destroy last element in deque
        this->size--;
    } else if (!this->cursorIsAtFront && this->nodeList.size() > 1) {  //deque empty but cursor at back.
        this->nodeList.pop_back();                                     //destroy tail of list.
        this->currentElement = this->nodeList.end();                   //assign current element to new end.
        this->backspace();                                             //call backspace with new, hopefully non empty element at end.
    }
    //if currently at front & current element is empty, don't do anything.
}

//print items
//TODO: check if was built already.
void Line::print() {  //start from head, go to tail.
    //list<deque<char>>::iterator node;
    //deque<char>::iterator character;
    if (!this->printWasCalled) {     //char* characters was not built yet
        this->buildOutputCharPtr();  //build it.
    }
    cout << this->characters;
}
void Line::buildOutputCharPtr() {                 //build char pointer containing output string
    this->characters = new char(this->size + 1);  //one extra space for the null terminator
    int charIndex = 0;
    for (deque<char> node : this->nodeList) {  //node = this->nodeList.begin(); node != this->nodeList.end(); node++) {//iterate through linked list
        for (char character : node) {          // = node->begin(); character != node->end(); character++) {//iterate through deque
            this->characters(charIndex) = character;
            charIndex++;
        }
    }
    this->characters(this->size) = '';  //last entry is null terminator
    this->printWasCalled = 1;             //change to characters were built
}
//compare content to string
int Line::strcomp(char* s, int length) {  //compare content to string
    if (length != this->size || !this->printWasCalled) {
        return 0;
    }
    for (int i = 0; i < length; i++) {
        if (this->characters(i) != s(i)) {
            return 0;
        }
    }
    return 1;
}
int Line::strcomp(string s) {
    int length = s.size();
    if (length != this->size || !this->printWasCalled) {
        return 0;
    }
    for (int i = 0; i < length; i++) {
        if (this->characters(i) != s(i)) {
            return 0;
        }
    }
    return 1;
}

//put cursor in front
//change iterator to beginning of list, put flag to not at front
void Line::front() {
    if (this->nodeList.begin()->size()) {          //if element at front not empty
        this->nodeList.push_front(deque<char>());  //create new empty element at front            }
    }
    this->currentElement = this->nodeList.begin();  //update current element to point at front
    this->cursorIsAtFront = 1;
}
//put cursor in back
//change iterator to end of list, put flag to not at front
void Line::back() {
    if (this->nodeList.size()) {
        this->currentElement = --this->nodeList.end();
    } else {  //create new element, which is both end and beginning but we will treat it as end.
        this->nodeList.push_back(deque<char>());
        this->currentElement = this->nodeList.begin();
    }
    this->cursorIsAtFront = 0;  //should this be in the if statement?
}