Category Archives: Programming languages

Investigating cobalt::generator

Standard C++ generator

The code below demonstrates how standard C++23 synchronous generator works:

#include <boost/cobalt.hpp>
#include <iostream>
#include <generator>

namespace cobalt = boost::cobalt;

std::generator<int> numbers()
{
    for (int i = 1; i <= 5; ++i)
    {
        co_yield i;
    }
}
(more…)

Building boost::cobalt with MSVC 2022

cd C:\dev\repos\boost_1_89_0

set OPENSSL_ROOT_DIR=C:/dev/libs/OpenSSL
set OPENSSL_USE_STATIC_LIBS=ON
 
bootstrap.bat

b2 cxxstd=20 install --with-system --with-thread --with-cobalt --prefix=C:/dev/libs/boost_1_89_0 --toolset=msvc-14.3 -s _WIN32_WINNT=0x0A00 link=static runtime-link=static variant=release address-model=64
b2 cxxstd=20 install --with-system --with-thread --with-cobalt --prefix=C:/dev/libs/boost_1_89_0 --toolset=msvc-14.3 -s _WIN32_WINNT=0x0A00 link=static runtime-link=static variant=debug address-model=64
(more…)

Using Frida to hook Win API calls

python -m pip install frida-tools
Collecting frida-tools
  Downloading frida-tools-14.4.5.tar.gz (4.7 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 4.7/4.7 MB 2.8 MB/s  0:00:01
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Requirement already satisfied: colorama<1.0.0,>=0.2.7 in c:\dev\tools\python313\lib\site-packages (from frida-tools) (0.4.6)
Collecting frida<18.0.0,>=17.2.8 (from frida-tools)
  Downloading frida-17.2.17-cp37-abi3-win_amd64.whl.metadata (2.3 kB)
Collecting prompt-toolkit<4.0.0,>=2.0.0 (from frida-tools)
  Downloading prompt_toolkit-3.0.52-py3-none-any.whl.metadata (6.4 kB)
Collecting pygments<3.0.0,>=2.0.2 (from frida-tools)
  Downloading pygments-2.19.2-py3-none-any.whl.metadata (2.5 kB)
Collecting websockets<14.0.0,>=13.0.0 (from frida-tools)
  Downloading websockets-13.1-cp313-cp313-win_amd64.whl.metadata (7.0 kB)
Collecting wcwidth (from prompt-toolkit<4.0.0,>=2.0.0->frida-tools)
  Downloading wcwidth-0.2.13-py2.py3-none-any.whl.metadata (14 kB)
Downloading frida-17.2.17-cp37-abi3-win_amd64.whl (41.8 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 41.8/41.8 MB 10.6 MB/s  0:00:04
Downloading prompt_toolkit-3.0.52-py3-none-any.whl (391 kB)
Downloading pygments-2.19.2-py3-none-any.whl (1.2 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.2/1.2 MB 10.4 MB/s  0:00:00
Downloading websockets-13.1-cp313-cp313-win_amd64.whl (159 kB)
Downloading wcwidth-0.2.13-py2.py3-none-any.whl (34 kB)
Building wheels for collected packages: frida-tools
  Building wheel for frida-tools (pyproject.toml) ... done
  Created wheel for frida-tools: filename=frida_tools-14.4.5-py3-none-any.whl size=4699595 sha256=115f2de0f912d70ee9eed25c26b0460f4fe24213359dd46a0ffec3e96e24c911
  Stored in directory: c:\users\dmitr\appdata\local\pip\cache\wheels\a6\b2\fb\eff238e22a7ceffee8c7a366ce7ff4011af13c77a103f870d4
Successfully built frida-tools
Installing collected packages: wcwidth, websockets, pygments, prompt-toolkit, frida, frida-tools
   ━━━━━━━━━━━━━╺━━━━━━━━━━━━━━━━━━━━━━━━━━ 2/6 [pygments]  WARNING: The script pygmentize.exe is installed in 'C:\dev\tools\Python313\Scripts' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╺━━━━━━ 5/6 [frida-tools]  WARNING: The scripts frida-apk.exe, frida-compile.exe, frida-create.exe, frida-discover.exe, frida-itrace.exe, frida-join.exe, frida-kill.exe, frida-ls-devices.exe, frida-ls.exe, frida-pm.exe, frida-ps.exe, frida-pull.exe, frida-push.exe, frida-rm.exe, frida-trace.exe and frida.exe are installed in 'C:\dev\tools\Python313\Scripts' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed frida-17.2.17 frida-tools-14.4.5 prompt-toolkit-3.0.52 pygments-2.19.2 wcwidth-0.2.13 websockets-13.1
(more…)

Printing a package property in CMake

By example of spdlog package:

find_package(spdlog 1.13.0 EXACT REQUIRED)

message("spdlog_FOUND: ${spdlog_FOUND}")

get_property(SPDLOG_INTERFACE_INCLUDE_DIRECTORIES TARGET spdlog::spdlog_header_only PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
message(STATUS "Location of spdlog: ${SPDLOG_INTERFACE_INCLUDE_DIRECTORIES}")

Subscribing to all ByBit trade streams in Python

from pybit.unified_trading import WebSocket
from pybit.unified_trading import HTTP
from time import sleep

session = HTTP(testnet=False)

info = session.get_instruments_info(category="spot")

symbol_infos = info["result"]["list"]

websockets = []

def handle_message(message):
    print(message)

def subscribe(websockets, symbols):
    print(f'Subscribing to {symbols}')
    ws = WebSocket(
        testnet=False,
        channel_type="spot",
    )
    ws.trade_stream(symbol=symbols, callback=handle_message)
    websockets += [ws]
(more…)

Subscribing to ByBit WebSocket streams in Python

Spot is limited to 10 symbols:

from pybit.unified_trading import WebSocket
from time import sleep

ws = WebSocket(
    testnet=True,
    channel_type="spot",
)

def handle_message(message):
    print(message)

#ws.orderbook_stream(50, "BTCUSDT", handle_message)
ws.ticker_stream(symbol=["BTCUSDT", "ETHUSDT"], callback=handle_message)

while True:
    sleep(1)
(more…)

An example of using base iterator in C++

The code below demonstrates how to access underlying range iterator by transformed iterator:

struct A
{
    int x;
};

struct B
{
    A* a;
};

std::vector<B> v;

int main()
{
    auto a_range = v | std::views::transform(std::mem_fn(&B::a));

    auto i = std::ranges::find(a_range, 5, std::mem_fn(&A::x));

    A* a = *i;

    B& b = *(i.base());
}
(more…)

Working with Git in Python on Windows

Disable Python aliases:

(more…)

Migrating a WordPress website from PHP 7.4 to PHP 8.3.6

After updated my WordPress to 6.7.1 and added the following to wp-config.php

define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );

and got the following error message:

Fatal error: Uncaught Error: Call to undefined function wp_kses() in /home/devnote/www/wp-includes/functions.php:6098 Stack trace: 
#0 /home/devnote/www/wp-includes/functions.php(5579): wp_trigger_error()
#1 /home/devnote/www/wp-includes/class-wpdb.php(1333): _deprecated_function()
#2 /home/devnote/www/wp-content/sunrise.php(11): wpdb->escape()
#3 /home/devnote/www/wp-includes/ms-settings.php(47): include_once('...')
#4 /home/devnote/www/wp-settings.php(156): require('...')
#5 /home/devnote/www/wp-config.php(107): require_once('...')
#6 /home/devnote/www/wp-load.php(50): require_once('...')
#7 /home/devnote/www/wp-blog-header.php(13): require_once('...')
#8 /home/devnote/www/index.php(17): require('...')
#9 {main} thrown in /home/devnote/www/wp-includes/functions.php on line 6098
(more…)

How I fixed wrong colors in my QML app on Android

I removed android:theme from AndroidManifest.xml:

<activity android:name="net.geographx.MainActivity"
    android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation|mcc|mnc|density"
    android:label="@string/app_name"
    android:theme="@style/AppTheme"
    android:launchMode="singleTask"
    android:screenOrientation="portrait"
    android:exported="true">
    <!-- Splash screen -->
    <meta-data android:name="android.app.splash_screen_drawable" android:resource="@drawable/splash"/>
    <!-- Splash screen -->
(more…)