Skip to content

Instantly share code, notes, and snippets.

John Calsbeek Nexuapex

Block or report user

Report or block Nexuapex

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
Nexuapex / inlined.h
Last active Aug 29, 2015
I would get behind this if I could just static_assert(size <= Size) in the placement operator new. Close but no cigar.
View inlined.h
#include <string.h>
template <typename T, size_t Size>
class inlined
Nexuapex /
Last active Aug 29, 2015
An attempt to reinvent `std::function' that ended up being about things I don't like about C++.
// Because it was possible to implement std::move and std::forward<T> as library
// functions, so that's what happened. Now this header is everywhere. This is
// 2,800 lines of kitchen sink for me.
#include <utility>
// C++ has half-decent pattern matching, but only on types. If only some of this
// energy could be thrown at language constructs like `switch'.
// Oh, right, and this relies on partial specialization, which only works on
// classes. So you get these pointless classes that contain a single typedef.
import socket
create_socket = lambda: socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP)
target_port = 49400 # Any port in the ephemeral port range that no process on your machine is using.
port = 0
# Create and bind sockets, working our way through the ephemeral port space, until we get close to our target.
while not (target_port - 5 < port < target_port):
sock = create_socket()
sock.bind(('', 0))
Nexuapex / Microsoft C++.sublime-build
Created Nov 17, 2014
A simple Sublime Text 3 build system for Visual Studio 2013's C/C++ compiler.
View Microsoft C++.sublime-build
"shell_cmd": "\"%VS120COMNTOOLS%\\..\\..\\VC\\vcvarsall.bat\" amd64 && cl /nologo \"$file\"",
"file_regex": "^(.*?)\\(([0-9+])(?:,([0-9+]))?\\)\\s+:\\s+(.*)$",
"working_dir": "${file_path}",
"selector": "source.c, source.c++"
Nexuapex / env.cmd
Created Mar 6, 2015
A Python script that injects environment variables into the calling cmd.exe shell.
View env.cmd
@echo off
rem = """
rem This is a hybrid batch and Python script. The batch (right here) invokes
rem the Python script and treats its standard output as a list of environment
rem variables to set in the current environment.
rem The -x argument causes the Python interpreter to ignore the first line.
rem The -S argument disables the implicit 'site' package import (speed go fast).
FOR /F "tokens=1,2 delims==" %%v IN ('python -x -S "%~f0" %*') DO SET %%v=%%w
GOTO :eof
Nexuapex / 7segment.c
Created Oct 29, 2011
7-segment display in 50 lines of C99.
View 7segment.c
#include <stdio.h>
int const schematic[7][7] = {
static GLfloat const minor = 0.5257311f;
static GLfloat const major = 0.8506508f;
float const icosahedron_position[12][3] = {
{0.f, +minor, +major},
{0.f, +minor, -major},
{0.f, -minor, +major},
{0.f, -minor, -major},
{+major, 0.f, +minor},
{+major, 0.f, -minor},
Nexuapex /
Created Feb 18, 2012
Reinterpreting int ⇔ float with SSE
#include <xmmintrin.h>
inline int as_int_bitwise(float a)
return _mm_cvtsi128_si32(_mm_set_ss(a));
inline float as_float_bitwise(int a)
return _mm_cvtss_f32(_mm_cvtsi32_si128(a));
Nexuapex / dump.lua
Created Jun 17, 2012
Dumping a description of a Lua value
View dump.lua
local dump_table_threshold = 3
local dump_indent = (" "):rep(4)
local dumptable = {
["nil"] = tostring,
["number"] = tostring,
["string"] = function(value) return "\"" .. value .. "\"" end,
["boolean"] = tostring,
["table"] = function(value, depth, markers)
if markers[value] then
Nexuapex / kahan3.c
Created Aug 23, 2012
Kahan summation (3-way)
View kahan3.c
float sum(float x0, float x1, float x2)
float accum = x0 + x1;
float excess = (accum - x0) - x1;
float addend = x2 - excess;
return accum + addend;
You can’t perform that action at this time.