Skip to content

Instantly share code, notes, and snippets.

View blockspacer's full-sized avatar
:octocat:

Devspace blockspacer

:octocat:
  • Google
  • USA
View GitHub Profile
@blockspacer
blockspacer / sanitizers_llvm.bash
Last active May 21, 2021 13:26
Build llvm with sanitizers: First, build sanitized cxx cxxabi compiler-rt with LLVM_USE_SANITIZER. Next, build compiler-rt without LLVM_USE_SANITIZER but with COMPILER_RT_BUILD_SANITIZERS="ON"
export CC=clang
export CXX=clang++
rm CMakeCache.txt ; cmake ../llvm -DCMAKE_BUILD_TYPE="Release" -DBUILD_SHARED_LIBS="ON" -DCONAN_CMAKE_POSITION_INDEPENDENT_CODE="ON" -DCMAKE_VERBOSE_MAKEFILE="ON" -DLLVM_ENABLE_PROJECTS="compiler-rt;libcxx;libcxxabi" -DLLVM_PARALLEL_COMPILE_JOBS="5" -DLLVM_COMPILER_JOBS="5" -DLLVM_PARALLEL_LINK_JOBS="1" -DLLVM_USE_SANITIZER="Address;Undefined" -DLLVM_ENABLE_LIBCXX="ON" -DLLVM_TOOL_CLANG_TOOLS_EXTRA_BUILD="OFF" -DLLVM_TOOL_OPENMP_BUILD="OFF" -DCLANG_ENABLE_ARCMT="OFF" -DCLANG_ENABLE_STATIC_ANALYZER="OFF" -DCLANG_ENABLE_FORMAT="OFF" -DCLANG_TOOL_CLANG_FORMAT_BUILD="OFF" -DCLANG_TOOL_CLANG_FUZZER_BUILD="OFF" -DLLVM_BUILD_INSTRUMENTED="OFF" -DLLVM_BUILD_LLVM_DYLIB="OFF" -DLLVM_LINK_LLVM_DYLIB="OFF" -DLLVM_ENABLE_LTO="OFF" -DLLVM_ENABLE_ZLIB="ON" -DLLVM_ENABLE_FFI="OFF" -DLLVM_BUILD_TOOLS="OFF" -DLLVM_INCLUDE_TOOLS="ON" -DLLVM_USE_OPROFILE="OFF" -DCOMPILER_RT_BUILD_SANITIZERS="ON" -DCOMPILER_RT_BUILD_BUILTINS="OFF" -DCOMPILER_RT_BUILD_XRAY="ON" -DCOMPILER_RT_BUILD_XRAY_NO_PRE
@blockspacer
blockspacer / Google_Colaboratory_backup.py
Created April 25, 2021 15:44 — forked from alexlib/Google_Colaboratory_backup.py
Simple Google Drive backup script with automatic authentication for Google Colaboratory (Python 3)
# Simple Google Drive backup script with automatic authentication
# for Google Colaboratory (Python 3)
# Instructions:
# 1. Run this cell and authenticate via the link and text box.
# 2. Copy the JSON output below this cell into the `mycreds_file_contents`
# variable. Authentication will occur automatically from now on.
# 3. Create a new folder in Google Drive and copy the ID of this folder
# from the URL bar to the `folder_id` variable.
# 4. Specify the directory to be backed up in `dir_to_backup`.
#include "utf.hpp"
#include <iostream>
#include <string>
int main()
{
// A UTF-8 literal
std::string utf8 = u8"z\u00df\u6c34\U0001d10b"; // or u8"zß水𝄋"
// or "\x7a\xc3\x9f\xe6\xb0\xb4\xf0\x9d\x84\x8b";

Header file fixed_point.h

#define SG14_FIXED_POINT_H 1

#include "type_traits.h"

#include "bits/common.h"

#define SG14_FIXED_POINT_EXCEPTIONS_ENABLED 
@blockspacer
blockspacer / float128.go
Created February 5, 2021 08:40 — forked from grd/float128.go
Simplified float128, more in style with the math package
// This package implements 128-bit ("double double") floating point using
// a pair of 64-bit hardware floating point values and standard hardware
// floating point operations. It is based directly on libqd by Yozo Hida,
// Xiaoye S. Li, David H. Bailey, Yves Renard and E. Jason Riedy. Source:
// http://crd.lbl.gov/~dhbailey/mpdist/qd-2.3.13.tar.gz
package float128
import (
"errors"
"fmt"

Barrier

Barrier.h

/*
  Barrier.h
 */

#include <mutex>
#include <condition_variable>
@blockspacer
blockspacer / gist:49680b12351ac2c52ebcf13a84d0ae2c
Last active December 23, 2020 08:47
C++ example: operator overloading with template (strong numeric type)
#include <iostream>
#include <vector>
#include <concepts>
#include <iostream>
#include <type_traits>
template<typename Tag, typename T>
class StrongNum;
template<typename Tag, typename T>
@blockspacer
blockspacer / traits.cpp
Created December 23, 2020 07:20 — forked from JPGygax68/traits.cpp
How to implement custom #traits (C++11)
#include <type_traits>
#include <iostream>
using std::enable_if;
using std::is_same;
using std::declval;
using std::integral_constant;
template <typename T>
using Invoke = typename T::type;
@blockspacer
blockspacer / sfinae_tostring_ex.cpp
Created December 23, 2020 06:30 — forked from fenbf/sfinae_tostring_ex.cpp
C++ SFINAE example: how to detect if a class contains ToString method
// SFINAE, enable_if example
// based on http://stackoverflow.com/questions/257288/is-it-possible-to-write-a-c-template-to-check-for-a-functions-existence
#include <iostream>
#include <type_traits>
class ClassWithToString
{
public:
@blockspacer
blockspacer / Event_Loop.md
Created September 25, 2020 10:43 — forked from kassane/Event_Loop.md
Explain Event Loop

Event Loop

In computer science, the event loop, message dispatcher, message loop, message pump, or run loop is a programming construct that waits for and dispatches events or messages in a program.

It works by making a request to some internal or external "event provider" (that generally blocks the request until an event has arrived), and then it calls the relevant event handler ("dispatches the event").

The event-loop may be used in conjunction with a reactor, if the event provider follows the file interface, which can be selected or 'polled' (the Unix system call, not actual polling).

The event loop almost always operates asynchronously with the message originator.