Skip to content

Instantly share code, notes, and snippets.

View hnakamur's full-sized avatar

Hiroaki Nakamura hnakamur

View GitHub Profile
@hnakamur
hnakamur / multiple_commands_pipe.py
Created July 29, 2015 17:05
multiple commands pipe in Python
from subprocess import Popen, PIPE
cmd = 'cat | head -5'
proc = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE)
outs, errs = proc.communicate(input="""
Popen.communicate(input=None, timeout=None)
Interact with process: Send data to stdin. Read data from stdout and stderr, until end-of-file is reached. Wait for process to terminate. The optional input argument should be data to be sent to the child process, or None, if no data should be sent to the child. The type of input must be bytes or, if universal_newlines was True, a string.
communicate() returns a tuple (stdout_data, stderr_data).
@hnakamur
hnakamur / diag.md
Created October 18, 2015 07:28 — forked from hashrock/diag.md
作図系ツール・ライブラリまとめ

シーケンス図とかフローチャートをしごとで描画することになった場合、 テキストから生成できたら楽なので、それ系のツールまとめ

GraphViz

http://www.graphviz.org/

  • C製
  • Doxygen, Moinmoinなどと連携可能
  • ブロック図、クラス図、ネットワーク図など
@hnakamur
hnakamur / a.odin
Created July 17, 2024 13:41
SIMD experiment with Odin
package main
import "core:fmt"
import "core:simd"
main :: proc() {
i := index_any([]u8{'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', '\r', '&', 'a'}, 16)
fmt.println(i)
}
@hnakamur
hnakamur / Dockerfile
Created June 11, 2020 00:27
Dockefile to build nginx-quic with BoringSSL on Ubuntu 20.04 LTS
FROM ubuntu:20.04
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get -y install git mercurial build-essential cmake ninja-build golang-go zlib1g-dev libpcre3-dev
RUN git clone https://github.com/google/boringssl \
&& cd boringssl \
&& mkdir build \
&& cd build \
&& cmake -GNinja .. \
@hnakamur
hnakamur / bash-args-array.sh
Created March 11, 2024 23:41
bash-args-array.sh
#!/bin/bash
# コマンドライン引数を配列に格納
args=("$@")
# 配列の要素を表示
for arg in "${args[@]}"; do
echo $arg
done
@hnakamur
hnakamur / main.go
Created November 17, 2016 16:17
An example Go web app which prints localized messages
package main
import (
"context"
"html"
"log"
"net/http"
"golang.org/x/text/language"
"golang.org/x/text/message"
@hnakamur
hnakamur / must.go
Created July 12, 2023 23:53
Go generic test must utility
package testx
import "testing"
func Must0(t *testing.T) func(error) {
return func(err error) {
t.Helper()
if err != nil {
t.Fatal(err)
}
@hnakamur
hnakamur / wezterm.lua
Last active July 10, 2023 20:08
My wezterm config
local wezterm = require 'wezterm'
local mux = wezterm.mux
local config = {}
if wezterm.config_builder then
config = wezterm.config_builder()
end
-- set startup Window position
-- https://github.com/wez/wezterm/issues/2976#issuecomment-1419492777
@hnakamur
hnakamur / go.json
Created June 27, 2023 21:03
main.go snippet for VS Code
{
"package main": {
"prefix": "package main",
"body": [
"package main",
"",
"import \"log\"",
"",
"func main() {",
"\tif err := run(); err != nil {",
@hnakamur
hnakamur / source_or_run.sh
Last active June 7, 2023 12:07
Find out whether a bash script is executed or sourced.
#!/bin/bash
if [ $BASH_ARGV0 = -bash ]; then
echo sourced
else
echo executed
fi