google-code-prettify – Project Hosting on Google Code
wget http://google-code-prettify.googlecode.com/files/prettify-21-May-2009.zip
unzip prettify-21-May-2009.zip
srcとtestsのディレクトリが解凍されたので、httpで見える場所に置く
mkdir ~/www/shokai.org/js
cp -R src/ ~/www/shokai.org/js/pre
inoveテーマを使っているので、 wp-content/themes/inove/header.php を編集
headの中に
<script type="text/javascript" src="http://shokai.org/js/pre/prettify.js"></script>
<link rel="stylesheet" type="text/css" href="http://shokai.org/js/pre/prettify.css" />
bodyタグを修正
<body onload="prettyPrint()">
これでpreやcodeタグでclass=”prettyprint”すれば色が付く
さすがに>や<は>と<に置換しないとならんかった
line-heightが広くなりすぎたのでcssで修正
c++テスト
#include "cv.h"
#include "highgui.h"
#include <boost/program_options.hpp>
#include <iostream>
using namespace boost;
using namespace std;
int main(int argc, char* argv[]) {
program_options::options_description opts("options");
opts.add_options()
("help,h", "ヘルプを表示")
("cascade,c", program_options::value<string>(), "haarcascade設定ファイル")
("input,i", program_options::value<string>(), "入力画像ファイル名")
("output,o", program_options::value<string>(), "出力ファイル名")
("preview,p", "プレビュー表示");
program_options::variables_map argmap;
program_options::store(parse_command_line(argc, argv, opts), argmap);
program_options::notify(argmap);
if (argmap.count("help") || !argmap.count("cascade") || !argmap.count("input")) {
cerr << "cascadeとinputが必要です" << endl;
cerr << opts << endl;
return 1;
}
CvHaarClassifierCascade *cascade;
cascade = (CvHaarClassifierCascade*)cvLoad(argmap["cascade"].as<string>().c_str(), 0, 0, 0);
if(!cascade){
cerr << "error! Cascade not Found" << endl;
return -1;
}
IplImage *image = cvLoadImage(argmap["input"].as<string>().c_str());
if(!image){
cerr << "error! Image File not Found" << endl;
return -11;
}
CvMemStorage *storage = 0;
storage = cvCreateMemStorage(0);
CvSeq* faces = cvHaarDetectObjects(image, cascade, storage,
1.1, 2, CV_HAAR_DO_CANNY_PRUNING,
cvSize(30, 30));
bool isOutput = (argmap.count("preview")||argmap.count("output"));
for(int i = 0; i < faces->total; i++){
CvRect *rect = (CvRect*)cvGetSeqElem(faces, i);
cout << "x:" << rect->x << ", y:" << rect->y
<< ", width:" << rect->width << ", height:" << rect->height << endl;
if(isOutput){
CvPoint center;
center.x = rect->x + rect->width/2.0;
center.y = rect->y + rect->height/2.0;
int r = (rect->width + rect->height)/4.0;
cvCircle(image, center, r, CV_RGB(255, 0, 0), 2, CV_AA, 0);
}
}
if(argmap.count("output")){
string out_filename = argmap["output"].as<string>();
cout << "save! " << out_filename << endl;
cvSaveImage(out_filename.c_str(), image);
}
if(argmap.count("preview")){
char winName[] = "haarcascade test";
cvNamedWindow(winName, CV_WINDOW_AUTOSIZE);
cvShowImage(winName, image);
while (1) {
if (cvWaitKey(1) == 'q') break;
}
cvDestroyWindow(winName);
}
cvReleaseImage(&image);
return 0;
}
rubyテスト
#!/usr/bin/env ruby
require 'rubygems'
require 'active_record'
require 'feed-normalizer'
require 'open-uri'
require 'kconv'
require 'yaml'
require File.dirname(__FILE__) + "/model_post.rb"
config = YAML::load open(File.dirname(__FILE__)+'/config.yaml')
user = config["usernum"] # twitterID
if user == nil
puts 'Error!: usernum not Found on config.yaml'
exit(1)
end
ActiveRecord::Base.establish_connection(
:adapter => 'sqlite3',
#:dbfile => ':memory:',
:dbfile => File.dirname(__FILE__) + '/db',
:timeout => 30000
)
last = 10
last = ARGV[0].to_i if ARGV[0].to_i > 0
first = 1
first = ARGV[1].to_i if ARGV[1].to_i > 0
errors = Array.new
for page in first..last
uri = "http://twitter.com/statuses/user_timeline/#{user}.atom?page=#{page}"
begin
if(config["user"] != nil && config["pass"] != nil)
feed = FeedNormalizer::FeedNormalizer.parse open(uri, :http_basic_authentication => [config["user"], config["pass"]])
else
feed = FeedNormalizer::FeedNormalizer.parse open(uri)
end
rescue
puts "feed fetch error! page:#{page}"
errors.push(page)
sleep 10
next
end
puts uri
feed.entries.each{ |e|
if Post.find_by_uri(e.url) == nil
post = Post.create(:uri => e.url,
:message => e.content.gsub(/(?:(\d*?)|(?:[xX]([0-9a-fA-F]{4})));/) { [$1.nil? ? $2.to_i(16) : $1.to_i].pack('U') },
:time => e.last_updated
)
puts post
end
}
puts "-----page:#{page} (#{first}-#{last}) finished-----"
sleep 10 if page < last
end
if errors.size > 0
print "feed fetch error at page:"
puts errors.join(' ')
end
jsテスト
var radio = new Object();
radio.id = 1;
radio.channel = 15;
var led = new Object();
led.pin = 7;
led.state = false;
pinMode(led.pin, true); // 出力設定
nodes = new Array(16);
for(i = 1; i < nodes.length; i++){
nodes[i] = new Node(i);
}
radioInit(0xDEAD, radio.id, radio.channel, 31);
serialInit(9600);
for(i = 0; i < 6; i++){
pinMode(i, true); // pull-up
}
function Node(id){ // Node型
this.id = id;
this.led = true;
}
function loop() {
for(i = 0; i < 6; i++){
if(serialAvailable()){
recv = serialRead();
serial_parse(recv);
}
if(digitalRead(i)){
id = i+6;
node = nodes[id];
digitalWrite(led.pin, led.state = !led.state);
request = "id:" + node.id + ",led:";
if(node.led) request += "1";
else request += "0";
radioSend(0xFFFF, request);
serialSend(request+"\r\n");
sleep(50);
}
}
}
function serial_parse(data){
for(i = 0; i < data.length; i++){
c = data.charAt(i);
switch(c){
case "a":
nodes[6].led = false;
break;
case "b":
nodes[7].led = false;
break;
case "c":
nodes[8].led = false;
break;
case "d":
nodes[9].led = false;
break;
case "e":
nodes[10].led = false;
break;
case "f":
nodes[11].led = false;
break;
case "A":
nodes[6].led = true;
break;
case "B":
nodes[7].led = true;
break;
case "C":
nodes[8].led = true;
break;
case "D":
nodes[9].led = true;
break;
case "E":
nodes[10].led = true;
break;
case "F":
nodes[11].led = true;
break;
}
}
}
function sleep(count){
for(var i = 0; i < count*10; i++){
}
}
while(true){
loop();
}
function pinMode(pin_id, mode){
}
function digitalWrite(pin_id, state){
}
function digitalRead(pin_id){
}
function analogWrite(pin_id){
}
function analogRead(pin_id){
}
function soundWrite(value){
}
function radioInit(panID, deviceID, channel){
}
function radioConnect(){
}
function radioSend(){
}
function radioClose(){
}
function serialInit(baudRate){
}
function serialAvailable(){
}
function serialRead(){
}
function serialSend(message){
}
function debug(message){
}