Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View jdarpinian's full-sized avatar

James Darpinian jdarpinian

View GitHub Profile

Keybase proof

I hereby claim:

  • I am jdarpinian on github.
  • I am jdarpinian (https://keybase.io/jdarpinian) on keybase.
  • I have a public key whose fingerprint is 2C59 2125 3786 AF9E 768E 09E3 EFE8 D4D7 3ADD 8643

To claim this, I am signing this object:

@jdarpinian
jdarpinian / hello-world.shc
Last active February 6, 2018 12:17
Directly execute C source code by embedding in a bash script.
#!/bin/bash
COMPILER_OPTIONS="-g -Wall -Wextra --std=c11 -O1 -fsanitize=address,undefined"
SOURCE_CODE=$(cat <<'END_OF_SOURCE_CODE'
#include <stdio.h>
int main() {
printf("Hello world!\n");
return 0;
}
@jdarpinian
jdarpinian / gl-test.cc
Last active February 13, 2018 00:00
A minimal test app for OpenGL using GLFW, with nice defaults for debugging (ASAN, glDebugMessageCallback)
//usr/bin/make LDLIBS="-lGL -lglfw" CPPFLAGS="-Wall -Wextra -g -O1 -fno-omit-frame-pointer -fsanitize=address,undefined" -s "${0%.*}"&&exec "${0%.*}" "$@";exit
#define GLFW_INCLUDE_GLCOREARB
#define GL_GLEXT_PROTOTYPES
#include <GLFW/glfw3.h>
#include <stdio.h>
static GLFWwindow *window = NULL;
static int swapAndPollInput();
static void run() {
@jdarpinian
jdarpinian / .bashrc
Last active April 13, 2018 22:35
Essential Linux config file additions that should be the default
# Eternal bash history.
# ---------------------
# Undocumented feature which sets the size to "unlimited".
# http://stackoverflow.com/questions/9457233/unlimited-bash-history
export HISTFILESIZE=
export HISTSIZE=
export HISTTIMEFORMAT="[%F %T] "
# Change the file location because certain bash sessions truncate .bash_history file upon close.
# http://superuser.com/questions/575479/bash-history-truncated-to-500-lines-on-each-login
export HISTFILE=~/.bash_eternal_history
@jdarpinian
jdarpinian / C and shell polyglot.cmd
Last active August 7, 2023 09:42
Polyglot files that can run on Windows, Linux, and Mac using bash, cmd, and C.
#if 0 // 2>NUL & GOTO :startbatch
COMPILER_OPTIONS="-g -Wall -Wextra --std=c99 -O1";THIS_FILE="$(cd "$(dirname "$0")"; pwd -P)/$(basename "$0")";OUT_FILE="/tmp/build-cache/$THIS_FILE";mkdir -p "$(dirname "$OUT_FILE")";test "$THIS_FILE" -ot "$OUT_FILE" || $(which clang || which gcc) $COMPILER_OPTIONS -xc "$THIS_FILE" -o "$OUT_FILE" || exit;exec "$OUT_FILE" "$@"
:startbatch
@echo off
setlocal enableextensions enabledelayedexpansion
md %TEMP%%~p0 2>NUL
rem Use xcopy to test if this file is newer than the cached executable.
for /f %%i in ('xcopy %0 %TEMP%%~pnx0.exe /D /Y /Q') do set copied=%%i
if "%copied:~0,1%" neq "0" (
rem Search for Visual Studio env vars. These are set globally if VS <2017 is installed.
@jdarpinian
jdarpinian / executable.c
Last active March 20, 2024 15:28
Add one line to your C/C++ source to make it executable.
///bin/true;COMPILER_OPTIONS="-g -Wall -Wextra --std=c99 -O1 -fsanitize=address,undefined";THIS_FILE="$(cd "$(dirname "$0")"; pwd -P)/$(basename "$0")";OUT_FILE="/tmp/build-cache/$THIS_FILE";mkdir -p "$(dirname "$OUT_FILE")";test "$THIS_FILE" -ot "$OUT_FILE" || $(which clang || which gcc) $COMPILER_OPTIONS -xc "$THIS_FILE" -o "$OUT_FILE" || exit;exec "$OUT_FILE" "$@"
#include <stdio.h>
int main() {
printf("Hello world!\n");
return 0;
}