Skip to content

Instantly share code, notes, and snippets.

Avatar

Hiroaki Nakamura hnakamur

View GitHub Profile
@hnakamur
hnakamur / mytask.yaml
Created May 15, 2022
trim spaces in ansible vairable using jinja2 if
View mytask.yaml
---
- name: My playbook
hosts: localhost
vars:
zabbix_agentd_d_dir: >-
{% if ansible_facts['os_family'] == 'RedHat' -%}
/etc/zabbix/zabbix_agentd.d
{%- else -%}
/etc/zabbix/zabbix_agentd.conf.d
{%- endif %}
View a.js
atob(`DES9N7bxsOmHupY4JsjDg6fZ7vaFIZaWDBASiCj6vN+S
VYuCa9Bo5LdJHmeo+kpmK2PTvlShVkxpOwt59hGX6sdlT
apaRgEGCB8FZt3iSkE9EdmShv5vmSv3oMrCoSFlqnLeGY
9Wh6hNCNx4nUfxtzjoExo494fUr+hZebjFTo5ow//oy22
fW8fuwieImoEm7y28eFSmN5ITVpjzDabYQBjYPgRpLStG
jRMcsilxGH6Ud3nweSyqjimsCs6f2OL4JuoIfPTSVAP9/
hiab9VKmyBM3WbOVwAi+wLjoS6k1FcAcyjQo8HUM3v
GALSnPn7w+wnD5YNKRdXPVpQ8tq+stidQzFdESSzajS7
rPC81pzrIjW3tXOkrDmusp/mEzfTEHOsFRq9eq3kOJr+
CXXSOhjXuSSPVNH1rt8JIDUts529LqAb5pPfYta1L4bD
@hnakamur
hnakamur / main.rs
Last active Apr 14, 2022
Read a byte from stdin in rust
View main.rs
use std::io;
use std::io::prelude::*;
fn main() -> io::Result<()> {
let mut buffer = [0; 1];
loop {
let n = io::stdin().read(&mut buffer)?;
if n == 0 {
break;
}
@hnakamur
hnakamur / show-cert-info-file.sh
Created Apr 14, 2022
Print dates, subject, issuer, and SANs in a server certificate and intermediate certificates at a server or in a file.
View show-cert-info-file.sh
#!/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 Apr 2, 2022
modified std.math.cast to support .ComptimeInt as well as .Int
View math.zig
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 Nov 8, 2021
Zig minimal generic callback example (slimmed version of TigerBeetle IO struct)
View callback_example.zig
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 Aug 19, 2021 — 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.
View bm_test.go
package bm
import (
"testing"
)
var mb = map[string]bool{
"alpha": true,
"beta": true,
"gamma": true,
@hnakamur
hnakamur / main.go
Created Jul 13, 2021
Go math/rand.NewZipf example
View main.go
package main
import (
"fmt"
"log"
"math/rand"
"sort"
"time"
)
@hnakamur
hnakamur / apt-key-add
Created May 12, 2021
Alternative script for "apt-key add" which is deprecated in Ubuntu 20.10
View apt-key-add
#!/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 Nov 21, 2020
openssl speed -evp aes-128-ctr | aes-128-gcm | chacha20-poly1305 のApple M1 Mac miniでの結果
View openssl-1.1.1h-apple-m1-mac-mini.log.md
% 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)