Skip to content

Instantly share code, notes, and snippets.

View ericoporto's full-sized avatar
🎮
making

Érico Porto ericoporto

🎮
making
View GitHub Profile
@benhoyt
benhoyt / markov.py
Created November 11, 2023 15:45
Generate text from an input using a simple Markov chain generator
import collections, random, sys, textwrap
# Build possibles table indexed by pair of prefix words (w1, w2)
w1 = w2 = ''
possibles = collections.defaultdict(list)
for line in sys.stdin:
for word in line.split():
possibles[w1, w2].append(word)
w1, w2 = w2, word
@rounk-ctrl
rounk-ctrl / Dark.md
Last active April 7, 2024 16:00
Win32 Dark Mode

Dark Mode APIs.

API Signatures.

ShouldAppsUseDarkMode()

Checks whether system is using dark mode or not.
Signature:

using fnShouldAppsUseDarkMode = bool (WINAPI*)(); // ordinal 132

AllowDarkModeForWindow(In HWND hWnd, In bool allow)

Introduction

Here are some rough notes on building Kirikiri SDL2 for iOS and Android.
Please note that these may or may not be incomplete. Improved documentation is being planned, but not started yet.

Startup Directory selection

For iOS, the startup directory will be searched in <app name>.app/Contents/Resources/.
For Android, the startup directory will be searched in the root of the assets directory embedded in the apk. For best performance, the file should be stored uncomompressed.

Startup folder candidates:

@bdsl
bdsl / matt-Hancock-mp-We must all do everything in our power to protect lives.md
Last active March 17, 2020 06:53
We must all do everything in our power to protect lives - Matt Hancock MP Secretary of State for Health and Social Care - The Telegraph 14 Mach 2020
@Jolg42
Jolg42 / readme.md
Created January 25, 2020 14:13
Code Signing on macOS and Windows + Apple Notarization

macOS

Steps

  • What we want is to get a Developer Id https://developer.apple.com/developer-id/ to be able to sign the binaries for distribution.
  • The company needs to get an Apple Developer Account Membership for macOS for $99/y https://developer.apple.com/programs/enroll/
  • Apple needs a A D-U-N-S® Number to register the account, the person doing the registration will need to get in touch with somebody that knows the legal part.
  • The registration could take a couple days
  • When done, a certificate can be created for signing, you'll need to sync it with Xcode.
  • Now the binary can be signed, and the signature can be verified.
#!/bin/bash
PROJ="/path/to/your/project/"
NAME="MyAwesomeGame"
SVER="1.0.0"
GODOT="/Applications/Godot.app/Contents/MacOS/Godot --path ${PROJ}/src"
###
# Mac OSX (RELEASE)
#include <stdio.h>
#include <SDL2/SDL.h>
#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#endif
static int count = 0;
static SDL_Surface* screen = NULL;
static SDL_Texture* sdlTexture = NULL;
static SDL_Renderer* sdlRenderer = NULL;

Why COW was deemed ungood for std::string.

COW, short for copy on write, is a way to implement mutable strings so that creating strings and logically copying strings, is reduced to almost nothing; conceptually they become free operations like no-ops.

Basic idea: to share a data buffer among string instances, and only make a copy for a specific instance (the copy on write) when that instance's data is modified. The general cost of this is only an extra indirection for accessing the value of a string, so a COW implementation is highly desirable. And so the original C++ standard, C++98, and its correction C++03, had special support for COW implementations, and e.g. the g++ compiler's std::string implementations used COW.

So why was that support dropped in C++11?

In particular, would the same reason or reasons apply to a reference counted immutable string value class?

// Uncompressed version of
// https://gist.github.com/munificent/b1bcd969063da3e6c298be070a22b604
#include <time.h> // Robert Nystrom
#include <stdio.h> // @munificentbob
#include <stdlib.h> // for Ginny
#include <stdbool.h> // 2008-2019
const int HEIGHT = 40;
const int WIDTH = 80;
@gcatlin
gcatlin / sdl-metal-example.m
Last active March 1, 2024 13:13
Minimal C SDL2 Metal example
//
// cc sdl-metal-example.m `sdl2-config --cflags --libs` -framework Metal -framework QuartzCore && ./a.out
//
#include <SDL.h>
#import <Metal/Metal.h>
#import <QuartzCore/CAMetalLayer.h>
int main (int argc, char *args[])
{
SDL_SetHint(SDL_HINT_RENDER_DRIVER, "metal");