Skip to content

Instantly share code, notes, and snippets.

View Shtille's full-sized avatar

Vladimir Shtille

  • Moscow
View GitHub Profile
@Shtille
Shtille / font_weight.cpp
Last active March 28, 2025 15:43
Get font weight by its style name
static int GetFontWeight(const std::string& styleStr)
{
std::string lowerStr = ::ToLower(styleStr);
const char* style = lowerStr.c_str();
if (std::strlen(style) == 0 ||
std::strstr(style, "normal") != nullptr ||
std::strstr(style, "regular") != nullptr)
return 400;
else if (std::strstr(style, "thin") != nullptr)
return 100;
@Shtille
Shtille / points_to_pixels.cpp
Created February 21, 2025 13:14
Text size convertation from point size to pixel size and vice versa
static inline float PointsToPixels(float points, float dpi)
{
// 1 pt = 0.352778 mm
float mm = 0.352778f * points;
// 1 inch = 25.4 mm
float inches = mm / 25.4f;
return dpi * inches;
}
static inline float PixelsToPoints(float pixels, float dpi)
{
@Shtille
Shtille / data_cache.hpp
Created February 4, 2025 12:15
Cache for data to be shared between different instances
#include <map>
#include <memory>
template <class Key, class Data>
class DataCache
{
public:
template<typename... Args>
std::shared_ptr<Data> GetData(const Key& key, Args... args)
{
@Shtille
Shtille / font_locations.cpp
Created January 14, 2025 09:27
Get platform-specific font locations
#if defined(_WIN32) || defined(_WIN64) // Windows
# include <shlobj.h>
#endif
#include <string>
#include <vector>
#include <filesystem>
static std::vector<std::wstring> GetStandardFontsLocations()
{
@Shtille
Shtille / drag_auto_scroller.js
Created July 1, 2024 10:20
Auto scrolling while dragging (JavaScript)
/**
* Drag scroller 0.2.0
* @author Shtille <[email protected]>
* @license MIT
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = global || self, global.DragAutoScroller = factory());
}(this, (function() { 'use strict';
@Shtille
Shtille / pack_file.js
Created April 27, 2023 14:40
Inflates file content and encodes as base64
/**
* To use this module simply run:
* ~~~{.sh}
* node pack_file.js
* ~~~
*/
const fs = require('fs');
const zlib = require('zlib');
@Shtille
Shtille / build-so.sh
Created April 7, 2022 15:45
Shell script to build shared library for Android via CMake build system
#!/bin/zsh
android_abi=armeabi-v7a
android_platform=android-19
path_to_cmakelists=~/Documents/dev/src/smartplatform-CMake
path_to_generated=~/Documents/dev/src/build
path_to_ndk=~/Library/Android/sdk/ndk/24.0.8215888
path_to_ninja=/usr/local/bin/ninja
@Shtille
Shtille / spin_perf.cpp
Created February 11, 2022 10:48
Custom spinlock vs pthread one speed comparison
#include <cstdlib>
#include <cstdio>
#include <thread>
#include <string>
#include <chrono>
#include <atomic>
#include <pthread.h>
class ScopeTimer {
@Shtille
Shtille / lru-cache.js
Created August 10, 2021 00:40
Simple LRU cache on pure JavaScript
/**
* Copyright (c) 2021 Vladimir Sviridov.
* Distributed under the MIT License (license terms are at http://opensource.org/licenses/MIT).
*
* Module defines LRU cache class.
*/
/**
* Defines LRU cache
*
@Shtille
Shtille / custom_app_bar.dart
Created October 29, 2020 13:19
Custom app bar
import 'package:flutter/material.dart';
/// Custom appbar with custom paddings and height
class MyCustomAppBar extends StatelessWidget implements PreferredSizeWidget {
final double _height;
final Widget Function(BuildContext context) _builder;
/// Builds custom app bar with [height] and [builder].
const MyCustomAppBar({
Key key,