Skip to content

Instantly share code, notes, and snippets.

View NocturnDragon's full-sized avatar

X NocturnDragon

View GitHub Profile
@compnerd
compnerd / reverse-range.cc
Last active December 18, 2015 00:09
An implementation of a reverse iteration adaptor for range based for-loops in C++11.
/* vim: set et ft=cpp.doxygen sts=2 sw=2 ts=8 : */
/**
* Copyright © 2013 Saleem Abdulrasool <compnerd@compnerd.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
@rygorous
rygorous / dtoa.c
Last active November 23, 2019 07:23
RAD dtoa
// The original author of this software is David M. Gay.
// RAD modifications from here down to the copyright notice
// Actual RAD version of this includes rrCore.h which does
// (among other things) endianness detection - you'll have to
// do that yourself.
#include "dtoa.h"
// Again, we normally use our own assert macros here.
@winzig
winzig / Liberal Regex Pattern for URLs
Last active July 30, 2024 22:09 — forked from gruber/Liberal Regex Pattern for Web URLs
Updated @gruber's regex with a modified version that looks for 2-13 letters rather than trying to look for specific TLDs, and many other improvements. (UPDATE 2018-07-30: Support for IPv4 addresses, bare hostnames, naked domains, xn-- internationalized domains, and more... see comments for BREAKING CHANGE.)
# Single-line version:
(?i)\b(https?:\/{1,3})?((?:(?:[\w.\-]+\.(?:[a-z]{2,13})|(?<=http:\/\/|https:\/\/)[\w.\-]+)\/)(?:[^\s()<>{}\[\]]+|\([^\s()]*?\([^\s()]+\)[^\s()]*?\)|\([^\s]+?\))+(?:\([^\s()]*?\([^\s()]+\)[^\s()]*?\)|\([^\s]+?\)|[^\s`!()\[\]{};:'\".,<>?«»“”‘’])|(?:(?<!@)(?:\w+(?:[.\-]+\w+)*\.(?:[a-z]{2,13})|(?:(?:[0-9](?!\d)|[1-9][0-9](?!\d)|1[0-9]{2}(?!\d)|2[0-4][0-9](?!\d)|25[0-5](?!\d))[.]?){4})\b\/?(?!@)(?:[^\s()<>{}\[\]]+|\([^\s()]*?\([^\s()]+\)[^\s()]*?\)|\([^\s]+?\))*(?:\([^\s()]*?\([^\s()]+\)[^\s()]*?\)|\([^\s]+?\)|[^\s`!()\[\]{};:'\".,<>?«»“”‘’])?))
# Commented multi-line version:
(?xi)
\b
(https?:\/{1,3})? # Capture $1: (optional) URL scheme, colon, and slashes
( # Capture $2: Entire matched URL (other than optional protocol://)
@ArtemGr
ArtemGr / BsonJson.cpp
Last active December 21, 2023 08:52
BSON-JSON with C++ and Rapidjson
#include <mongo/bson/bson.h>
using mongo::BSONObj; using mongo::BSONObjBuilder;
using mongo::BSONArray; using mongo::BSONArrayBuilder;
using mongo::BSONElement;
#include <rapidjson/document.h>
#include <rapidjson/reader.h>
#include <rapidjson/writer.h>
#include <rapidjson/stringbuffer.h>
@castano
castano / hemicube.cpp
Created June 20, 2014 09:46
Hemicube Integrator
#include "hemicube.h"
#define PACK_HEMICUBES 1
static void get_hemicube_face_normal(int index, Vector3 *forward, Vector3 *left, Vector3 *up) {
// Unwrapped hemicube with positive-Z in the middle.
switch (index) {
case 0: *forward = Vector3(+1, 0, 0); *left = Vector3( 0, 1, 0); break;
@dwilliamson
dwilliamson / Triangle.cpp
Created August 22, 2014 13:26
Dumb but accurate triangle rasteriser with top-left fill
void RasteriseTriangle3(char* buffer, int width, int height, float2 v0, float2 v1, float2 v2)
{
// Sort vertices along the y-axis, lowest first
if (v1.y < v0.y)
std::swap(v0, v1);
if (v2.y < v1.y)
std::swap(v1, v2);
if (v1.y < v0.y)
std::swap(v0, v1);
@dwilliamson
dwilliamson / GenericExpansion.c
Last active August 29, 2015 14:05
Generics stored and parsed in C-style comments, generating code directly after them whenever the comments change.
//
// Pre-processor scans your C/header file for the '/*$gen:' signature
// It consumes everything inside the C-style comment and generates a unique hash
// This hash is used to determine if the contents of the comment have changed since it last looked
// The hash is stored after the '/*$gen:' signature
//
/*$gen:0x1AF673C3
// This is your generic implementation with (T) the generic type
@seanparsons
seanparsons / gist:c8a44e5fa9d70193f378
Created October 23, 2014 23:50
Monads: The Why, the What For, and especially the It's Like X, But!
-- To run this file you just need the ghc application from the Haskell Platform bundle
-- With that on a command line run the following (assuming the code is in Monads.hs):
-- ghc Monads.hs && ./Monads
-- Imports needed for later:
import System.IO
-- So pretty much every language has this concept:
-- doThingA();
-- doThingB();
-- If that wasn't hugely clear, it was the concept of calling one bit of code
@rygorous
rygorous / gist:58358f18ce59bc79f360
Created October 30, 2014 20:11
Weak handles for audio
// ---- INTERFACE
// Sound handle. This is a weak reference; they automatically go invalid as voices
// stop playing and get reused. You don't need to worry about leaks.
struct SoundHandle
{
uint32_t opaque; // Mixer decides what this means (but 0=null)
explicit SoundHandle(uint32_t handle=0) : opaque(handle) {}
@dwilliamson
dwilliamson / FileWatcher.cpp
Created January 22, 2015 21:39
Single-threaded file watcher with overlapped I/O and filtering of multiple notifications
class FileWatcher
{
public:
FileWatcher(const Path& path)
: m_Path(path)
, m_DirHandle(INVALID_HANDLE_VALUE)
, m_BufferSize(CORE_KB(100))
, m_Buffer(nullptr)
, m_ChangedFiles(1024)
{