Skip to content

Instantly share code, notes, and snippets.

View ricejasonf's full-sized avatar

Jason Rice ricejasonf

  • Henderson, NV
View GitHub Profile
@chadaustin
chadaustin / tmpfile.cpp
Last active January 11, 2018 00:30
How to atomically write a file without giving it a temporary name
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
// Can't get O_TMPFILE to work for some reason.
#ifndef __O_TMPFILE
# define __O_TMPFILE (020000000 | __O_DIRECTORY)
#endif
@badair
badair / function_type.cpp
Last active December 17, 2018 18:07
function_type - reference implementation
/*
(c) copyright Barrett Adair 2017
Distributed under the Boost Software License - Version 1.0 - August 17th, 2003
Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:
The copyright notices in the Software and this entire statement, including
@danguita
danguita / docker-machine-ssh-tunneling.md
Last active June 26, 2020 16:43
Docker Machine SSH tunneling

As described on the Docker Machine SSH reference, the docker-machine CLI invokes the standard OpenSSH client so we can use the common SSH tunneling syntax here. The following command will forward port 3000 from the default machine to localhost on your host computer's loopback interface. Using 0.0.0.0 as bind_address will make it bind to all interfaces:

$ docker-machine ssh default -L 0.0.0.0:3000:localhost:3000

So, the container running at machine's port 3000 can be reached through localhost:3000 or any of your interfaces' IP (i.e. 192.168.1.10:3000). That'd be useful to access your containerized services from other devices in your LAN.

@danguita

@kus
kus / fixIOSAudioContext.js
Last active March 27, 2024 11:21
Fix iOS AudioContext on Safari not playing any audio. It needs to be "warmed up" from a user interaction, then you can play audio with it as normal throughout the rest of the life cycle of the page.
// Fix iOS Audio Context by Blake Kus https://gist.github.com/kus/3f01d60569eeadefe3a1
// MIT license
(function() {
window.AudioContext = window.AudioContext || window.webkitAudioContext;
if (window.AudioContext) {
window.audioContext = new window.AudioContext();
}
var fixAudioContext = function (e) {
if (window.audioContext) {
// Create empty buffer
@socantre
socantre / CMakeLists.txt
Created August 24, 2015 03:45
Example of using add_custom_command and add_custom_target together in CMake to handle custom build steps with minimal rebuilding: This example untars library headers for an INTERFACE library target
set(LIBFOO_TAR_HEADERS
"${CMAKE_CURRENT_BINARY_DIR}/include/foo/foo.h"
"${CMAKE_CURRENT_BINARY_DIR}/include/foo/foo_utils.h"
)
add_custom_command(OUTPUT ${LIBFOO_TAR_HEADERS}
COMMAND ${CMAKE_COMMAND} -E tar xzf "${CMAKE_CURRENT_SOURCE_DIR}/libfoo/foo.tar"
COMMAND ${CMAKE_COMMAND} -E touch ${LIBFOO_TAR_HEADERS}
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/include/foo"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/libfoo/foo.tar"
@jimporter
jimporter / build-boost-libc++
Last active August 7, 2022 20:10
Build Boost against libc++
#!/bin/sh
# First, build libc++ See <http://libcxx.llvm.org/>, "Build on Linux using CMake
# and libsupc++." and substitute libsupc++ for libstdc++. NOTE: You'll probably
# need to explicitly link libsupc++ when you compile your own code!
#
# Next, download Boost and extract it somewhere. Set SRC_DIR to that location.
SRC_DIR=$HOME/src/boost_1_55_0
# Set this to be the install prefix. "/usr" is also a good choice.
@tibordp
tibordp / variant.cc
Last active May 7, 2024 02:40
A simple variant type implementation in C++
#include <iostream>
#include <utility>
#include <typeinfo>
#include <type_traits>
#include <string>
template <size_t arg1, size_t ... others>
struct static_max;
template <size_t arg>
@johngibb
johngibb / install-git-completion.sh
Last active August 10, 2022 04:42
Mac OS X - Install Git Completion
URL="https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash"
PROFILE="$HOME/.profile"
echo "Downloading git-completion..."
if ! curl "$URL" --silent --output "$HOME/.git-completion.bash"; then
echo "ERROR: Couldn't download completion script. Make sure you have a working internet connection." && exit 1
fi