Skip to content

Instantly share code, notes, and snippets.

James Darpinian jdarpinian

Block or report user

Report or block jdarpinian

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
jdarpinian / C and shell polyglot.cmd
Last active May 20, 2019
Polyglot files that can run on Windows, Linux, and Mac using bash, cmd, and C.
View C and shell polyglot.cmd
#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" "$@"
@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 / executable.c
Last active Oct 2, 2019
Add one line to your C/C++ source to make it executable.
View executable.c
///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;
jdarpinian / hello-world.shc
Last active Feb 6, 2018
Directly execute C source code by embedding in a bash script.
View hello-world.shc
COMPILER_OPTIONS="-g -Wall -Wextra --std=c11 -O1 -fsanitize=address,undefined"
#include <stdio.h>
int main() {
printf("Hello world!\n");
return 0;
jdarpinian /
Last active Feb 13, 2018
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
#include <GLFW/glfw3.h>
#include <stdio.h>
static GLFWwindow *window = NULL;
static int swapAndPollInput();
static void run() {

Keybase proof

I hereby claim:

  • I am jdarpinian on github.
  • I am 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 / .bashrc
Last active Apr 13, 2018
Essential Linux config file additions that should be the default
View .bashrc
# Eternal bash history.
# ---------------------
# Undocumented feature which sets the size to "unlimited".
export HISTSIZE=
export HISTTIMEFORMAT="[%F %T] "
# Change the file location because certain bash sessions truncate .bash_history file upon close.
export HISTFILE=~/.bash_eternal_history
You can’t perform that action at this time.