Skip to content

Instantly share code, notes, and snippets.

View alphaKAI's full-sized avatar

Akihiro Shoji alphaKAI

View GitHub Profile
@alphaKAI
alphaKAI / HelloWorld.md
Last active June 29, 2016 20:38
Hello World in various language(which I can use or have touched)

#Hello World in various programming languages

##Listed

  • C
  • C++
  • D
  • Ruby
  • TypeScript
  • F#
  • Haskell
@alphaKAI
alphaKAI / tinyBase64Decoder.fs
Last active June 29, 2016 23:25
Tiny Base64 Decoder in F#
module tinyBase64Decoder
open System
open System.Collections.Generic
// Declare fundamental functions
// Convert binary string into decimal
let binToDec binStr = Convert.ToInt32 (binStr, 2)
// Convert decimal into binary string
@alphaKAI
alphaKAI / zcomb.cpp
Last active June 27, 2016 02:04
Z Combinator for D and C++
#include <iostream>
#include <functional>
template <typename R, typename... Args>
std::function<R(Args...)> Z(std::function<R(std::function<R(Args...)>, Args...)> f) {
return [&](const Args&... args) { return f(Z(f), args...); };
}
int main(int argc, char const* argv[]) {
std::cout <<
@alphaKAI
alphaKAI / curry.ts
Created June 24, 2016 15:11
currying in TypeScript! Currying any function.
function isFunction(obj: any): boolean {
return typeof(obj) == "function";
}
function curry(func: any) {
if (!isFunction(func)) {
console.log("Fatal Error. An invalid value was given. It was not a function");
return;
}
@alphaKAI
alphaKAI / jsonStructure.d
Last active June 21, 2016 10:09
Yet Another JSON Parser for D[WIP].
import std.conv;
enum JSONNodeValueType {
Numeric,
String,
Boolean,
Array,
NULL,
JSONObject
}
@alphaKAI
alphaKAI / wave.d
Created June 17, 2016 13:33
Handling WAVE format in D Raw. This program works as $ ffmpeg -i filename -f s16le -ac 2 -acodec pcm_s16le -ar 44100 filename.pcm
import std.stdio;
struct ChunkHead {
char[4] id;
uint size;
}
struct RiffChunk {
ChunkHead head;
char[4] format;
@alphaKAI
alphaKAI / c_version.c
Last active June 10, 2016 17:52
D language's template version of C's container_of and offsetof macro
#include <stdio.h>
#define offsetof(type, member) ((size_t)&((type*)0)->member)
#define container_of(ptr, type, member) ({ \
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );})
typedef struct {
int val1;
@alphaKAI
alphaKAI / singlelist.c
Last active June 10, 2016 13:53
データとリストを分離し、任意の型で簡単に単方向リストを実装できるようにするサンプル(Linuxカーネルでの実装を参考にしました。)
#include <stdbool.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#define container_of(ptr, type, member) ({ \
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );})
#ifdef __compiler_offsetof
#define offsetof(TYPE,MEMBER) __compiler_offsetof(TYPE,MEMBER)
#else
@alphaKAI
alphaKAI / Installation.md
Last active April 10, 2016 04:07
Sample of LINE echo bot in D Programming Language.

Installation of this code

Pre-requirements

Note: Currently, LINE bot API is TRIAL, limited to the first 10,000 developers.

Installation

  1. Create vibe.d application skeleton with dub
class BASE {}
class A : BASE {}
BASE f(A a) {return a;}
void main() {
BASE b = new BASE;
A a = new A;
assert (typeid(b) == typeid(typeof(b))); // pass
assert (typeid(a) == typeid(typeof(a))); // pass