Skip to content

Instantly share code, notes, and snippets.

@hnaohiro
hnaohiro / webcam.rb
Created August 6, 2013 06:30
RubyでWebカメラを使い、WebSocketで配信する最小のコード
require 'opencv'
require 'em-websocket'
require 'base64'
class WebCam
def initialize(n = 0)
@cap = OpenCV::CvCapture.open(n)
end
def get_with_base64
@hnaohiro
hnaohiro / pagination.ctp
Last active December 19, 2015 10:49
CakePHP + Twitter Bootstrapでページネーション
<div class="pagination">
<ul>
<?php echo $this->Paginator->prev(__('prev'), array('tag' => 'li'), null, array('tag' => 'li','class' => 'disabled','disabledTag' => 'a')); ?>
<?php echo $this->Paginator->numbers(array('separator' => '','currentTag' => 'a', 'currentClass' => 'active','tag' => 'li','first' => 1, 'ellipsis' => '<li class="disabled"><a>...</a></li>')); ?>
<?php echo $this->Paginator->next(__('next'), array('tag' => 'li','currentClass' => 'disabled'), null, array('tag' => 'li','class' => 'disabled','disabledTag' => 'a')); ?>
</ul>
</div>
@hnaohiro
hnaohiro / opencv_install.sh
Last active December 19, 2015 06:28
OpenCVをインストールするスクリプト http://www.kkaneko.com/rinkou/opencv/opencvinstalllinux.html
# 最初は前提ソフトウエアのインストール
sudo apt-get -yV install build-essential
#
cd /tmp; sudo apt-get source opencv
sudo apt-get -yV build-dep opencv
#
sudo apt-get -yV install opencl-headers
#
sudo apt-get -yV install libjpeg-dev
sudo apt-get -yV install libopenjpeg-dev
@hnaohiro
hnaohiro / ip_mac.rb
Last active December 19, 2015 03:19
LAN内のすべての端末のIPアドレスとMACアドレスを収集
def ping(ip)
r = Regexp.new('[1-9]\d* (packets )?received')
result = r.match(`ping -c 1 -W 1 #{ip}`)
result != nil
end
def arp(ip)
r = Regexp.new('[0-f]+:[0-f]+:[0-f]+:[0-f]+:[0-f]+:[0-f]+')
result = r.match(`arp -n #{ip}`)
result ? result.to_s : nil
@hnaohiro
hnaohiro / capture.rb
Created April 22, 2013 04:21
ruby-opencvでキャプチャーした画像を保存
require 'opencv'
capture = OpenCV::CvCapture.open
mat = capture.query.to_CvMat
mat.save('output.jpg')
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QLayout>
#include <QVTKWidget.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
MainWindow::MainWindow(QWidget *parent) :
#-------------------------------------------------
#
# Project created by QtCreator 2013-03-14T00:52:51
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
@hnaohiro
hnaohiro / active_record_sample.rb
Created February 11, 2013 17:58
Ruby単体でのActive Recordのサンプル
require 'active_record'
ActiveRecord::Base.establish_connection(
:adapter => 'sqlite3',
:database => 'db/hatena.db'
)
class EntryInit < ActiveRecord::Migration
def self.up
create_table(:entries) do |t|
@hnaohiro
hnaohiro / mongo2redis.rb
Last active December 12, 2015 09:59
MongoのデータをRedisに移して検索する
# encoding: utf-8
require 'redis'
require 'mongo'
def mongo2redis
redis = Redis.new
redis.flushall
connection = Mongo::Connection.new
@hnaohiro
hnaohiro / struct2map.go
Created January 24, 2013 21:35
Golangでreflectを使ってstructからmapへ変換
package main
import (
"fmt"
"reflect"
)
func StructToMap(data interface{}) map[string]interface{} {
result := make(map[string]interface{})
elem := reflect.ValueOf(data).Elem()