Skip to content

Instantly share code, notes, and snippets.

@heiwa4126
heiwa4126 / syslogloop.pl
Last active November 14, 2019 02:38
0.5秒ごとにUDPで現在時刻を送りつけるPerlのコード。syslogサーバのテスト用。
#!/usr/bin/env perl
# -*- coding: utf-8 -*-
# for RHEL `sudo yum install perl-Sys-Syslog`
use strict;
use warnings;
use Sys::Syslog qw(:standard setlogsock);
use Time::HiRes qw(gettimeofday usleep);
use POSIX qw(strftime);
use constant TARGET => 'r1'; ### ** UPDATE HERE. hostname or IP ***
setlogsock('udp');
@heiwa4126
heiwa4126 / doubleHttpd.go
Created November 14, 2019 06:46
golangのnet/httpで、違うポートで2つhttpを立ち上げるテスト。
// 異なるポートで2つhttpdを立ち上げる。タイムアウトも設定してご安全に。
package main
import (
"fmt"
"net/http"
"time"
)
func handler1(w http.ResponseWriter, r *http.Request) {
@heiwa4126
heiwa4126 / utcnow.py
Last active January 15, 2020 06:38
python3でタイムゾーン付き現在時刻。すぐ忘れるのでメモ
from datetime import timezone, datetime
print(datetime.now(timezone.utc))
# 「today() および utcnow() よりもこの関数を使う方が好ましいです」だそうです。
# [datetime --- 基本的な日付型および時間型 — Python 3.8.1 ドキュメント](https://docs.python.org/ja/3/library/datetime.html)
@heiwa4126
heiwa4126 / timefile.py
Created December 16, 2019 09:11
タイムベースでファイル名、とかよくあるあれ。`%f` (Microsecond)が思い出せないのでメモ。
from datetime import timezone, datetime
print(datetime.now(timezone.utc).strftime("%Y%m%d%H%M%S%f"))
@heiwa4126
heiwa4126 / sinwave.jupyter
Last active December 23, 2019 07:24
Jupyter notebookの動作確認用でsin波を書くやつ。
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(-10, 10, 1000)
y = np.sin(x)
plt.plot(x, y)
plt.show()
@heiwa4126
heiwa4126 / utf8tosjis.go
Last active February 11, 2024 10:36
GolangでUTF8をShiftJISに変換する基本。
package main
import (
"fmt"
"golang.org/x/text/encoding/japanese"
"golang.org/x/text/transform"
"log"
)
func main() {
@heiwa4126
heiwa4126 / bufio1.go
Created December 24, 2019 10:51
Golangのbufio.Peek()で、EOFのときにエラーにしたくないときの処理。`err == bufio.ErrBufferFull`ではないところがコツ
package main
import (
"bufio"
"fmt"
"io"
"log"
"strings"
)
@heiwa4126
heiwa4126 / join.yml
Last active March 6, 2020 12:47
Ansibleのjoinとsequenceのサンプル
- name: join and sequence example
hosts: localhost
become: no
gather_facts: False
vars:
data: [foo, bar, baz]
tasks:
-
name: join example
debug: msg="{{ data|join(', ') }}"
@heiwa4126
heiwa4126 / handler1.yml
Last active March 6, 2020 12:52
Ansibleで、handlersを使ってテンポラリフォルダを消すサンプル
- name: handler test
hosts: localhost
become: no
gather_facts: false
force_handlers: true
#-------------
tasks:
- name: Create working directory.
tempfile:
state: directory
@heiwa4126
heiwa4126 / join2.yml
Last active March 6, 2020 13:07
Ansibleのサンプル。Jnija2には内包表記がない。リストを「引用符でくくって、コンマでつなぐ」例。win_shellとかでよく使う。
- name: jinja2 has not list comprehension.
hosts: localhost
become: no
gather_facts: false
vars:
data: [foo, bar, baz]
tasks:
-
debug:
msg: >