Skip to content

Instantly share code, notes, and snippets.

View ochaochaocha3's full-sized avatar

Kosuke Yamashita ochaochaocha3

View GitHub Profile
@ochaochaocha3
ochaochaocha3 / tact_switch.cpp
Created November 11, 2016 13:12
Raspberry Pi:チャタリング対策付き負論理タクトスイッチのC++クラス
/**
* @file tact_switch.cpp
* @brief タクトスイッチ
*/
#include "tact_switch.h"
#include <wiringPi.h>
@ochaochaocha3
ochaochaocha3 / Makefile
Created September 18, 2016 15:53
OSXでOpenCVのテスト
CXX=clang++
CXXFLAGS=-Wall
LDLIBS=-lopencv_core -lopencv_highgui -lopencv_imgproc
capture: capture.cpp
$(CXX) $(CXXFLAGS) -o $@ $^ $(LDLIBS)
@ochaochaocha3
ochaochaocha3 / extract_configuration_options.rb
Last active August 19, 2016 15:22
MobileFrontend configuration options extraction and conversion to MediaWiki markup
source = File.read('README.md')
m = source.match(/^Configuration options\n---------------------/)
raise 'Missing "Configuration options" headng' unless m
body = m.post_match.strip
# Adjust heading level
body.gsub!(/^##/, '')
@ochaochaocha3
ochaochaocha3 / johnson.rb
Created July 5, 2016 12:50
フローショップ・スケジューリングのジョンソン・アルゴリズムの実装(Ruby)
require 'forwardable'
# ジョブを表すクラス
class Job
# ジョブの名前
# @return [String]
attr_reader :name
# ジョブの所要時間
# @return [Array<Numeric>]
attr_reader :length
@ochaochaocha3
ochaochaocha3 / johnson.scm
Last active July 5, 2016 12:56
フローショップ・スケジューリングのジョンソン・アルゴリズムの実装(Gauche)
; ジョブを作成する
(define (make-job name len1 len2)
(list name (cons len1 len2)))
; ジョブの名前を返す
(define (job-name job)
(car job))
; ジョブの所要時間をペアの形で返す
(define (job-length job)
@ochaochaocha3
ochaochaocha3 / display_old_rooms.rb
Last active July 2, 2016 09:27
どどんとふの「削除可能」な部屋の一覧を表示するスクリプト
#!/usr/bin/env ruby
require 'optparse'
require 'json'
PlayRoom = Struct.new(:num, :name, :updated)
def pad(s, width)
char_lengths = s.each_char.map { |c| c.ord >= 8192 ? 2 : 1 }
length = char_lengths.reduce(0, &:+)
@ochaochaocha3
ochaochaocha3 / client_command.rb
Last active May 5, 2016 01:39
どどんとふのコマンドテーブルのプロトタイプ
require_relative 'command_table'
# クライアントからのコマンドを定義するクラス
class ClientCommand
include CommandTable
# 部屋の状態を取得するコマンド
define_command('getPlayRoomStates') do
{
minRoom: 0,
@ochaochaocha3
ochaochaocha3 / ex7.rb
Created August 19, 2015 11:30
2015-08-19 Code Kata2 問題 7
# 7 けたの整数 2004XXX は 2, 3, 4, 5, 6, 7, 8 すべての倍数です。
# XXX に入る 3 けたの整数を求めなさい。
# 2 で割り切れるので 2004XXX は偶数
# 約数について
# * 8 で割り切れる => 4, 2 でも割り切れる
# * 6 で割り切れる => 3 でも割り切れる
# ので、[5, 6, 7, 8] で割り切れるものを選べばよい
nums = (0..999).select { |n| n % 2 == 0 }
@ochaochaocha3
ochaochaocha3 / ex6.rb
Last active August 29, 2015 14:27
2015-08-19 Code Kata2 問題 6
# 問題 6. A は 0 でない整数とし、<A> は A の約数の和を表すものとします。
# たとえば、<8> = 1 + 2 + 4 + 8 = 15 です。
# 約数のリストを求める
def divisors(n)
# 1、n は必ず含まれる
# n/2 < d < n である d で n を割ると必ず 1 より大きく 2 未満になる
# ので、d は約数ではない
[1] + (2..(n / 2)).select { |d| n % d == 0 } + [n]
end
@ochaochaocha3
ochaochaocha3 / jan-check-digit.c
Last active August 29, 2015 14:25
バーコード(JAN)のチェックディジットを算出する
#include <stdio.h>
#include <string.h>
#include <assert.h>
// チェックディジットを返す
// [data] チェックディジットなしのデータ
// [length] データの長さ
int check_digit(char* data, int length) {
int sum_odd = 0; // 奇数の和
int sum_even = 0; // 偶数の和