Skip to content

Instantly share code, notes, and snippets.

View Astro36's full-sized avatar

Seungjae Park Astro36

View GitHub Profile
const date = new Date();
const seed = date.getFullYear() * 10000 + (date.getMonth() + 1) * 100 + date.getDate();
let nums = [...new Array(50).keys()]; // [0, 1, 2, 3, ..., 29];
const rand = (() => {
let next = seed;
return () => (next = (1103515245 * next + 12345) % 10000000) % 3;
})();
@Astro36
Astro36 / iterable.h
Last active March 29, 2020 14:17
Check if arbitrary type can use for-each loop by using C++ SFINAE
#include <iterator>
#include <type_traits>
template<typename T, typename = void>
struct is_iterable : std::false_type {};
template<typename T>
struct is_iterable<T, std::void_t<decltype(*std::begin(std::declval<T&>()) != *std::end(std::declval<T&>())),
decltype(++std::declval<decltype(std::begin(std::declval<T&>()))&>())>> : std::true_type {};
template<typename T, typename Index = std::size_t, typename = void>
struct has_subscript_operator : std::false_type {};
template<typename T, typename Index>
struct has_subscript_operator<T, Index, std::void_t<decltype(std::declval<T>()[std::declval<Index>()])>> : std::true_type {};
template<typename T, typename Index = int>
using has_subscript_operator_v = typename has_subscript_operator<T, Index>::value;
template<typename T>
#include <iostream>
template<unsigned int N>
constexpr unsigned int factorial_v = N * factorial_v<N - 1>;
template<>
constexpr unsigned int factorial_v<1> = 1;
template<unsigned int N, unsigned int K>
constexpr unsigned int binomial_v = factorial_v<N> / (factorial_v<K> * factorial_v<N - K>);
@Astro36
Astro36 / .vimrc
Last active May 1, 2020 13:38
My Vim Config
colorscheme delek
set nu
set mouse=a
set ruler
set shiftwidth=4
set tabstop=4
set softtabstop=4
@Astro36
Astro36 / renew-certbot.sh
Created May 30, 2020 07:26
Renew Let's Encrypt Certificate
sudo nginx -s stop
sudo certbot renew
nginx
@Astro36
Astro36 / .clang-format
Last active August 26, 2020 07:25
My C++ Clang-Format Style
# https://gist.github.com/Astro36/211443b279e964af9b2ed05ddec0b1ee
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
# AlignConsecutiveMacros: false
AlignEscapedNewlines: DontAlign
AlignOperands: true
AlignTrailingComments: false
# AllowAllArgumentsOnNextLine: false
@Astro36
Astro36 / compose.gpu.yml
Last active July 31, 2024 06:16
Windows ML Dev Env /w Docker
services:
psj:
image: nvcr.io/nvidia/pytorch:24.06-py3
deploy:
resources:
reservations:
devices:
- capabilities: [gpu]
driver: nvidia
shm_size: 10gb