Skip to content

Instantly share code, notes, and snippets.

View selimanac's full-sized avatar

Selim Anaç selimanac

View GitHub Profile
// color1 and color2 are R4G4B4 12bit RGB color values, alpha is 0-255
uint16_t blend_12bit( uint16_t color1, uint16_t color2, uint8_t alpha ) {
uint64_t c1 = (uint64_t) color1;
uint64_t c2 = (uint64_t) color2;
uint64_t a = (uint64_t)( alpha >> 4 );
// bit magic to alpha blend R G B with single mul
c1 = ( c1 | ( c1 << 12 ) ) & 0x0f0f0f;
c2 = ( c2 | ( c2 << 12 ) ) & 0x0f0f0f;
uint32_t o = ( ( ( ( c2 - c1 ) * a ) >> 4 ) + c1 ) & 0x0f0f0f;
@aglitchman
aglitchman / device.lua
Last active October 23, 2024 16:02
Detect operating system (iOS, Android, Blackberry, Windows, Firefox OS, MeeGo), orientation (Portrait vs. Landscape), and type (Tablet vs. Mobile). Lua module for the Defold game engine.
-- Based on the device.js module: https://github.com/matthewhudson/current-device
-- MIT License
--
-- Usage:
-- local device = require("device")
-- if device.type == "mobile" then
-- -- do something!
-- end
--
-- Or:
@lennardv2
lennardv2 / 1. Building PHP-MAMP on Apple Silicon M1.md
Last active February 25, 2025 15:28
Native PHP development / MAMP stack on Apple silicon M1

Building the MAMP stack (php, apache & mysql) on Apple Silicon ARM (native)

Update! This tutorial is outdated. Nowadays brew installes m1 binaries just fine. Also use valet: https://laravel.com/docs/9.x/valet. It's 10x easier.

In this tutorial, we'll build the the nescessary packages for ARM via homebrew. After that we'll configure apache2 for using virtual hosts. The native php is ofcourse way faster, see the results of this benchmark below.

TEST NAME SECONDS OP/SEC
@Reedbeta
Reedbeta / interesting-libs.txt
Last active July 4, 2023 02:38
Interesting libraries I might like to use in a project
Interesting libraries I might like to use in a project...
Asset loading:
assetsys.h - virtual filesystem with ZIP backing, overlaying, etc https://github.com/mattiasgustavsson/libs/blob/master/docs/assetsys.md
cute_filewatch.h - file modification watching, for runtime reloading etc https://github.com/RandyGaul/cute_headers/blob/master/cute_filewatch.h
flatbuffers - data serialization, zero-copy deserialization, extensible schemas https://github.com/google/flatbuffers
stb_image - https://github.com/nothings/stb/blob/master/stb_image.h
tinyexr - https://github.com/syoyo/tinyexr
tinygltf - https://github.com/syoyo/tinygltf
tinyobjloader - https://github.com/syoyo/tinyobjloader
@vurtun
vurtun / _GJK.md
Last active March 3, 2025 15:26
3D Gilbert–Johnson–Keerthi (GJK) distance algorithm

Gilbert–Johnson–Keerthi (GJK) 3D distance algorithm

The Gilbert–Johnson–Keerthi (GJK) distance algorithm is a method of determining the minimum distance between two convex sets. The algorithm's stability, speed which operates in near-constant time, and small storage footprint make it popular for realtime collision detection.

Unlike many other distance algorithms, it has no requirments on geometry data to be stored in any specific format, but instead relies solely on a support function to iteratively generate closer simplices to the correct answer using the Minkowski sum (CSO) of two convex shapes.

@mathiaswking
mathiaswking / android_deploy.sh
Last active June 18, 2019 07:24
Deploys an .apk to the USB connected Android device. Starts the app, and grabs the logging events for that PID
#!/usr/bin/env bash
#set -e
PACKAGE=$1
if [ -z "$PACKAGE" ]; then
echo "You must pass a .apk as input!"
exit 1
fi
@britzl
britzl / luautils.cpp
Last active September 1, 2019 14:02
Lua C utility functions for manipulating the stack and setting up listeners
#include <dmsdk/sdk.h>
#include "luautils.h"
void luaL_checklistener(lua_State* L, int idx, struct lua_Listener& listener) {
int top = lua_gettop(L);
luaL_checktype(L, idx, LUA_TFUNCTION);
lua_pushvalue(L, idx);
int cb = dmScript::Ref(L, LUA_REGISTRYINDEX);
if (listener.m_Callback != LUA_NOREF) {
@TeoTwawki
TeoTwawki / example.lua
Last active April 6, 2019 08:40
Weighted Random Selection in pure Lua
function WeightedRandomSelect(tableID)
local outerTable =
{
[1] =
{
{weightValue, thingValue},
{weightValue, thingValue}
},
[2] =
{
@AGulev
AGulev / swipe.lua
Last active November 22, 2021 15:54
adoptation of swipe-direction script by ScottPhillips https://github.com/ScottPhillips/swipe-direction/blob/master/swipe-direction.lua for Defold engine
local beginX
local beginY
local endX
local endY
local startTime
local xDistance
local yDistance
@thennequin
thennequin / DisplayInImGui.cpp
Last active November 16, 2022 16:00
Ini Config Reader/Writer
Ini::IniConfig& m_oIniConfig;
Ini::CategoryValueMap& mCategories = m_oIniConfig.GetCategories();
if (ImGui::Button("Reload"))
{
m_oIniConfig.Load("Config.ini", true, false);
}
ImGui::SameLine();
if (ImGui::Button("Save"))