Skip to content

Instantly share code, notes, and snippets.

View kazoo04's full-sized avatar

Kazuya Gokita kazoo04

  • Garm Inc.
  • Tokyo
View GitHub Profile
@kazoo04
kazoo04 / p2p_mahjong.md
Created May 3, 2016 14:11
P2Pで麻雀をする方法

はじめに

P2Pのような中央集権型でない環境や、信頼できるノードが存在しないときは、合意形成が難しいため様々な手法が提案されています。

ここでは、麻雀を例にとり、各クライアントが自身の動作を悪意を持って制御可能な状況下で、 定められた手順通り正しく動作をしていて正しく動作し続けたことを後から検証する方法について述べます。

問題設定

麻雀では山(壁牌)から牌を取り(自摸、ツモ)、手牌に加えたのち1枚を捨てる(打牌)ことを繰り返して役を揃えることを目指します。

import cv2
import numpy as np
def create_template():
templates = []
for text in list('0123456789'):
img = np.zeros((200,200,1), dtype=np.uint8)
cv2.putText(img, text, (100, 100), cv2.FONT_HERSHEY_DUPLEX, 2, 255, 5)
contours, _ = cv2.findContours(img.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
x, y, w, h = cv2.boundingRect(contours[0])
import std.stdio;
import std.array;
import std.utf;
void main() {
string s = "AあBい";
foreach(c; array(s)) {
foreach(b; [c].toUTF8) {
writef("%02x ", b);
}
@kazoo04
kazoo04 / card.html
Created March 13, 2015 06:09
materialize card
<div class="row">
<div class="col s12 m6">
<div class="card">
<div class="card-content blue-grey darken-1">
<span class="card-title lighten-5-text">Card Title</span>
</div>
<div class="card-content grey lighten-5 darken-4-text">
<p>I am a very simple card. I am good at containing small bits of information.
I am convenient because I require little markup to use effectively.</p>
</div>
import arow;
import std.stdio;
import std.random;
import std.string;
import std.conv;
import std.file;
import std.stream;
struct example {
int label;
@kazoo04
kazoo04 / request.py
Created October 9, 2014 10:36
Mesiterror API sample
# -*- coding: utf-8 -*-
import urllib.request
import urllib.response
import json
if __name__ == '__main__':
api_url = 'http://food.kazoo04.com:8080/api/v0/upload'
img_url = 'http://www.example.com/image.jpg'
@kazoo04
kazoo04 / request.rb
Created October 9, 2014 10:35
Mesiterror API sample
#encoding: utf-8
require 'uri'
require 'net/http'
require 'json'
uri = 'http://food.kazoo04.com:8080/api/v0/upload'
img_url = 'http://www.example.com/image.jpg'
parsed = URI.parse(uri)
@kazoo04
kazoo04 / request.go
Last active August 29, 2015 14:07
Mesiterror API sample
package main
import (
"net/http"
"net/url"
"io/ioutil"
"encoding/json"
"fmt"
)
@kazoo04
kazoo04 / xor_example.c
Created September 11, 2014 09:05
XorShift_example
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
unsigned long xorshift() {
static unsigned long x=123456789, y=362436069, z=521288629, w=88675123;
unsigned long t;
t = (x ^ (x << 11));
x = y;
@kazoo04
kazoo04 / xorshift.c
Created September 11, 2014 05:58
XorShift
unsigned long xorshift() {
static unsigned long x=123456789, y=362436069, z=521288629, w=88675123;
unsigned long t;
t = (x ^ (x << 11));
x = y;
y = z;
z = w;
w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));