Skip to content

Instantly share code, notes, and snippets.

@gcatlin
gcatlin / sdl-metal-example.m
Last active April 20, 2024 13:04
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");
@gcatlin
gcatlin / core-audio-sine-wave.c
Last active April 3, 2024 04:23
Core Audio sine wave example
// To run:
// clang core-audio-sine-wave.c -framework AudioUnit && ./a.out
#include <AudioUnit/AudioUnit.h>
#define SAMPLE_RATE 48000
#define TONE_FREQUENCY 440
#define M_TAU 2.0 * M_PI
OSStatus RenderSineWave(
void *inRefCon,
@gcatlin
gcatlin / glfw-metal-example.m
Last active March 23, 2024 18:13
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>
@gcatlin
gcatlin / sdl-opengl-example.c
Last active September 2, 2023 17:21
Minimal C SDL2 OpenGL example
//
// cc main.c glad.c -lSDL2
//
#include "glad.h" // https://glad.dav1d.de/
#include <SDL2/SDL.h>
#include <SDL2/SDL_opengl.h>
#include <stdbool.h>
int main()
{
@gcatlin
gcatlin / gist:1847248
Created February 16, 2012 19:43
Install specific version of Homebrew formula
brew update
brew versions FORMULA
cd `brew --prefix`
git checkout HASH Library/Formula/FORMULA.rb # use output of "brew versions"
brew install FORMULA
brew switch FORMULA VERSION
git checkout -- Library/Formula/FORMULA.rb # reset formula
## Example: Using Subversion 1.6.17
#
@gcatlin
gcatlin / glfw-opengl-example.c
Last active February 19, 2022 03:07
Minimal C GLFW OpenGL example
//
// cc glfw-opengl-example.c glad.c -lglfw
//
#include "glad.h" // https://glad.dav1d.de/
#include <GLFW/glfw3.h>
static void quit(GLFWwindow *window, int key, int scancode, int action, int mods)
{
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) {
glfwSetWindowShouldClose(window, GLFW_TRUE);
@gcatlin
gcatlin / ncurses.diff
Created July 12, 2012 14:28
Homebrew Ncurses clang patch
diff --git a/ncurses.rb b/ncurses.rb
index 1067083..8cc12bc 100644
--- a/ncurses.rb
+++ b/ncurses.rb
@@ -23,4 +23,9 @@ class Ncurses < Formula
system "make"
system "make install"
end
+
+ def patches
@gcatlin
gcatlin / keybase.md
Created March 12, 2019 00:26
keybase.md

Keybase proof

I hereby claim:

  • I am gcatlin on github.
  • I am gcatlin (https://keybase.io/gcatlin) on keybase.
  • I have a public key ASDOkhxPwBV28ND_Pzm3rzNcVWViUFUakYvCgFb8dC-kiQo

To claim this, I am signing this object:

@gcatlin
gcatlin / gist:1897059
Created February 24, 2012 03:19
Set short keyboard delay and fast repeat rate on OS X
# Source: http://quickies.seriot.ch/index.php?id=411
defaults write NSGlobalDomain InitialKeyRepeat -int 7
defaults write NSGlobalDomain KeyRepeat -int 0
@gcatlin
gcatlin / multiple-error-handlers.php
Created May 30, 2013 13:53
Adds support for multiple error handlers in PHP
<?php
function append_error_handler($handler) {
set_error_handlers(array(set_error_handler($handler), $handler));
}
function prepend_error_handler($handler) {
set_error_handlers(array($handler, set_error_handler($handler)));
}