Skip to content

Instantly share code, notes, and snippets.

View thynson's full-sized avatar

Xingcan LAN thynson

  • Li Auto
  • Beijing, China
View GitHub Profile
@thynson
thynson / branchless_comparator.cpp
Last active April 17, 2023 00:45
A general branchless comparison implementation
#include <functional>
#include <iostream>
#include <utility>
template<typename Comparator, typename T>
typename std::enable_if<
std::is_same<
bool,
decltype(std::declval<const Comparator &>()(std::declval<const T &>(), std::declval<const T &>()))
>::value,
@thynson
thynson / ziggurat-gauss-distribution.ts
Last active March 23, 2023 05:24
The Javascript(Typescript) port of Ziggurat method of generating a Gauss distributed variable.
interface RandomEngine {
randomUint32(): number;
}
const PARAM_R = 3.44428647676;
/* tabulated values for the heigt of the Ziggurat levels */
const ytab = [
1, 0.963598623011, 0.936280813353, 0.913041104253, 0.892278506696, 0.873239356919, 0.855496407634, 0.838778928349,
@thynson
thynson / wyhash_final4.rs
Last active January 29, 2023 07:09
A rust implementation of wyhash_final4
///
/// This is free and unencumbered software released into the public domain.
///
/// Anyone is free to copy, modify, publish, use, compile, sell, or
/// distribute this software, either in source code form or as a compiled
/// binary, for any purpose, commercial or non-commercial, and by any
/// means.
///
/// In jurisdictions that recognize copyright laws, the author or authors
/// of this software dedicate any and all copyright interest in the
@thynson
thynson / index.spec.ts
Last active September 23, 2021 15:48
Jest custom resolver not work in globalSetup
import {MyClass} from './test-file';
test('stub', async () => {
await new MyClass().function();
});
@thynson
thynson / kubernetes-cli.rb
Last active April 15, 2020 09:43
kubernetes-cli@1.17.4 for macos catalina
class KubernetesCli < Formula
desc "Kubernetes command-line interface"
homepage "https://kubernetes.io/"
url "https://github.com/kubernetes/kubernetes.git",
:tag => "v1.17.4",
:revision => "8d8aa39598534325ad77120c120a22b3a990b5ea"
head "https://github.com/kubernetes/kubernetes.git"
bottle do
cellar :any_skip_relocation
@thynson
thynson / typeorm-camelcase-naming-strategy.ts
Last active November 11, 2019 02:28
TypeORM CamelCase Naming Strategy
import {DefaultNamingStrategy, Table, VersionColumn, CreateDateColumn, UpdateDateColumn} from 'typeorm';
import {camelCase} from 'typeorm/util/StringUtils';
export class NamingStrategy extends DefaultNamingStrategy {
name: string;
columnName(propertyName: string, customName: string | undefined, embeddedPrefixes: string[]): string {
let name = [customName || propertyName];
if (embeddedPrefixes.length > 0) {
name = embeddedPrefixes.concat(name);
@thynson
thynson / .zshrc
Last active October 10, 2017 10:52
zshrc based on ohmyzsh
# Path to your oh-my-zsh installation.
export ZSH=/Users/lanxingcan/.oh-my-zsh
# Set name of the theme to load. Optionally, if you set this to "random"
# it'll load a random theme each time that oh-my-zsh is loaded.
# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
ZSH_THEME="candy"
# Uncomment the following line to use case-sensitive completion.
@thynson
thynson / Let's-encrypt-with-systemd.md
Last active April 18, 2017 03:10
Let's Encrypt Certificate Renew Script Set

This script set help your renew your certificate from Let's Encrypt.

How to use

Suppose you have a domain example.com

  • Generate a private key

    mkdir -p /etc/letsencrypt
    

openssl genrsa 2048 > /etc/letsencrypt/example.com.key

@thynson
thynson / C++17-Value-Category-System.md
Last active January 22, 2022 16:12
C++ 17 Value Category System

C++ 17 Value Category System

-----------------------------
|   glvalue       |         |
-----------------------------
| lvalue | xvalue | prvalue |
-----------------------------
|        |     rvalue       |
-----------------------------
@thynson
thynson / mersenne_twister_engine.hpp
Last active July 22, 2016 08:07
Mersenne Twister Randome Number Genrator
/*
* Copyright (C) 2016 LAN Xingcan
* All right reserved
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF