Poll visible windows’ positions from C++ and send to a C# client

I’m creating a C# client which shows all Windows visible windows’ bounds at real time. (this is not the main purpose, but it’s a core feature).

At the beginning, I found DLL injection. So I considered a global DLL injection so that every process with an injected DLL sends its bounds to my client. But this was far too complicated.

I quickly turned to polling. It’s important to know that I have a game loop with interpolation in order to have a “real-time display of windows’ bounds”

(I subscribed to CompositionTarget.Rendering event, I’m using WPF)

First, I used (and I still use) EnumWindows in my game loop. This was laggy, and in order to filter all the windows, I was always gathering all the information of a window with P/Invoke calls although it was not always necessary.

Anyway. To optimize this, I put all this logic in an infinite loop in a Dispatcher Thread and for each enumerated window, I get its information one at a time, only if I need it, and in the order of first exclusion.

My want is to have the smoothest polling I can have, so I’d like to switch to C++ for this poll and filter stuff to make it faster.

Note: this duo of C++ and C# “apps” would never be running separately. The C++ side is only useful to the C# side. If C# side stops, the other needs to stop too.

Now that you see the big picture of what I already did, and what I’d like to achieve, here’s my question(s):

  • I’m considering using a C++ service, is it a good idea? If not, what would you advise me?
  • What method would you advise me to send a relatively continuous flow of bounds information to my C# client from C++?

I say send because I think of the “from C++ to C#” way, but maybe it’s better to think the other way. For example, C++ serves a file or something which is continously updated, and I would read it with C#…

The only thing is that all of this has to be fast and look smooth.

Ramda – Forming a string based on array of word positions

I saw this question and wondered how it’d be best to accomplish this using Ramda.

I’m new to the library so I thought it’d be an interesting learning exercise.

I have a working solution but it seems overly complicated and verbose. I’d be grateful for any suggestions on what other ways it would be possible to achieve this output using Ramda.

I’m aware that this doesn’t need a library; as I say, I approached it as a learning exercise.

Here’s what I have:

const { addIndex, always, fromPairs, join, map, sort, toPairs, unnest } = R;  const song = {   "99": [0, 7],   "bottles": [1, 8],   "of": [2, 9],   "beer": [3, 10],   "on": [4],   "the": [5],   "wall": [6] };  const toSentence = join(' ');  const parsed = toSentence(     map(       ([_, word]) => word,       sort(         ([a, _], [b, __]) => a < b ? -1 : 1,         unnest(map(           ([word, indices]) => map(             index => [index, word],             indices,           ),           toPairs(song)         ))       )     )   )    console.dir(parsed)
<script src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.26.1/ramda.js"></script>

O(B) algorithm to find positions of all permutations of smaller string in a bigger string with length B – how is this possible?

Context: I’ve been working through Cracking the Code Interview and on page 70 the book asserts that there is a O(B) solution to this problem.


  • s = little string and S = len(s)
  • b = big string and B = len(b)

then I believe it would be something along the lines of (pseudocode):

hs = hash(s) for every position, substring of length S in B:      h_sub = hash(substring)     if hs == h_sub:          print position 

Note that the for loop will run B-S+1 times, so whatever happens inside the loop must be O(1) in order for the whole thing to be O(B).

This assumes that there exists a O(1) hash function hash(s) that only returns the same hash when two words are permutations of each other, and never collide otherwise.

What is this hash function? It seems like you’d have to iterate through every letter in substring to calculate h_sub and I don’t see how that can happen in less than O(S) time. This answer seemed promising but then someone found a non-valid collision.

I learned about the radix-2p hash for this problem in school and we had to prove it as a homework exercise so I am convinced of its correctness.

However in the calculation $ k = \sum_{i=0}^{n-1} x_i(2^{p})^i$ , the exponent on the $ 2^p$ always changes depending on the position of the letter $ x_i$ within the substring, so I don’t see how we can avoid having to iterate anew through all S letters of the substring when we calculate $ k \text{ mod } (2^p-1)$ .

Am I missing something or is there another approach entirely? Thanks.

Python: How to replace a vowel with a character being ‘@’ and state the positions of the vowels?

I have a question about replacing vowels (aeiou upper/lower) with the symbol “@”. I have a full code written that also prints ONLY capital letters (working), every other character in the string (working), and the number of digits in the string (working). The only issues that I am having with the program is that I am unable to replace ALL vowels in the string with the symbol “@” as well as output the position of each vowel in the string. I am in a low-level coding class for Python, so I am using only loops to complete the program. Here is what I have so far:

str=input("Enter a string: ") char=0 s=0 onlyCaps=0 v=0 n=0 count=0 countv=0 vowels=('a' and 'A' or 'e' and 'E' or 'i' and 'I' or 'o' and 'O' or 'u' and 'U') position=vowels def upperOnly(s):     onlyCaps=""     for char in s:         if char.isupper()==True:             onlyCaps+=char     return onlyCaps for n in str:     if n.isnumeric():         count=count+1 if str.__contains__(vowels):     countv+=1 print(upperOnly(str)) print(str[::2]) print(str.replace(vowels,'@')) print("The string contains",count,"digits.") print("The vowels are at positions:",countv) 



Ti sats 2.

This is a test 123. (Where the string should have vowels replaced with “@”)

The string contains 3 digits.

The vowels are at positions: 0 (Where the positions of vowels are given)

How to calculate the positions of the vertices of a deformed cube with different local and global symmetry?

Going over degrees of freedom, it appears that the following construction works, but I have no idea how to calculate exact positions of the vertices, or even a practical approach to approximating them well.

There’s a deformed cube, meaning the vertices are all moved around a bit but the four vertices of each face are still planar, and it has the property that the length of UFL (up front left) to UBL (up back left) equals UFL to DFL equals DFL to DFR. Also UFR to UBR equals UBR to DBR equals DBR to DBL. Also the other six edges are all the same length. But not all edges are the same length. I believe there’s continuum of these defined by a single parameter which can be, for example, the ratio in length between two of the edges.

Any idea how to calculate exact vertex positions, or at least dimensions of the faces? This is meant to be a ‘find the symmetry’ puzzle, where each face misleadingly hints at a possible symmetry of the puzzle as a whole but the actual one is something different, and it can be made either as a solid block or a fold-out on paper.

Recovering Positions


Just a week ago I buy a domain for the website. This website has a great list for many keywords. Just one year ago the owner (my friend) decided to 301 to another domain. Now he'll go to sell me this domain and I'm curious what is the best solutions to recover Google position? Did i need to start doing SEO from the beginning?

How does one calculate a margin position’s liquidation price for Bitfinex and other exchanges?

I’m learning how margin works and wanted to understand how does liquidation price work in a margin position when using an exchange like Bitfinex? Their requirements is 30% equity.

Let’s say I deposited $ 1000 in USD and purchased $ 2000 worth of Bitcoin at the price of $ 1000 each BTC.

I understand that my equity is $ 1000 which is what I deposited.

What is my liquidation price and how does one calculate it?

And what other factors do I need to know when if I wanted to hold onto this margin position for many months?