Skip to content

Instantly share code, notes, and snippets.

View saxbophone's full-sized avatar
🏳️‍⚧️

saxbophone

🏳️‍⚧️
View GitHub Profile
@saxbophone
saxbophone / float_test.c++
Last active May 4, 2024 17:39
Generate and verify safe ranges of integers for to-and-from float-int conversion
/*
* Written by Joshua Saxby ("saxbophone") 2023-03-14 -- saxbophone.com
*
* This demonstration program for how to derive max/min "safe" integers for
* conversion to and from floating point is hereby released into the public domain.
*/
#include <limits> // numeric_limits
#include <type_traits> // make_signed
@saxbophone
saxbophone / gitignore.sh
Created November 17, 2022 16:26
Generate .gitignore files for given languages straight from the comfort of the UNIX shell
# Created by Joshua Saxby 2022
# This BASH shell script function is placed into the Public Domain
# There are no restrictions on its use but it is provided with ABSOLUTELY no liability, warranty, etc, etc...
# !!don't sue me for using it at your own risk...!!
# uses the new version of the former gitignore.io API to generate gitignore files for given languages
# usage: $ gitignore <lang 1> <lang 2> ... <lang n>
#
# NOTE: overwrites local .gitignore file in-place
@saxbophone
saxbophone / floatrep.cpp
Last active July 27, 2023 12:31
Using memcpy to easily and portably get the underlying representation of an IEEE-754 float
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <limits>
std::uint32_t floatrep(float x) {
std::uint32_t n;
std::memcpy(&n, &x, sizeof(x));
return n;
@bindreams
bindreams / svstream.hpp
Last active March 30, 2024 12:08
string_view compatible std::istringstream.
/**
* MIT No Attribution
*
* Copyright 2020-2024 Anna Zhukova
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
* software and associated documentation files (the "Software"), to deal in the Software
* without restriction, including without limitation the rights to use, copy, modify,
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so.
@WesThorburn
WesThorburn / 1.Instructions.md
Last active March 14, 2024 22:11
Linux: Compile C++ to WebAssembly and JavaScript using Emscripten and CMake

Linux: Compile C++ to WebAssembly and JavaScript using Emscripten and CMake

Download and Install Emscripten

  • My preferred installation location is /home/user
  • Get the latest sdk: git clone https://github.com/emscripten-core/emsdk.git
  • Enter the cloned directory: cd emsdk
  • Checkout main: git checkout main
  • Install the lastest sdk tools: ./emsdk install latest
  • Activate the latest sdk tools: ./emsdk activate latest
  • Activate path variables: source ./emsdk_env.sh
@rikka0w0
rikka0w0 / VirtualBox_Linux_Headless_Run_Windows10.md
Last active February 7, 2024 10:52
[VirtualBox] Run Windows10 Headlessly on Linux

https://redplus.me/post/set-up-headless-windows-10-virtual-machine-on-remote-linux-server/ https://www.ostechnix.com/install-oracle-virtualbox-ubuntu-16-04-headless-server/ https://www.howtoforge.com/tutorial/running-virtual-machines-with-virtualbox-5.1-on-a-headless-ubuntu-16.04-lts-server/

Installation

$ sudo nano /etc/apt/sources.list
      deb http://download.virtualbox.org/virtualbox/debian stretch contrib
$ wget -q https://www.virtualbox.org/download/oracle_vbox_2016.asc -O- | sudo apt-key add -
$ sudo apt-get update
@tylerneylon
tylerneylon / rwlock.py
Last active May 2, 2024 12:46
A simple read-write lock implementation in Python.
# -*- coding: utf-8 -*-
""" rwlock.py
A class to implement read-write locks on top of the standard threading
library.
This is implemented with two mutexes (threading.Lock instances) as per this
wikipedia pseudocode:
https://en.wikipedia.org/wiki/Readers%E2%80%93writer_lock#Using_two_mutexes
@mbinna
mbinna / effective_modern_cmake.md
Last active May 31, 2024 16:02
Effective Modern CMake

Effective Modern CMake

Getting Started

For a brief user-level introduction to CMake, watch C++ Weekly, Episode 78, Intro to CMake by Jason Turner. LLVM’s CMake Primer provides a good high-level introduction to the CMake syntax. Go read it now.

After that, watch Mathieu Ropert’s CppCon 2017 talk Using Modern CMake Patterns to Enforce a Good Modular Design (slides). It provides a thorough explanation of what modern CMake is and why it is so much better than “old school” CMake. The modular design ideas in this talk are based on the book [Large-Scale C++ Software Design](https://www.amazon.de/Large-Scale-Soft

@SunveerSingh
SunveerSingh / countries.json
Created November 30, 2017 13:01 — forked from keeguon/countries.json
A list of countries in JSON
[
{name: 'Afghanistan', code: 'AF'},
{name: 'Åland Islands', code: 'AX'},
{name: 'Albania', code: 'AL'},
{name: 'Algeria', code: 'DZ'},
{name: 'American Samoa', code: 'AS'},
{name: 'AndorrA', code: 'AD'},
{name: 'Angola', code: 'AO'},
{name: 'Anguilla', code: 'AI'},
{name: 'Antarctica', code: 'AQ'},
0xe3cdde8460670662d487f18228d252bc37c4353b