Skip to content

Instantly share code, notes, and snippets.

View equalent's full-sized avatar
🍉

Andrei Tsurkan equalent

🍉
View GitHub Profile
@equalent
equalent / color_from_kelvin.py
Created August 27, 2019 10:58
Color from light temperature
from math import log
k = int(input("Kelvin: "))//100
(r,g,b) = (0,0,0)
# RED:
if k <= 66:
r=255
@equalent
equalent / capture.cpp
Created August 18, 2019 16:41 — forked from holmesconan/capture.cpp
Capture screen by GDI on Windows
HDC hdc = GetDC(NULL); // get the desktop device context
HDC hDest = CreateCompatibleDC(hdc); // create a device context to use yourself
// get the height and width of the screen
int height = GetSystemMetrics(SM_CYVIRTUALSCREEN);
int width = GetSystemMetrics(SM_CXVIRTUALSCREEN);
// create a bitmap
HBITMAP hbDesktop = CreateCompatibleBitmap( hdc, width, height);
@equalent
equalent / bs_01.py
Created August 17, 2019 15:03
Simple search vs binary search vs CPython list index
from typing import List
from random import randint
import timeit
def simple_search(haystack: List[int], needle: int):
for idx, i in enumerate(haystack):
if i == needle:
return idx
@equalent
equalent / framelimit.cpp
Created August 9, 2019 01:14
Limit framerate at 5 Hz (200 ms)
// source: https://web.archive.org/web/20190809011021/https://stackoverflow.com/questions/38730273/how-to-limit-fps-in-a-loop-with-c
// cody by HolyBlackCat
#include <iostream>
#include <cstdio>
#include <chrono>
#include <thread>
std::chrono::system_clock::time_point a = std::chrono::system_clock::now();
std::chrono::system_clock::time_point b = std::chrono::system_clock::now();
#if defined(_MSC_VER)
_CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF|_CRTDBG_ALLOC_MEM_DF);
_CrtSetReportMode(_CRT_ASSERT,_CRTDBG_MODE_FILE);
_CrtSetReportFile(_CRT_ASSERT,_CRTDBG_FILE_STDERR);
#endif
// InstructionSet.cpp
// Compile by using: cl /EHsc /W4 InstructionSet.cpp
// processor: x86, x64
// Uses the __cpuid intrinsic to get information about
// CPU extended instruction set support.
#include <iostream>
#include <vector>
#include <bitset>
#include <array>
@equalent
equalent / human-size.c
Created July 23, 2019 09:00 — forked from dgoguerra/human-size.c
Format a quantity in bytes into a human readable string (C)
#include <stdio.h>
#include <stdlib.h> // atoll
#include <stdint.h> // uint64_t
#include <inttypes.h> // PRIu64
static const char *humanSize(uint64_t bytes)
{
char *suffix[] = {"B", "KB", "MB", "GB", "TB"};
char length = sizeof(suffix) / sizeof(suffix[0]);
@equalent
equalent / fw.cpp
Created July 21, 2019 15:20
Fullscreen/Windowed
bool GoFullscreen()
{
// turn off window region without redraw
SetWindowRgn(m_hWindow, 0, false);
DEVMODE newSettings;
// request current screen settings
EnumDisplaySettings(0, 0, &newSettings);
@equalent
equalent / dxrcheck_cmd.cpp
Last active July 21, 2019 08:06
Full code for DXR check
// Copyright (c) 2019 Antinomy Interactive. All rights reserved.
// PURPOSE: Check for DXR support
// AUTHOR: Andrey Tsurkan (andrey.turcan@hotmail.com)
#include <iostream>
#include <sstream>
#include <string>
#include <windows.h>
#include <dxgi.h>
#include <d3d12.h>
@equalent
equalent / dxrcheck.h
Last active July 21, 2019 05:19
Check DirectX Raytracing support [WITH COMMENTS]
inline bool IsDirectXRaytracingSupported(IDXGIAdapter1* adapter)
{
ComPtr<ID3D12Device> testDevice;
D3D12_FEATURE_DATA_D3D12_OPTIONS5 featureSupportData = {};
// create Direct3D 12 device with 11.0 FL
// IID_PPV_ARGS automatically computes interface ID (REFIID that equals to IID_ID3D12Device)
// and the pointer and passes them as two comma-separated arguments
return SUCCEEDED(D3D12CreateDevice(adapter, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&testDevice)))
// check support for OPTIONS5 (will work only on Windows 10 1803+)