Skip to content

Instantly share code, notes, and snippets.

@hidetatz
hidetatz / Dockerfile
Last active November 11, 2023 09:07
Docker + Pytorch + Python3.11.6 + Poetry environment
FROM nvidia/cuda:11.8.0-cudnn8-devel-ubuntu20.04
ENV NVIDIA_VISIBLE_DEVICES=all
ENV NVIDIA_DRIVER_CAPABILITIES=all
ENV DEBIAN_FRONTEND=noninteractive
# configure locale
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
@hidetatz
hidetatz / .bashrc
Last active January 22, 2024 01:59
dotfiles
export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin
source /usr/share/bash-completion/bash_completion
@hidetatz
hidetatz / main.go
Last active May 10, 2022 01:58
Backtracking Sudoku solver in Go
package main
import "fmt"
type Board struct {
Numbers [][]int
}
func NewBoard(n [][]int) *Board {
return &Board{n}
@hidetatz
hidetatz / bit_format.go
Created March 22, 2022 00:51
Format bit stream with separator in Go
package bitformat
import (
"fmt"
)
func bitFormat8(b uint8, places ...int) string {
return insertSep(fmt.Sprintf("%08b", b), places...)
}
@hidetatz
hidetatz / brainfuck.go
Last active January 28, 2022 09:47
brainfuck interpreter
package main
import (
"bufio"
"bytes"
"fmt"
"os"
)
func main() {
@hidetatz
hidetatz / generics_aware_goimports.sh
Last active April 8, 2024 02:13
How to build generics-aware goimports as of 2021/12/07
# In this script I'll use gotip, but there might be other ways
go install golang.org/dl/gotip@latest
# golang/go HEAD will be built
gotip download
# make sure gotip is available
gotip version
git clone https://github.com/golang/tools
@hidetatz
hidetatz / realip.go
Last active October 1, 2021 13:51
X-Forwarded-For handling in a correct manner
// RealIP sets the real client IP address to r.RemoteAddr.
// You must specify trustedIPs, which are the set of trusted IP address.
// For example, the IP address of LB, web server or reverse proxy should be in the set.
// When a malcious client sets X-Forwarded-For header with fake IP address,
// you cannot know which is the correct client's one without trustedIPs.
func RealIP(next http.Handler, trustedIPs []string) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
xff := r.Header.Get("X-Forwarded-For")
if xff == "" {
next.ServeHTTP(w, r)
#!/bin/bash
git clone https://github.com/vim/vim.git
cd vim
./configure \
--enable-multibyte \
--enable-nls \
--enable-perlinterp \
--enable-rubyinterp \
@hidetatz
hidetatz / main.go
Created May 19, 2021 05:53
encoding/gob cannot handle recursive value.
package main
import (
"bytes"
"encoding/gob"
)
type Entry struct {
V interface{}
}
@hidetatz
hidetatz / hit_and_blow.go
Last active April 26, 2021 13:27
Hit and Blow in pure Go, no dependencies
package main
import (
"bufio"
"flag"
"fmt"
"math/rand"
"os"
"strconv"
"strings"