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
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" "$@"
: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 Dec 15, 2018
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
jdarpinian / hello-world.shc
Last active Feb 6, 2018
Directly execute C source code by embedding in a bash script.
View hello-world.shc
#!/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 Feb 13, 2018
A minimal test app for OpenGL using GLFW, with nice defaults for debugging (ASAN, glDebugMessageCallback)
View gl-test.cc
//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() {
View keybase.md

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 / .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".
# 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
You can’t perform that action at this time.