Skip to content

Instantly share code, notes, and snippets.

View alphaKAI's full-sized avatar

Akihiro Shoji alphaKAI

View GitHub Profile
@alphaKAI
alphaKAI / metadlang.d
Created November 21, 2019 13:28
Meta Dlang
import std.stdio, std.format;
interface MetaDlangObject {
const enum string eval();
}
interface MetaDlangExpr : MetaDlangObject {
}
interface MetaDlangStatement : MetaDlangObject {
@alphaKAI
alphaKAI / dfa.d
Created October 10, 2019 15:32
DFA util
import std.stdio;
import std.typecons;
import std.conv;
class DFA(Q, Sigma) {
Q q0;
Q[] F;
Q[Tuple!(Q, Sigma)] delta;
this(Q[Tuple!(Q, Sigma)] delta, Q q0, Q[] F) {
@alphaKAI
alphaKAI / apple_music_web_us.js
Created October 7, 2019 13:59
An useful User Script for Apple Music beta (https://beta.music.apple.com)
// ==UserScript==
// @name AppleMusicTools
// @namespace https://alpha-kai-net.info
// @version 0.1
// @description Useful Apple Music User Script
// @author alphaKAI
// @match https://beta.music.apple.com/*
// @grant none
// ==/UserScript==
@alphaKAI
alphaKAI / cpuid.d
Created August 14, 2019 19:38
manipulate CPUID instruction
import std.stdio;
import std.conv;
import std.string;
struct Regs {
uint a, b, c, d;
}
Regs cpuid(uint eax) {
Regs r;
@alphaKAI
alphaKAI / calc.rs
Last active July 18, 2019 00:27
Stack Machine VM based calculator in Rust
#[derive(Debug, Copy, Clone, PartialEq)]
enum VMIns {
Push(i32),
Add,
Sub,
Mul,
Div,
Println,
}
@alphaKAI
alphaKAI / Makefile
Last active May 10, 2019 19:03
Binary Search Tree in C
.PHONY: all test clean
CC := cc
CFLAGS := -Wextra -Wall -g
TARGET = cplayground
SRCS = \
$(shell find ./ -maxdepth 1 -name "*.c") \
$(shell find ./sds -name "*.c")
OBJS = $(shell find ./ -name "*.o")
@alphaKAI
alphaKAI / rbd.d
Created April 23, 2019 13:24
Ruby embedded into D. compile: dmd rbd.d -L-L/path/to/ruby/lib -L-lruby.2.6
/*
Ruby embedded into D.
compile: dmd rbd.d -L-L/path/to/ruby/lib -L-lruby.2.6
Example... dmd rbd.d -L-L/usr/local/opt/ruby/lib -L-lruby.2.6
*/
import std.stdio,
std.string;
extern (C) {
@alphaKAI
alphaKAI / py3.d
Created April 23, 2019 13:10
Python3 Embedded into D. compile: $ dmd py3d.d -L-L/Path/To/Python3LibDirectory -L-lpython3.7m
/*
Python3 Embedded into D.
compile: $ dmd py3d.d -L-L/Path/To/Python3LibDirectory -L-lpython3.7m
Example...
dmd py3d.d -L-L/usr/local/opt/python/Frameworks/Python.framework/Versions/3.7/lib/python3.7/config-3.7m-darwin -L-lpython3.7m
*/
import std.stdio,
@alphaKAI
alphaKAI / avl_tree.d
Last active April 1, 2019 07:53
AVLTrees (implemented in TypeScript, D)
module avl;
import std.stdio;
import std.typecons;
string string_rep(string s, size_t n) {
string ret;
foreach (_; 0 .. n) {
ret ~= s;
}
@alphaKAI
alphaKAI / inner_func.c
Created March 30, 2019 01:33
FAKE nested function defintion def in C
#include <stdio.h>
#define INNNER_FUNC_PROT(N, RET, func_prot) \
func_prot; \
RET inner_func_ ##N ## _next();
#define INNNER_FUNC_DEF(N, RET, func_name, func_def) \
func_name (); \
return inner_func_ ## N ## _next(); \
} \