Skip to content

Instantly share code, notes, and snippets.

View hnakamur's full-sized avatar

Hiroaki Nakamura hnakamur

View GitHub Profile
@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 / 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 / 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
@hnakamur
hnakamur / main.go
Created May 3, 2023 23:04
verify Go os.File.Read returns 0, io.EOF at end of file.
package main
import (
"io"
"log"
"os"
)
func main() {
if err := run(); err != nil {
@hnakamur
hnakamur / 1677487639.json.diff
Last active February 28, 2023 14:14
Karabiner-Elements complex modifications takezo + ctrl-k for Microsoft 365
--- 1677487639.json 2023-02-27 17:51:03
+++ with-ctrl-k.json 2023-02-27 17:54:54
@@ -919,6 +919,42 @@
{
"type": "basic",
"from": {
+ "key_code": "k",
+ "modifiers": {
+ "mandatory": [
+ "control"
@hnakamur
hnakamur / bounded_array_example.zig
Created February 17, 2023 23:55
Zig BoundedArray example
// Zig version: 0.10.1
// Import the standard library.
const std = @import("std");
// Define MyBoundedArray type.
const maxLength = 32;
const MyBoundedArray = std.BoundedArray(u8, maxLength);
/// Takes a slice as a parameter and fills it with a message.
@hnakamur
hnakamur / ilog2_test.c
Created January 4, 2023 12:52
Test ilog2
#include <math.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gmp.h>
#include <mpfr.h>
int ilog2(uint64_t x) { return 63 - __builtin_clzll(x); }