Skip to content

Instantly share code, notes, and snippets.

View syoyo's full-sized avatar
💗
ray tracing

Syoyo Fujita syoyo

💗
ray tracing
View GitHub Profile
#include <iostream>
#include <string>
static int _ReadUTF8(char const *&cp, std::string *errMsg)
{
// Return a byte with the high `n` bits set, rest clear.
auto highBits = [](int n) {
return static_cast<unsigned char>(((1 << n) - 1) << (8 - n));
};
@syoyo
syoyo / traffic-control.sh
Created July 29, 2022 11:59 — forked from ole1986/traffic-control.sh
Traffic control script for incoming and outgoing packages using TC (on a specific ip address)
#!/bin/bash
VERSION="1.0.2"
# Interface connect to out lan
INTERFACE="eth0"
# Interface virtual for incomming traffic
VIRTUAL="ifb0"
# set the direction (1 = outgoing only, 2 = incoming only 3 = both)
DIRECTION=3
# Speed
@syoyo
syoyo / gist:2e80c2027278e7cde2107bdb2747d472
Created September 25, 2020 10:07
OptiX 7.1 illegal memory access issue
// Issue
// * Allocate and provice insufficient data size(e.g. vertex data) fo GAS input.
// * Call `optixAccelBuild` with "correct" buffer size(e.g. `buildInput.triangleArray.numVertices`)
// * Build GAS against invalid data but no error report at this time
// * Some memory object causes 'illegal memory access' error when freeing(also happens in CUDA driver API)
// How to reprocible
//
// OptiX 7.1 optixHair SDK sample
// Uncomment following in Util.h
@syoyo
syoyo / gist:8e980a1c04f4253894d32da25d68bad4
Created July 5, 2020 12:30
_mm_min_ps implementation in ARM NEON
#include <arm_neon.h>
#include <cstdio>
#include <limits>
#include <cassert>
#include <cmath>
#include <cstdint>
bool check_snan(float f)
{
bool is_nan = std::isnan(f);
@syoyo
syoyo / gist:62c0ec0183e91bff668624eba91f76f4
Created July 5, 2020 12:30
_mm_min_ps implementation in ARM NEON
#include <arm_neon.h>
#include <cstdio>
#include <limits>
#include <cassert>
#include <cmath>
#include <cstdint>
bool check_snan(float f)
{
bool is_nan = std::isnan(f);
@syoyo
syoyo / gist:831c4b1926aa88c0da9221211723da2d
Created December 17, 2018 13:12
C++ implementaion of "A simple method to construct isotropic quasirandom blue noise point sequences"
//
// C++ implementaion of "A simple method to construct isotropic quasirandom blue
// noise point sequences"
//
// http://extremelearning.com.au/a-simple-method-to-construct-isotropic-quasirandom-blue-noise-point-sequences/
//
// Assume 0 <= x
static double myfmod(double x) { return x - std::floor(x); }
@syoyo
syoyo / gist:24d0bf30dd2a9b5b2b69
Last active March 26, 2016 08:26
Intel C compiler bug or ill-defined C++?
// Writing (&x)[i] in operator[] is safe/correct C++ code or not?
// The following is the reduced code fragment(Thus not work by just copy&paste) which Intel C++ compier(ver 13 and 15) miscompiles(Release build only) the code for the access to real3 object through operator[] inside OpenMP loop.
// clang and gcc are OK to compile&run
typedef float real;
struct real3 {
real3() {}
real3(real xx, real yy, real zz) {
x = xx;
@syoyo
syoyo / gist:9acc46554723db14d3a5
Created December 21, 2015 11:44
clang/LLVM for Android ARM64 corss compile script
#!/bin/bash
rm -rf CMake*
export NDK=/home/syoyo/local/android-ndk-r10e
export SYSROOT=$NDK/platforms/android-21/arch-arm64
export CC="$NDK/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-gcc"
export CXX="$NDK/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-g++"
@syoyo
syoyo / gist:778d2294fd5534e0f923
Created December 15, 2015 10:55
ninja generator example
#!/usr/bin/env python
import ninja_syntax
import glob
import os
cxx_files = [
"src/OptionParser.cpp"
, "src/easywsclient.cpp"
, "src/json_to_eson.cc"
@syoyo
syoyo / gist:527bd92bd08759b3a165
Created November 17, 2015 06:13
draw image using DataURI
socket.on("render_data", function(data) {
console.log("render_data");
var canvas = document.getElementById('mycanvas');
var ctx = canvas.getContext('2d');
var canvasWidth = canvas.width;
var canvasHeight = canvas.height;
var img = new Image();
img.onload = function() { ctx.drawImage(img, 0, 0, canvasWidth, canvasHeight); };