Categories
Mastering Development

LWIP Can’t Connect to Remote Server

My code is raw tcp/ip client application. It can connect local server on my computer frequently but it can’t connect to remote server “sometimes (about 2/3 ratio) ” . Remote server is working properly, I guarantee by connecting my computer with simple socket application. If I try to execute TCP_WRITE function, return error 13 so […]

Categories
Mastering Development

Accessing an item in a Python dict

Suppose I have a function that filters out the data like so: from typing import Dict, Union def filterData(data: Dict[str, str], fields: Union[list, tuple]) -> dict: filteredData = {} for field in fields: if field in data: filteredData[field] = data[field] return filteredData And I use this function like so: data = filterData({“a”: “b”, “c”: “d”}, […]

Categories
Mastering Development

how to encrypt and decrypt string with openssl?

Trying to encrypt and decrypt strings with evp functions of openssl. I tried the following source code but I got unexpected results (garbege output). What I am missing? #include <stdio.h> #include <unistd.h> #if 1 #include <openssl/evp.h> char *se_evp_encrypt(char *ssid, char *data, int inl, char *ret, int *rb) { int i, tmp, ol; EVP_CIPHER_CTX evpctx; char […]

Categories
Mastering Development

Regex: extract a number after a string that contains a number

Suppose I have a string: str <- “England has 90 cases(1 discharged, 5 died); Scotland has 5 cases(2 discharged, 1 died)” How can I grab the number of discharged cases in England? I have tried sub(“(?i).*England has [\\d] cases(.*?(\\d+).*”, “\\1”, str), It’s returning the original string. Many Thanks!

Categories
Mastering Development

The request was aborted: Could not create SSL/TLS secure channel using Restsharp

I am trying to connect the service file(.svc). from my c# code but i am getting message as The request was aborted: Could not create SSL/TLS secure channel The server accept only below Cipher code The ciphers accepted are as per below: TLSv1.2 128 bits ECDHE-RSA-AES128-GCM-SHA256 Curve P-256 DHE 256 TLSv1.2 256 bits ECDHE-RSA-AES256-GCM-SHA384 Curve […]

Categories
Development

JavaScript – Caesar Cipher

I know there have been a few posts about Caesar Ciphers in the past, which I have had a look at, but I haven’t found an answer which has helped me to solve this kata, hence my post. The language is JavaScript. I’ve written 3 tests, 2 of which are passing so far, but the […]

Categories
Development

How to dynamically use Python’s type hinting to indicate a return value to be the same as a parameter’s type

I’m using Python to read JSON from disk, and I’m trying to make sure my type hints are correct downstream. For example, something like this: from typing import List def verify_contains_ints(items: List[object]) -> List[int]: for item in items: if not isinstance(item, int): raise TypeError(“List contents must be all ints”) return items The problem I’m running […]

Categories
Development

How to move text from one point to another and delete the text letter by letter when variable arrives at 0

Well I’m trying to move text from 1 point X to point X1, when the text reaches point X1 it starts to disappear. DrawTextW function https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-drawtextw void DirectX::Font::DrawText(const wchar_t* str, long x, long y) { // Generate rectangle param RECT rect; SetRect( &rect, x, y, 0, 0 ); // Draw text m_font->DrawTextW( NULL, str, -1, […]

Categories
Development

mypy complains: function type annotation with Type[TypeVar[‘T’, str, date]] and T output: Incompatible return value type (got “str”, expected “date”)

The intention is to overload the function and allow for multiple types of input, with user-defined coherent output. I thus set a Type[TypeVar] of str or datetime.date (second function argument, with default value=str) where the function would output the relevant TypeVar. The following is the basic function (that I would further extend once this version […]

Categories
Development

Modify C file without making a copy

I’m trying to modify a given file without making a copy of it adding a string in a given position,and I distinguish 2 cases: if the given position is at the end of file, I simply append the string, otherwise I add it at the right spot. I have 2 problems: 1) when I append […]