Skip to content

Instantly share code, notes, and snippets.

View hk220's full-sized avatar

kazuki hk220

View GitHub Profile
@hk220
hk220 / bst.py
Created December 28, 2023 15:11
class Node:
def __init__(self, data):
self.data = data
self.left = None
self.right = None
def __str__(self):
return str(self.data)
def create_tree(array):
// SayHello implements helloworld.GreeterServer
func (s *server) SayHello(ctx context.Context, in *pb.HelloRequest) (*pb.HelloReply, error) {
	log.Printf("Received: %v", in.GetName())
	// return &pb.HelloReply{Message: "Hello " + in.GetName()}, nil
	return nil, fmt.Errorf("hoge")
}

errorを返すと、クライアントにエラーの内容を伝播してくれる。

@hk220
hk220 / fix-microphone-background-noise.sh
Created January 10, 2021 02:26 — forked from adrianolsk/fix-microphone-background-noise.sh
FIx linux microfone background noise
# Microphone Realtime background noise reduction script
# author Luigi Maselli - https://grigio.org licence: AS-IS
# credits: http://askubuntu.com/questions/18958/realtime-noise-removal-with-pulseaudio
# run as: sudo && pulseaudio -k
# wget -qO - https://gist.github.com/adrianolsk/bfa32f3227dc674eff72a2008f6c0316 | sudo bash && pulseaudio -k
sudo cp /etc/pulse/default.pa /etc/pulse/default.pa.bak
sudo cat <<EOT >> /etc/pulse/default.pa
load-module module-echo-cancel source_name=noechosource sink_name=noechosink
@hk220
hk220 / Applicative.scala
Last active November 11, 2020 14:35
Scala Text 付録:様々な型クラスの紹介
// memo: Applicative Functor型クラス
trait Applicative[F[_]] {
def point[A](a: A): F[A]
def ap[A, B](fa: F[A])(f: F[A => B]): F[B]
def map[A, B](fa: F[A])(f: A => B): F[B] = ap(fa)(point(f))
}
// memo: Applicative則
// https://eed3si9n.com/herding-cats/ja/Applicative.html
.PHONY: setup
setup:
sudo apt-get update
sudo apt-get install -y unzip build-essential libsnmp-dev p7zip-full # Debian-based distros
.PHONY: mibs
mibs:
git clone https://github.com/prometheus/snmp_exporter.git snmp_exporter
cd snmp_exporter/generator; make mibs
#!/bin/python3
import subprocess
import re
EFIBOOTMGR = 'efibootmgr'
SHOW_BOOTMGR = [EFIBOOTMGR, '-v']
BOOT_CURRENT_RE = re.compile(r'^BootCurrent: (?P<current>\d+)$')
TIMEOUT_RE = re.compile(r'^Timeout: (?P<timeout>\d+) seconds$')
BOOT_ORDER_RE = re.compile(r'^BootOrder: (?P<order>[\d,]+)$')
@hk220
hk220 / gist:fe1ab01e78d157a6af3cb04451784f08
Created June 9, 2018 04:36
OSS Gate 作業メモのメモ
# 180609
URxvt*font: xft:Source Code Pro:size=12:antialias=true
URxvt*boldFont: xft:Source Code Pro:size=12:style=bold:antialias=true
URxvt*termName: rxvt-256color
URxvt*xftAntialias: true
URxvt*background: #3f3f3f
URxvt*foreground: #dcdccc
URxvt*cursorColor: #aaaaaa
URxvt*colorUL: #366060
URxvt*underlineColor: #dfaf8f
URxvt*color0: #3f3f3f
;; 2.4.2 タグ付きデータ
;; type-tag と contents という手続きを持っていると想定する。
;; type-tag: データオブジェクトからタグを抽出するもの。
;; contents は実際の中身。
(define (attach-tag type-tag contents)
(cons type-tag conents))
(define (type-tag datum)
(if (pair? datum)
(car datum)
(error "Bad tagged datum: TYPE-TAG" datum)))
;; 2.4.1
(define (add-complex z1 z2)
(make-from-real-imag (+ (real-part z1) (real-part z2))
(+ (imag-part z1) (imag-part z2))))
(define (sub-complex z1 z2)
(make-from-real-imag (- (real-part z1) (real-part z2))
(- (imag-part z1) (imag-part z2))))