Skip to content

Instantly share code, notes, and snippets.

View equalent's full-sized avatar
🍉

Andrei Tsurkan equalent

🍉
View GitHub Profile
@equalent
equalent / dxgi_format.h
Last active June 15, 2021 15:29
DXGI format utils
#pragma once
constexpr size_t DxgiFormatRowSize(DXGI_FORMAT format, uint width)
{
switch (format)
{
case DXGI_FORMAT_R32G32B32A32_TYPELESS:
case DXGI_FORMAT_R32G32B32A32_FLOAT:
case DXGI_FORMAT_R32G32B32A32_UINT:
case DXGI_FORMAT_R32G32B32A32_SINT:
@equalent
equalent / rd_vis_bc5nrm.hlsl
Last active June 12, 2021 18:24
Unpack a normal map. Use with BC5-encoded normal map to reconstruct Z and remap the values to [-1, 1] range
/*
A BC5 normal map texture visualization shader for RenderDoc.
Usage:
1. Save this to %APPDATA%/qrenderdoc/ on Windows or ~/.local/share/qrenderdoc elsewhere
2. Set Channels mode to Custom in RenderDoc Texture Viewer
3. Select the shader from the dropdown menu
*/
SamplerState pointSampler : register(s0);
Texture2DArray<float4> texDisplayTex2DArray : register(t2);
@equalent
equalent / mandelbrot.html
Created September 15, 2020 14:18
Simple JS + WebGL Mandelbrot set implementation
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>MANDELBROT</title>
</head>
<body style="font-family: sans-serif;">
@equalent
equalent / Qt 5 Dark Fusion Palette
Created February 3, 2020 23:56 — forked from QuantumCD/Qt 5 Dark Fusion Palette
This is a complete (I think) dark color palette for the Qt 5 Fusion theme, as well as a nice style sheet for the tool tips that make them blend better with the rest of the theme. To have immediate effect, be sure to put this in your main function before showing the parent window. Child windows should automatically inherit the palette unless you …
qApp->setStyle(QStyleFactory::create("Fusion"));
QPalette darkPalette;
darkPalette.setColor(QPalette::Window, QColor(53,53,53));
darkPalette.setColor(QPalette::WindowText, Qt::white);
darkPalette.setColor(QPalette::Base, QColor(25,25,25));
darkPalette.setColor(QPalette::AlternateBase, QColor(53,53,53));
darkPalette.setColor(QPalette::ToolTipBase, Qt::white);
darkPalette.setColor(QPalette::ToolTipText, Qt::white);
darkPalette.setColor(QPalette::Text, Qt::white);
@equalent
equalent / ack_short.py
Created October 10, 2019 16:13 — forked from justjkk/ack_short.py
Ackermann Function in python
import sys
count=0
sys.setrecursionlimit(50000)
cache={}
def a(m,n):
global count
global cache
count=count+1
if cache.has_key(m) and cache[m].has_key(n):
return cache[m][n]
@equalent
equalent / aligned_malloc.cpp
Created October 1, 2019 15:52 — forked from ashwin/aligned_malloc.cpp
Aligned memory allocation
// Assume we need 32-byte alignment for AVX instructions
#define ALIGN 32
void *aligned_malloc(int size)
{
// We require whatever user asked for PLUS space for a pointer
// PLUS space to align pointer as per alignment requirement
void *mem = malloc(size + sizeof(void*) + (ALIGN - 1));
// Location that we will return to user
@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();