Skip to content

Instantly share code, notes, and snippets.

View kubo39's full-sized avatar
💭
I may be slow to respond.

Hiroki Noda kubo39

💭
I may be slow to respond.
View GitHub Profile
# -*- coding: utf-8 -*-
# Numericクラスを拡張
class Numeric
# 数値の二乗を計算するメソッド
# 返り値はfloat
def pow
self ** 2.0
end
end
# -*- coding: utf-8 -*-
# 辺
$edge = [[0,1,2], [0,2,5], [1,2,4], [1,3,6],
[1,4,10], [2,3,2], [3,5,1], [4,5,3],
[4,6,5], [5,6,9], [1,0,2], [2,0,5],
[2,1,4], [3,1,6], [4,1,10], [3,2,2],
[5,3,1], [5,4,3], [6,4,5], [6,5,9]]
# ダイクストラ法
@kubo39
kubo39 / knapsack.py
Created October 6, 2011 14:36
Solved by Dynamic programming.
MAX_N = 100
MAX_W = 10000
knap = [
{'weight':2, 'value':3},
{'weight':1, 'value':2},
{'weight':3, 'value':4},
{'weight':2, 'value':2}
]
# -*- coding: utf-8 -*-
require 'socket'
class Resolver
@sock = Socket::new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
@fd = @sock.fileno
# INETのSTRAMソケットを作成
attr_reader :queue, :results, :dnsserver, :port
def initialize
require 'rubygems'
require 'eventmachine'
EM.run do
resolver = proc do
['210.251.121.21', "8.8.8.8"].map do |addr|
begin
Resolv.getname addr
rescue
addr
import std.stdio;
/* 要素がすべて無限大である、num_v * num_v の2重配列 */
pure real[][] make_cost(int num_v)
{
real[][] cost;
cost.length = num_v+1;
for(int i;i<=num_v;i++){
cost[i].length = num_v+1;
import std.stdio;
class BinaryIndexedTree {
int size;
int[] bits;
this(int l){
size = l;
bits.length = l+1;
}

パターン認識

ものがどのくらい似ているか=類似度

似ている=相対量

  • 他のものがないと判断できない(正例、負例)
@kubo39
kubo39 / fakednsserver.rb
Last active December 13, 2015 23:39
fake DNS server
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
require 'socket'
class DNSQuery
attr_reader :domain_io
def initialize data
@data = data
@domain_io = ''
@kubo39
kubo39 / async.md
Created March 23, 2013 17:33
非同期プログラミングめも

非同期とか並列とか

いわゆる非同期

2種類考えられる

  • IO多重化(epoll/kqueue/etc..)

read(2)/write(2)が非同期