Skip to content

Instantly share code, notes, and snippets.

View sinkingsugar's full-sized avatar

Giovanni Petrantoni sinkingsugar

View GitHub Profile
@sinkingsugar
sinkingsugar / http-server.shs
Created July 19, 2024 09:56
Shards simple http server
@mesh(root)
@define(headers {
"Cross-Origin-Opener-Policy": "same-origin"
"Cross-Origin-Embedder-Policy": "require-corp"
})
@wire(handler {
Http.Read = request
Take("target") >= target
@sinkingsugar
sinkingsugar / ModifiedMarchingCubes.js
Created February 9, 2022 08:07 — forked from dwilliamson/ModifiedMarchingCubes.js
Transvoxel's Modified Marching Cubes Lookup Tables
//
// Lookup Tables for Transvoxel's Modified Marching Cubes
//
// Unlike the original paper (Marching Cubes: A High Resolution 3D Surface Construction Algorithm), these tables guarantee
// a closed mesh "whose connected components are continuous and free of holes."
//
// Rotations are prioritised over inversions so that 3 of the 6 cases containing ambiguous faces are never added. 3 extra
// cases are added as a post-process, overriding inverses through custom-build rotations to eliminate the rest.
//
// Uses the exact same co-ordinate system as https://gist.github.com/dwilliamson/c041e3454a713e58baf6e4f8e5fffecd
@sinkingsugar
sinkingsugar / WireGuard-site-to-site.md
Created January 6, 2021 10:27
Accessing a subnet that is behind a WireGuard client using a site-to-site setup

WireGuard Site-to-Site

Accessing a subnet that is behind a WireGuard client using a site-to-site setup

Problem Summary

We want to access a local subnet remotely, but it is behind a NAT firewall and we can't setup port forwarding. Outgoing connections work, but all incoming connections get DROPPED by the ISP's routing policy.

Solution Summary

{"lvl":"TRC","ts":"2020-07-31 14:38:42+09:00","msg":"globalRaiseHook","topics":"networking","tid":30355,"file":"eth2_network.nim:250","msg":"Future operation cancelled!","name":"CancelledError","trace":"/nbc/nim-beacon-chain/vendor/nim-testutils/testutils/moduletests.nim(21) beacon_node\n/nbc/nim-beacon-chain/beacon_chain/beacon_node.nim(1196) main\n/nbc/nim-beacon-chain/beacon_chain/beacon_node.nim(893) start\n/nbc/nim-beacon-chain/beacon_chain/beacon_node.nim(843) run\n/nbc/nim-beacon-chain/vendor/nim-chronos/chronos/asyncloop.nim(278) poll\n/nbc/nim-beacon-chain/vendor/nim-chronos/chronos/asyncmacro2.nim(290) readOnce\n"}
{"lvl":"TRC","ts":"2020-07-31 14:38:42+09:00","msg":"globalRaiseHook","topics":"networking","tid":30355,"file":"eth2_network.nim:250","msg":"Future operation cancelled!","name":"CancelledError","trace":"/nbc/nim-beacon-chain/vendor/nim-testutils/testutils/moduletests.nim(21) beacon_node\n/nbc/nim-beacon-chain/beacon_chain/beacon_node.nim(1196) main\n/nbc/nim-beacon-chain/beacon_chain/beac
import results
import chronos # requires chornos
type
AsyncResult*[T] = Future[Result[T, string]]
AsyncCall*[T1, T2] = proc(prev: AsyncResult[T1]): AsyncResult[T2]
# the whole point is not loose errors around and to be able to declare a chain of async ops clearly
# we do strict error checking and propagate them in the result
# and so we need just a single await in user code
use futures::future::Future;
use libp2p_core::identity;
use libp2p_core::transport::Transport;
use libp2p_core::upgrade::{self};
use libp2p_core::Multiaddr;
use libp2p_noise::{Keypair, NoiseConfig, X25519};
use libp2p_tcp::TcpConfig;
use tokio::{self, io};
fn main() {
@sinkingsugar
sinkingsugar / random.h
Created January 12, 2020 02:31 — forked from Leandros/random.h
C++ Pseudo Random Number Generators
/* Copyright (c) 2018 Arvid Gerstmann. */
/* This code is licensed under MIT license. */
#ifndef AG_RANDOM_H
#define AG_RANDOM_H
class splitmix
{
public:
using result_type = uint32_t;
static constexpr result_type (min)() { return 0; }
@sinkingsugar
sinkingsugar / Swizzles.h
Created January 12, 2020 02:31 — forked from NocturnDragon/Swizzles.h
Swizzles in Clang, GCC, and Visual c++
#include <stdio.h>
// #define CLANG_EXTENSION
// Clang compile with -O3
#define VS_EXTENSION
// https://godbolt.org/z/sVWrF4
// Clang compile with -O3 -fms-compatibility
// VS2017 compile with /O3
@sinkingsugar
sinkingsugar / halide.nim
Created July 2, 2019 05:52
Nim and Haldie
import nimline
import os
static:
let
halideDist = getenv("HALIDE_DIST")
assert halideDist != "" , "HALIDE_DIST environment variables not set!"
when defined windows:
@sinkingsugar
sinkingsugar / Dockerfile
Created February 20, 2019 08:51
Pytorch build
FROM nvidia/cuda:10.0-cudnn7-devel-ubuntu18.04
RUN apt-get update && apt-get install -y build-essential git cmake python3-pip libmpfr-dev libgmp-dev wget curl
RUN pip3 install pyyaml
RUN pip3 install typing
RUN cd && \
wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh