Skip to content

Instantly share code, notes, and snippets.

View alphaKAI's full-sized avatar

Akihiro Shoji alphaKAI

View GitHub Profile
@alphaKAI
alphaKAI / keymap.c
Last active April 19, 2023 00:25
alphakai's Keychron Q2 ANSI Encoder model keymap.c
/* Copyright 2021 @ Keychron (https://www.keychron.com)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

Keybase proof

I hereby claim:

  • I am alphakai on github.
  • I am alphakai (https://keybase.io/alphakai) on keybase.
  • I have a public key ASBN9H3xYiXbY3Ay4NMfosF-Ai9eqqpcP3WfOBO2KAMkRAo

To claim this, I am signing this object:

#include <stdio.h>
#include <string.h>
void show_char_bits(char c) {
for (size_t i = 0; i < 8; i++) {
printf("%i", (c >> (7 - i)) & 1);
}
printf("\n");
}
@alphaKAI
alphaKAI / expr_calc.c
Last active August 18, 2020 03:24
四則演算(+剰余)の式をスタックマシンで計算するプログラム
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <stdint.h>
#include <stdbool.h>
#include <limits.h>
////////////////////// Util //////////////////////
@alphaKAI
alphaKAI / baby_translator_v3.d
Last active July 7, 2020 13:31
赤ちゃん語に変換するやつ (v3はv2のUTF-8化。v2は「ば」「ぶ」「マ」「!」の4値をつかって変換, 無印(original)は「ばぶばぶ!」と「ママ!」の2値で変換)
import std;
enum int[dchar] BabyTerm = [
'ば' : 0b0000,
'ぶ' : 0b0001,
'マ' : 0b0010,
'!' : 0b0011,
];
enum dchar[int] BabyTerm_R = [
@alphaKAI
alphaKAI / context_switching.c
Created June 9, 2020 10:33
context switching using ucontext_t and context family functions
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <ucontext.h>
#include <sys/time.h>
#include <stdbool.h>
void *xmalloc(size_t size) {
void *ptr = malloc(size);
@alphaKAI
alphaKAI / sjlj_test.d
Created May 28, 2020 19:52
setjmp/longtest behavior test in D
import core.sys.posix.setjmp;
import std.stdio;
import std.format;
string yield(alias callee_env, alias caller_env, alias val)() {
return q{
if (setjmp(%s) == 0) {
longjmp(%s, %s);
}
}.format(callee_env.stringof, caller_env.stringof, val);
@alphaKAI
alphaKAI / sexp.rs
Last active March 22, 2020 14:24
S-Expression Parser in Rust
#[derive(Debug)]
pub enum SexpObject {
Float(f64),
Bool(bool),
String(String),
Symbol(String),
List(Vec<SexpObject>),
}
impl SexpObject {
00100110000000000000000000000000
00000001000000000000000000000001
00100110000100010000000000000000
00000001000100000000000000000100
00100110001000100000000000000000
00000001001000000000000000000011
00000100000100100000000000000000
00100110001000100000000000000000
00000001001000000000000000000010
00000010000100100000000000000000
@alphaKAI
alphaKAI / rt_o1_fizzbuzz.d
Created November 26, 2019 04:19
Runtime O(1) FizzBuzz by nested string-mixin
import std.stdio;
import std.format;
import std.traits;
import std.array;
mixin(q{
enum string fizzbuzz_code = {
enum string prim_fb(int M)() {
static if (M % 15 == 0) { return "writeln(\"fizzbuzz\");"; }
else if (M % 3 == 0) { return "writeln(\"fizz\");"; }