Skip to content

Instantly share code, notes, and snippets.

View hnakamur's full-sized avatar

Hiroaki Nakamura hnakamur

View GitHub Profile
@hnakamur
hnakamur / show-cert-info-file.sh
Created April 14, 2022 00:16
Print dates, subject, issuer, and SANs in a server certificate and intermediate certificates at a server or in a file.
#!/bin/bash
if [ $# -ne 1 ]; then
>&2 echo "Usage: $0 /path/to/cert_file"
exit 1
fi
cert_file="$1"
certs=$(cat $cert_file)
count=$(echo "$certs" | grep -c '^-----BEGIN CERTIFICATE-----')
i=1
@hnakamur
hnakamur / math.zig
Created April 2, 2022 15:29
modified std.math.cast to support .ComptimeInt as well as .Int
const std = @import("std");
const assert = std.debug.assert;
const maxInt = std.math.maxInt;
const minInt = std.math.minInt;
pub fn cast(comptime T: type, x: anytype) (error{Overflow}!T) {
comptime assert(@typeInfo(T) == .Int); // must pass an integer
comptime assert(@typeInfo(@TypeOf(x)) == .Int or
@typeInfo(@TypeOf(x)) == .ComptimeInt); // must pass an integer or comptimeint
if (x > maxInt(T)) {
@hnakamur
hnakamur / callback_example.zig
Created November 8, 2021 08:50
Zig minimal generic callback example (slimmed version of TigerBeetle IO struct)
pub const Transport = struct {
pub fn send(
self: *Transport,
comptime Context: type,
context: Context,
comptime callback: fn (
context: Context,
reuslt: usize,
) void,
) void {
@hnakamur
hnakamur / bm_test.go
Last active August 19, 2021 12:56 — forked from mipearson/bm_test.go
Add an increment of a global variable after each op to ensure the Go compiler isn't being clever about optimisation.
package bm
import (
"testing"
)
var mb = map[string]bool{
"alpha": true,
"beta": true,
"gamma": true,
@hnakamur
hnakamur / main.go
Created July 13, 2021 06:49
Go math/rand.NewZipf example
package main
import (
"fmt"
"log"
"math/rand"
"sort"
"time"
)
@hnakamur
hnakamur / apt-key-add
Created May 12, 2021 04:59
Alternative script for "apt-key add" which is deprecated in Ubuntu 20.10
#!/bin/bash
# apt-key-add - Alternative script for "apt-key add" which is deprecated in Ubuntu 20.10
#
# example:
# curl -fsSL https://deb.nodesource.com/gpgkey/nodesource.gpg.key | sudo apt-key-add - nodesource
# instead of
# curl -fsSL https://deb.nodesource.com/gpgkey/nodesource.gpg.key | sudo apt-key add -
#
set -e
if [ $# -ne 2 -o $UID -ne 0 ]; then
@hnakamur
hnakamur / openssl-1.1.1h-apple-m1-mac-mini.log.md
Last active November 21, 2020 14:53
openssl speed -evp aes-128-ctr | aes-128-gcm | chacha20-poly1305 のApple M1 Mac miniでの結果
% sysctl -n hw.model
Macmini9,1
% /usr/libexec/PlistBuddy -c 'print :"CPU Names"' ~/Library/Preferences/com.apple.SystemProfiler.plist | awk -F ' = ' '{prevlast=last; last=$2} END{print prevlast}' 
Mac mini (M1, 2020)
@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 / test.py
Last active June 10, 2020 13:39
LXD REST API example via unix socket using python3 socket
#!/usr/bin/env python3
import socket
target_host = "localhost"
socket_path = "/var/snap/lxd/common/lxd/unix.socket"
client = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
client.connect(socket_path)
# send some data
@hnakamur
hnakamur / main.c
Created May 11, 2020 11:55
try to print time on every second on realtime clock
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
const int sec_in_nsec = 1000000000;
#define ITERMAX 10000
typedef long long nanotime_t;