Skip to content

Instantly share code, notes, and snippets.

# Function to check if the script is running as Administrator
function Test-IsAdmin {
$currentUser = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
return $currentUser.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
}
# If not running as Administrator, restart the script with elevated privileges
if (-not (Test-IsAdmin)) {
Write-Output "Restarting script with elevated privileges..."
Start-Process powershell -ArgumentList "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs
@a4lg
a4lg / invariant_macro.rs
Created March 9, 2023 05:30
`invariant!` macro to declare an invariant
// If `unsafe` and `nightly` are enabled, enable unstable `core_intrinsics` feature
// with #![feature(core_intrinsics)] (Nightly only).
macro_rules! invariant {
($expr: expr) => {
cfg_if::cfg_if! {
if #[cfg(all(feature = "unsafe", feature = "nightly"))] {
core::intrinsics::assume($expr);
}
else if #[cfg(feature = "unsafe")] {
@darka
darka / png_out.py
Last active January 3, 2024 05:44
Generating a PNG in Python
import struct
import zlib
from typing import BinaryIO, List, Tuple
Pixel = Tuple[int, int, int]
Image = List[List[Pixel]]
BLACK_PIXEL: Pixel = (0, 0, 0)
WHITE_PIXEL: Pixel = (255, 255, 255)
@rust-play
rust-play / playground.rs
Created January 10, 2020 12:11
Code shared from the Rust Playground
// EloRating Calculator
// http://www.kurims.kyoto-u.ac.jp/~ooura/gamerf.html
pub fn gammaln_6(x: f64) -> f64 {
// 0 < x < infinity
// err = 2.09144255e-18
(x - 0.5) * (x + 6.0975075753906857609437558e+0).ln() - x
+ ((((((1.1240582657165407383437999e-2 / (x + 5.0003589884831925541613237e+0)
+ 5.0219722703392090725884168e-1)
/ (x + 3.9999966300007508932097016e+0)
@lvisdd
lvisdd / GoogleColabShogi.md
Last active August 20, 2022 14:58
DeepLearningShogi for Google Colab

GCT (Gaming pC / Google Colab / Cloud Training) 将棋

基本方針

  • 将棋AIで学ぶディープラーニング (山岡忠夫著) の手法を参考にする。 [1]
  • 個人で利用するのが現実的な学習リソースとコストで、ディープラーニングモデルを強くするため、Google Colab を積極的に活用する。
  • 将棋以外にも活用するため、 Python を利用する。
  • 高速化が見込まれる場合は、 Cython を利用する。
  • 対局時の高速化のために、dlshogi (Pytorch/TensorRT) を利用する。
  • 学習時の高速化のために、dlshogi (Pytorch) を利用する。
  • Google の AlphaZero の手法をリスペクトするため、Google Colab (GCP) の TPU を利用する。
anonymous
anonymous / hello.perl
Created August 5, 2015 07:58
http://paiza.jp/guide/samplecode の邪悪化
map print,
map "hello = $_->[0] , world = $_->[1]\n",
map [split ','],
map {s/[\x0d\x0a]//g; $_}
map scalar <STDIN>,
1..<STDIN>;
@t-nissie
t-nissie / Gudermannian-erf-tanh-Langevin.md
Last active March 12, 2021 08:08
ゼロ近傍で傾きを持ち、±∞で±1か±π/2になる関数

ゼロ近傍で傾きを持ち、±∞で±1か±π/2になる関数

ゼロ近傍で傾きを持ち、x→±∞ で f(x) → ±1 or ±π/2 になる関数、ようするに図1の5つの関数を集めてみた。

figure1

図1: グーデルマン関数 gd(x)、誤差関数 erf(x)、tanh(x)、ランジュバン関数 L(x)

グーデルマン関数