Monday, April 21, 2025

Error: in triplet x64-windows: Unable to find a valid Visual Studio instance

error: in triplet x64-windows: Unable to find a valid Visual Studio instance
Could not locate a complete Visual Studio instance
The following paths were examined for Visual Studio instances:
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary/Build\vcvarsall.bat

The fix works for me:

git pull
.\bootstrap-vcpkg.bat
.\vcpkg.exe integrate install


Tuesday, October 29, 2024

The TP-Link Archer T2U Nano on Debian/Kali kernel 6.8.11: no available networks

After some time of playing around with different things, the following steps helped:

For

uname -v 
#1 SMP PREEMPT_DYNAMIC Kali 6.8.11-1kali2 (2024-05-30)

First, check the dongle is available







 

 

 

 

This sequence of commands worked for me:

sudo apt install build-essential git dkms
sudo apt-get install linux-headers-$(uname -r)
cd Downloads
git clone https://github.com/aircrack-ng/rtl8812au.git
cd rtl8812au/
sudo make dkms_install
dkms status
reboot
# sudo modprobe 8812au
sudo apt install realtek-rtl88xxau-dkms reboot # Check the driver: dkms status 8812au/5.6.4.2_35491.20191025, 6.8.11-amd64, x86_64: built
realtek-rtl8814au/5.8.5.1~git20240527.d8208c8, 6.8.11-amd64, x86_64: installed realtek-rtl88xxau/5.6.4.2~git20240726.63cf0b4, 6.8.11-amd64, x86_64: installed
# check available wifi
nmcli dev wifi
 

 

Sunday, February 4, 2024

Quickstart: Run SQL Server Linux container images with Docker

Quickstart: install connect docker

Error:

liblber-2.4.so.2 No such file or directory
libcrypto.so.6 No such file or directory

on RHEL8/9 

Investigate:

yum provides \*/libcrypto.so
yum provides \*/liblber-2.4.so 
Solution:

sudo yum install openldap-compat


 

Sunday, February 19, 2023

There was no match for the specified key in the index. (0x80070491)

Problem

using Microsoft.Windows.ApplicationModel.DynamicDependency;
using System;

namespace CsConsoleActivation
{
    class Program
    {
        // Windows App SDK version.
        static uint majorMinorVersion = 0x00010000;
        private static string executablePath;
        private static string executablePathAndIconIndex;

        static void Main(string[] args)
        {
            try
            {
                Bootstrap.Initialize(majorMinorVersion);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
    }
}

This code generates an error, because I've got 
Windows App SDK of version 1.2 on my machine. So, I tried to modify 
majorMinorVersion to 0x00010010 to no avail.

Solution


After several hours of deep diving on the Win. App SDK source code I found out, 
that the field majorMinorVersion is not a binary type, but something different. 
It should have been set to 0x00010002. So, for my 1.2 version of Windows App SDK,
the correct code looks like this: 


using Microsoft.Windows.ApplicationModel.DynamicDependency;
using System;

namespace CsConsoleActivation
{
    class Program
    {
        // Windows App SDK version.
        static uint majorMinorVersion = 0x00010002;
        private static string executablePath;
        private static string executablePathAndIconIndex;

        static void Main(string[] args)
        {
            try
            {
                Bootstrap.Initialize(majorMinorVersion);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
    }
}

Sunday, August 14, 2022

The pip command produces wierd LookupError: unknown encoding: cp65001

Running Python 2.7 is not easy in these modern days. Today I needed to have Conda running on Python 2.7, and I was struggling with this weird error: (xxxxx) C:\Users\name>pip install jupyter notebook Traceback (most recent call last): File "D:\Anaconda3\envs\xxxxx\Scripts\pip-script.py", line 6, in from pip._internal.main import main File "D:\Anaconda3\envs\xxxxx\lib\site-packages\pip\_internal\main.py", line 13, in from pip._internal.cli.autocompletion import autocomplete File "D:\Anaconda3\envs\xxxxx\lib\site-packages\pip\_internal\cli\autocompletion.py", line 11, in from pip._internal.cli.main_parser import create_main_parser File "D:\Anaconda3\envs\xxxxx\lib\site-packages\pip\_internal\cli\main_parser.py", line 7, in from pip._internal.cli import cmdoptions File "D:\Anaconda3\envs\xxxxx\lib\site-packages\pip\_internal\cli\cmdoptions.py", line 31, in from pip._internal.utils.ui import BAR_TYPES File "D:\Anaconda3\envs\xxxxx\lib\site-packages\pip\_internal\utils\ui.py", line 64, in _BaseBar = _select_progress_class(IncrementalBar, Bar) # type: Any File "D:\Anaconda3\envs\xxxxx\lib\site-packages\pip\_internal\utils\ui.py", line 57, in _select_progress_class six.text_type().join(characters).encode(encoding) LookupError: unknown encoding: cp65001

For Windows 10/11 I'm on, the solution is to switch encoding in Python console to UTF-8.

(xxxxx) C:\Users\name>set PYTHONIOENCODING=UTF-8
Then ensure running
pip install jupyter notebook
Instead of
conda install jupyter notebook

Tuesday, July 27, 2021

SIGINT handler in cxx


#include <iostream>
#include <csignal>
#ifdef _WIN32
#include <Windows.h>
#else
#include <unistd.h>
#endif


using namespace std;

void signalHandler( int signum ) {
    cout << "Interrupt signal (" << signum << ") received.\n";

    // cleanup and close up stuff here
    // terminate program

    exit(signum);
}

int main () {
    // register signal SIGINT and signal handler
    signal(SIGINT, signalHandler);

    while(1) {
        cout << "Going to sleep...." << endl;
        sleep(1);
    }

    return 0;
}

Sunday, April 25, 2021

Convert python dictionary to object

Consider having json response from REST service stored internally in dictionary object. Now, following code converts content of the dictionary to instace of class Test.

Keep in mind though it's just simple demonstration. Enhancement in form of data validation might be required!


from collections import namedtuple

class Test:
    def __init__(self, name : str, description : str, float_number : float): 
        self.name, self.descrition, self.float_number  = name, description, float_number

    def __repr__(self) -> str:
        return f"Test class data: name='{self.name}', description='{self.descrition}', number={self.float_number}"

paramDict = dict(name="Name Property Value", description="Description Property Value", float_number=102.0036)

tstInstance = Test(*(namedtuple('x', paramDict.keys())(*paramDict.values())))

print(repr(tstInstance))

Running the code above prints following representation of the object on the std output:

Test class data: name='Name Property Value', description='Description Property Value', number=102.0036

Saturday, March 6, 2021

Create trustore and keystore for local Kafka and Zookeeper on Windows

Scenario:

  1. Needed to use local Zookeeper and Kafka with existing CA certificate as well as existing consumer certificate. 
  2. Hence needed to be able to use specific CN for 127.0.0.1, not a localhost
  3. Modification of windows hosts file not allowed
All samples I found on the net presumed that CA needs to be generated. My use case was different. I was given with CA and client certificate and I needed to use defined certificate chain for authentication.

Used Git Bash i.e. cygwin for this exercise, hence winpty presence on line with openssl command.


 keytool -genkeypair -keyalg RSA -keysize 2048 -alias projenvlocal -dname "CN=projenvlocal" 
    -ext SAN=DNS:projenvlocal,DNS:localhost,IP:127.0.0.1 -validity 3650 -keystore server.keystore.jks 
    -storepass pwd1234 -keypass pwd1234 -deststoretype pkcs12  

 keytool -keystore server.truststore.jks -alias CARoot -import -file projEnvCALocal.crt 
    -storepass pwd1234 -noprompt

 keytool -keystore server.keystore.jks -alias projenvlocal -certreq -file localhost.csr 
    -storepass pwd1234  

 winpty openssl x509 -req -CA projEnvCALocal.crt -CAkey projEnvCALocal.key -in localhost.csr 
    -out localhost-signed.crt -days 3650 -CAcreateserial -extfile sign-cert.cnf 
    -extensions server_cert -passin pass:keypwd  

 keytool -keystore server.keystore.jks -alias CARoot -import -file projEnvCALocal.crt 
    -storepass pwd1234 -noprompt  

 keytool -keystore server.keystore.jks -alias projenvlocal -import -file localhost-signed.crt 
    -storepass pwd1234  

* passwords are just illustrative of full command line

This part below is the main thing for being able to use certificate's CN as user name for Kafka authentication on localhost/127.0.0.1

   -dname "CN=projenvlocal" -ext SAN=DNS:projenvlocal,DNS:localhost,IP:127.0.0.1

Performing of script above create two files, server.trustore.jks and server.keystore.jks .These files need to be used in ssl section of Kafka's server.properties and Zookeeper's zoo.cfg (file names may differ though).

Wednesday, November 4, 2020

The Pylance - Goodbye Kite

Goodbye Kite.

Fast, feature-rich language support for Python in Visual Studio Code

The name Pylance serves as a nod to Monty Python’s Lancelot, who is the first knight to answer the bridge keeper’s questions in the Holy Grail.


(cheers John Cleese et al.)

Expecting Pybrian plugin in the near future :)

The Quntopian has drawn to the close

The Quantopian has been brought to the end but some of their valuable resources have been placed on the github.

[1] Quantopian research 

[2] Community classes 

[3] ... (?)


Saturday, October 3, 2020

Black-Sholes delta


import numpy as np 
from scipy.stats import norm

def delta(flag, s, k, t, r, v): 
  d1 = (np.log(s/k)+(r+v*v/2)*t)/(v*np.sqrt(t)) 
  if flag == “C”:
    return norm.cdf(d1) 
  else: 
    return norm.cdf(-d1) # +signed put delta

Type = ‘C’ # call
S = 97.65 # underlying
K = 100.00 # strike
T = 30/365 # 30 days to expiry (in years)
R = 0.00 # “risk-free” rate
V = 0.12 # 12 vol
delta(Type, S, K, T, R, V)

0.25044822

Type = ‘P’
S = 3000
K = 2900
T = 30/365
R = 0.00
V = 0.20
delta(Type, S, K, T, R, V)

0.27

S = 2950
T = 29/365
delta(Type, S, K, T, R, V)

0.37

Saturday, December 6, 2014

LNK2001: unresolved external symbol __imp__PyObject_IsTrue

Recently I was experiencing following liknking error [1] .
I was checking path VC++ directories settings, upgrading from boost 1.55 to 1.57, still the same issue. After couple of ours, the resolution was so simple, I could not believe I can be so absent minded.

Never try to compile project referencing 32bit of boost, and linking 64bit Python engine.

[1] error LNK2001: unresolved external symbol __imp__PyObject_IsTrue    %PATH%\libboost_python-vc120-mt-gd-1_55.lib(class.obj)   

Thursday, November 20, 2014

Boost::Python callback triggered from Non-Python created threads

Consider  we have virtual/abstract C++ class that's fully implemented in Python. And for some sake of necessity we have a callback method (e.g. as some sort of event) that is being triggered from different thread on C++ side and is handled in Python .
In such case corresponding callback methods have to manage global interpreter lock state with PyGILState_STATE member variable.
So the resulting C++ callback class definition will look like below (notice that Python method calls are wrapped up with GIL state handling code).


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
class SessionStatusListenerCallback : public SessionStatusListener
{
public:
 SessionStatusListenerCallback(PyObject *pyObject)
  : self(pyObject) {}

 SessionStatusListenerCallback(PyObject* pyObject, const SessionStatusListener& listener)
  : self(pyObject), SessionStatusListener(listener) {}

 void onSessionStatusChanged(O2GSessionStatus status)
 {
  // GIL state handler
  PyGILState_STATE gstate;
  gstate = PyGILState_Ensure();
  // Python callback
  call_method<void>(self, "onSessionStatusChanged", status);
  // GIL handler release
  PyGILState_Release(gstate);
 }
 
 void onLoginFailed(const char* error)
 {
  // GIL state handler
  PyGILState_STATE gstate;
  gstate = PyGILState_Ensure();
  // Python callback
  call_method<void>(self, "onLoginFailed", error);
  // GIL handler release
  PyGILState_Release(gstate);
 }
private:
 PyObject* const self;
};
 
 

Wednesday, November 12, 2014

Microsoft Visual C++ Compiler for Python 2.7

New tool Microsoft Visual C++ Compiler for Python 2.7 is available. 
I have not tested it yet. But solution for: 
The typical error message you will receive if you need this compiler package is Unable to find vcvarsall.bat. 
 sounds promising :)

Friday, November 7, 2014

Handling "AddressAccessDeniedException: HTTP could not register URL" error

Having self hosting WCF service one can get following exception:

AddressAccessDeniedException: HTTP could not register URL http://+:13025/

By default, listening at a particular HTTP address requires administrator privileges. Since application users does not often have such privileges it's necessary to allow port listening for particular user or group via nesth.

E.g.

netsh http add urlacl url=http://+:13025/applicationsvcs/booking user=DOMAIN\app_account

Proxying WCF service through the Fiddler

Set Fiddler as system wide proxy with preferred port (e.g. 8888).
Change app config of the WCF service host application as follows

<system.net>
  <defaultProxy
            enabled = "true"
            useDefaultCredentials = "true">
   <proxy autoDetect="false" bypassonlocal="false" proxyaddress="http://127.0.0.1:8888"    usesystemdefault="false" />
  </defaultProxy>
</system.net>

That's it.

Wednesday, August 27, 2014

How to handle pure virtuals with optional argumets in Boost::Python

Let's assume we have following C++ snippet:


class A
{
public:
  virtual void Method1(const char* par1, IInterface* p = 0) = 0;
};
How to handle default value for paremeter p? 
My first idea was using BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS as per boost doc.

class AWrap: public A, public wrapper<A>
{
public:
  void Method1(const char* par1, IInterface* p = 0){ this->get_override("Method1")();}
};

BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(method_overload, IInterface::onRequestCompleted, 1, 2)

class_<AWrap>("A")
  .def("Method1", &A::Method1, method_overload())
   ;

This would solve the optionality of the parameter, hovewer how to pass any default value? So I've ended up using args:

class_<AWrap>("A")
  .def("Method1", &A::Method1, (arg("par1"), arg("p") = 0))
   ;

Saturday, July 19, 2014

HelloWorld with Boost, Visual Studio 2013 and Python Tools for Visual Studio

So I've Boost compiled and prepared for some serious things and big projects :).
But first I was eager to test of wrapping some simple C++ code with Boost library and calling the resulting library from Python and all of that within one instance of Visual Studio 2013.
This is a result of my effort on experimental HelloWorld library incorporating:
  1. Python (libs and includes being referenced from Visual Studio)
  2. Visual Studio 2013
  3. Python Tools for Visual Studio
  4. Boost 1.5.5(compiled and lib and includes directories being referenced from Visual Studio)
So here is my really stupid simple sample of HelloWorld that is based on slightly changed code available in Boost documentation (see snippet below).
The main things for library to be callable from Python that are really important and are not aforementioned in Boost documentation:
  1. Resulting DLL has to be renamed to PYD. Python interpreted does not load DLL (At least I was not successful in convincing an interpreter to do that)
  2. Resulting PYD library has to have the same name like parameter of BOOST_PYTHON_ MODULE(...). So in my case I have hello as a parameter so correspondingly my compiled module is named hello.pyd.
  3. PYD file has to be available/findable for Python interpreter. Verify that your file is in corresponding %PYTHONPATH%. Otherwise Python's import hello (in my case) would cause runtime errors.
#define BOOST_ALL_DYN_LINK
#define BOOST_LIB_DIAGNOSTIC
#define BOOST_PYTHON_STATIC_LIB
#include <boost/python.hpp>
using namespace boost::python;

class World
{
public:
 void set(std::string msg) { this->msg = msg; }
 std::string greet() { return msg; }
 std::string msg;
 friend std::ostream &operator<<(std::ostream &o, World const &w) { o << w.msg ; return o; }
};


BOOST_PYTHON_MODULE(hello)
{
 class_<World>("World")
  .def("greet", &World::greet)
  .def("set", &World::set)
  .def(self_ns::str(self_ns::self))
  ;
}

The sample code is available on github:

Once I have had library compiled I was test it within Visual Studio's Python interpreter. (I really like the simplicity of  combining C++ and Python in one development tool). That's really cool.





Friday, July 18, 2014

Compiling Boost with Visual Studio 2013 for 64bits

Recently I needed to use Boost library in one of my project. So I've downloaded Boost package from boost.org and needed to build the whole Boost package for my Visual Studio 2013
The required steps I've had to do to build the Boost package were following.
  1. Open command prompt in root of %boost_install_dir%
  2. Execute bootstrap.bat
  3. Execute b2 toolset=msvc-12.0 --build-type=complete --libdir=%mylibs%\lib\x64 architecture=x86 address-model=64 install -j4 
  4. Add %mylibs%\lib\x64 into the libs path in the Visual Studio
Mission accomplished.

Update 2014-12-05:
Do not expect that building 32bit boost against 64bit version of python will bring any promising result :(.