Skip to content

Instantly share code, notes, and snippets.

@nus
nus / main.cpp
Last active March 10, 2025 15:57
An example of emscripten with WebSocket.
// $ em++ -lwebsocket.js -o index.html main.cpp
#include <emscripten/emscripten.h>
#include <emscripten/websocket.h>
#include <stdio.h>
EM_BOOL onopen(int eventType, const EmscriptenWebSocketOpenEvent *websocketEvent, void *userData) {
puts("onopen");
EMSCRIPTEN_RESULT result;
timers = {}
function after(delay, action, repeatable, after, tag)
local tag = tag or uid() -- uid returns a unique id every time it's called, "or" will resolve the expression to the result of uid() if tag is nil (the same as if not tag then tag = uid() end)
timers[tag] = {type = 'after', current_time = 0, delay = delay, action = action, repeatable = repeatable, after = after, tag = tag}
end
function tween(delay, target, source, method, after, tag)
local tag = tag or uid()
local initial_values = {}
#include <stdio.h>
#include "bgfx/bgfx.h"
#include "bgfx/platform.h"
#include "bx/math.h"
#include "GLFW/glfw3.h"
#define GLFW_EXPOSE_NATIVE_WIN32
#include "GLFW/glfw3native.h"
#define WNDW_WIDTH 1600
#define WNDW_HEIGHT 900
@skizhak
skizhak / build-static-v8-libs.sh
Last active October 20, 2024 05:39
Build and generate static v8 library
#Run build-v8.sh to setup deps.
gn gen "--args=is_clang=true is_component_build=false v8_static_library=true use_custom_libcxx=false target_cpu=\"x64\"" out.gn/x64.Release
ninja -C out.gn/x64.Release/
@nicebyte
nicebyte / dyn_arr.h
Last active February 25, 2025 10:29
dyn_arr
#pragma once
#define DYN_ARR_OF(type) struct { \
type *data; \
type *endptr; \
uint32_t capacity; \
}
#if !defined(__cplusplus)
#define decltype(x) void*
@gcatlin
gcatlin / glfw-metal-example.m
Last active February 24, 2025 15:14
Minimal C GLFW Metal example
//
// cc glfw-metal-example.m `pkg-config --cflags --libs glfw3` -framework AppKit -framework Metal -framework QuartzCore
//
#define GLFW_INCLUDE_NONE
#define GLFW_EXPOSE_NATIVE_COCOA
#include <GLFW/glfw3.h>
#include <GLFW/glfw3native.h>
#import <Metal/Metal.h>
#import <QuartzCore/CAMetalLayer.h>
@fnky
fnky / ANSI.md
Last active May 9, 2025 16:07
ANSI Escape Codes

ANSI Escape Sequences

Standard escape codes are prefixed with Escape:

  • Ctrl-Key: ^[
  • Octal: \033
  • Unicode: \u001b
  • Hexadecimal: \x1B
  • Decimal: 27
@gcatlin
gcatlin / sdl-metal-example.m
Last active February 24, 2025 15:11
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");
@Aerijo
Aerijo / tree_sitter_guide.md
Last active February 17, 2025 23:42
Guide to writing your first Tree-sitter grammar

Guide to your first Tree-sitter grammar

NOTE: The Tree-sitter API and documentation has changed and improved since this guide was created. I can't guarantee this is up to date.

About

Tree-sitter is the new way Atom is providing language recognition features, such as syntax highlighting, code folding, autocomplete, and more. In contrast to TextMate grammars, which work by regex matching, Tree-sitter will generate an entire syntax tree. But more on that can be found in it's own docs.

Here, we look at making one from scratch.

@sherjilozair
sherjilozair / celeste.lua
Created June 17, 2018 19:18
Source code for pico-8 version of Celeste
-- ~celeste~
-- matt thorson + noel berry
-- globals --
-------------
room = { x=0, y=0 }
objects = {}
types = {}
freeze=0