Sunday, May 31, 2009
Hangul
FooSendアイディア
- 色のバラエティを使用頻度で変える
- 使用頻度に応じて使える機能や装飾を増やす
- 何かを出来るポイントを付与していく
- 貼り付け中の付箋をLIVE、剥がしたものをDEAD、トータルをTOTALとしてカウント表示する
Saturday, May 30, 2009
Travian game
Friday, May 29, 2009
FooSend
- 付箋のドラッグでの移動
- 付箋の整列(inline, cascade, random)
- 付箋のドロップでの削除
- flashによる通知
- ドロップ削除時のflash通知
- ウィンドウサイズを超える付箋の貼り付け時のフッター移動
- 整列のデフォルト設定
- 付箋編集
- 付箋の拡大
- 最新付箋のバウンス
- URLリンク
- YouTubeリンク
- ブックマークレット
- タグ付けおよびその絞り込み
Thursday, May 28, 2009
Sinatra::FooSend
- partialを定義して新規作成をmainに挿入
- session-flashを使ってnoticeを通知
- 直近5件を付箋とは別に表示
Wednesday, May 27, 2009
Heroku problem
Monday, May 25, 2009
プログラミングの目的
Sunday, May 24, 2009
Hangul
Hangul
Saturday, May 23, 2009
Sudoku
class Range
def each_combination
ary = self.to_a
ary.product(*[ary]*(ary.length-1)).each { |i| yield i }
end
end
solve = []
floor = (1..5)
floor.each_combination do |baker, cooper, fletcher, miller, smith|
next if [baker, cooper, fletcher, miller, smith].uniq!
next if baker.eql? 5
next if cooper.eql? 1
next if fletcher.eql? 1 or fletcher.eql? 5
next if miller < cooper
next if (smith - fletcher).abs.eql? 1
next if (fletcher - cooper).abs.eql? 1
solve << [baker, cooper, fletcher, miller, smith]
end
p solve
Friday, May 22, 2009
英辞郎mini
Thursday, May 21, 2009
jQuery子要素の指定の仕方
- $('.child_class', this)
- $(this).children('.child_class')
- $(this).find('.child_class')
Wednesday, May 20, 2009
Sinatra User認証で悩む
- beforeフィルタは各リクエストの前に実行されるので、ここで毎回ユーザ認証を行う
- つまりユーザのクッキーの値とユーザDBの認証IDを比較する
- メイン画面において、ユーザ認証前は入力・修正・削除ボックスが隠れており、認証により出現する
- 新規付箋作成時にはユーザ認証IDが各付箋に付けられる
- クッキーのユーザ認証IDと各付箋に付されたIDが比較され、一致するもののみが表示される
Hangul
Hangul
Tuesday, May 19, 2009
postmeその後
- Userクラスでユーザの名前とパスワードを管理
- PostクラスとUserクラスは多対多の関係
- つまり1ユーザに複数の付箋が結びつけられると同時に1つの付箋に複数のユーザが結びつけられるようにする
- これによって付箋の共有を可能にする
- 付箋が貼られる頁は全ユーザ共通の1つの頁とし、各ユーザには自分の付箋しか表示できないようにする
Monday, May 18, 2009
Sunday, May 17, 2009
postのコピーができた postme
document.onkeydown = function(e){
$(".post").draggable("disable");
};
document.onkeyup = function(e){
$(".post").draggable("enable");
};
Saturday, May 16, 2009
編集成功!postme
$("#edit_area").droppable({
over: function(){
size_effect(this, area_W, area_H*2);
},
drop: function(event, ui){
$(ui.draggable).fadeOut("slow");
var id = ui.draggable.attr("id").split('_')[1];
$.get('/'+id, function(data){
var data = $(data).find("#ed_area").text();
$("#edit_form").append("<form id='ed_form' action='/"+id+"' method='POST'><input type='hidden' name='_method' value='PUT'></input><textarea class='rounded {5px}' id='ed_area' name='edit_body' rows='6' cols='25' >"+data+"</textarea><br/><input id='edit_btn' type='submit', value='Edit'></input></form>");
});
$("#post_form").css("display", "none");
size_effect(this, area_W, area_H)
},
out: function(){
size_effect(this, area_W, area_H);
}
});
Thursday, May 14, 2009
postme
- 対象の付箋を編集エリアにドラッグ・ドロップする
- 編集エリアが編集フォームに切り替わって、そのテキストエリアには元の内容が入っている
- エディットボタンで編集完了
$.cookie("post_id", id);
location.href="/";
$("#edit_form").css("display", "inline");
var te = ui.draggable.find('.pbody').text()または.html()
$("#edit_area").text(te)
$("#edit_area").droppable({drop: function(event, ui){$(ui.draggable).fadeOut("fast");var id = ui.draggable.attr("id").split('_')[1];$.get('/'+id, function(data){$("#ed_area").text($(data).find("#ed_area").text());});$("#edit_form").css("display", "inline");}});
Wednesday, May 13, 2009
Hangul
Tuesday, May 12, 2009
単語帳アプリ
- 各付箋のテキストに単語とその訳を行を変えて入力
- 各行をリストとして扱い一方を表示他方を非表示
- クリックにより非表示の訳が現れる
- ドラッグ・ドロップで付箋自体を非表示
- 条件によって色分けとかソートとか
Monday, May 11, 2009
Hangul
Saturday, May 09, 2009
痔
Friday, May 08, 2009
Hangul
Postme
- inline templateをviews以下のファイルに分ける
- haml+Sassを使う
- inline jQueryをファイルにする
- redirect時に表示が崩れる
- jQueryファイル内でRubyオブジェクトにアクセスできない(Shakeで)
- 代替手段(javascript)がわからない(任意のDOMの選択方法)
Thursday, May 07, 2009
Hangul
Hangul
Wednesday, May 06, 2009
入力データのXSS対策
helpers do
include Rack::Utils
alias_method :h, :escape_html
end
<%=h somedata %>
submit onclick javascript
<p><input type="submit" value="Post" onclick="return confirm('post?')" ></p>
jQueryで非同期通信
- $.ajax, $.get, $.postが使える
- $.post('/delete/'+id, null, finction(){ location.reload() });などとする
- <a href=javascript:void(0) onclick="jQuery.post('/delete/<%= entry.id %>', null, function(){location.reload()})">delete</a>か
- <span onclick="jQuery.post('/delete/<%= entry.id %>', null, function(){location.reload()})">delete</span>などとする
- href=java..は何もしない印し
Tuesday, May 05, 2009
Post.rb
- RESTのDelete methodを発行するHTMLのdomがよくわからない。input type='hidden' name='_method'とかするようだけど、Sinatraではそんなこと必要ないって書いてある。
- Sinatraでlink_toとかどうすればいいのか
1 require "rubygems"
2 require "sinatra"
3 require "dm-core"
4 require "dm-validations"
5 require "dm-timestamps"
6
7 DataMapper.setup(:default, ENV['DATABASE_URL'] || "sqlite3://#{Dir.pwd}/post.sqlite3")
8
9 class Post
10 include DataMapper::Resource
11 property :id, Integer, :serial => true
12 property :body, String, :length => 1..200
13 property :created_at, DateTime
14 end
15
16 DataMapper.auto_upgrade!
17
18 get '/' do
19 @posts = Post.all
20 erb :index
21 end
22
23 post '/' do
24 @post = Post.new(:body => params[:post_body])
25 if @post.save
26 redirect "/"
27 else
28 redirect '/'
29 end
30 end
31
32 get '/:id' do |id|
33 @post = Post.get(id)
34 if @post
35 erb :show, :layout => false
36 else
37 redirect '/'
38 end
39 end
40
41 delete '/:id' do |id|
42 @post = Post.get(id)
43 if @post.destroy
44 redirect '/'
45 else
46 redirect '/#{id}'
47 end
48 end
49
50 __END__
51 @@layout
52 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
53 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
54 <html>
55 <head>
56 <meta http-equiv="Content-type" content="text/html; charset=utf-8">
57 <title>Post Me</title>
58 <style type="text/css" media="screen">
59 body { background:#eed;}
60 #input { float:left;}
61 .draggable { width:150px; height:80px; position:absolute; padding:3px 3px 3px 3px; color:#fff;}
62 #droppable { float:right; width:200px; height:120px; background:#999;}
63 #drop_text { color:#fff; padding:35px 83px;}
64 a#link_to_each { text-decoration:none;}
65 </style>
66 <script type="text/javascript" src="javascripts/jquery-1.3.2.min.js"></script>
67 <script type="text/javascript" src="javascripts/jquery-ui-1.7.1.custom.min.js"></script>
68 <script type="text/javascript" charset="utf-8">
69 $(function() {
70 $(".draggable").draggable({ });
71 $("#droppable").droppable({
72 drop: function(event, ui) { $(ui.draggable).remove(); }
73 });
74 $("#p_<%= @posts.last.id %>").effect("shake", { times: 4 }, 100)
75 });
76 </script>
77
78 </head>
79 <body>
80 <%= yield %>
81 </body>
82 </html>
83
84 @@index
85 <div id="input">
86 <form action="/" method="POST" accept-charset="utf-8">
87 <textarea name="post_body" rows="6" cols="25"></textarea><br/>
88 <p><input type="submit" value="Save"></p>
89 </form>
90 </div>
91 <div id="droppable">
92 <p id='drop_text'>Trash</p>
93 </div>
94
95 <div id="area">
96 <% @posts.each do |entry| %>
97 <div id="p_<%= entry.id %>" class='draggable' style="top:<%= 150+rand(20)*25 %>px; left:<%= 50+rand(40)*20 %>px; background:#<%= 500+rand(299) %>;">
98 <a id='link_to_each' href="/<%= entry.id %>">â– </a><%= entry.body.gsub(/\n/, "<br/>") %>
99 </div>
100 <% end %>
101 </div>
102
103 @@show
104 <div id="show">
105 <p id='id'><%= @post.id %></p>
106 <p id='body'><%= @post.body %></p>
107 <p id='time'><%= @post.created_at %></p>
108 </div>
109 <div id="delete">
110 <form action="/<%= @post.id %>" method="post" accept-charset="utf-8">
111 <input type="hidden" name="_method" value="delete">
112
113 <p><input type="submit" value="Delete"></p>
114 </form>
115 </div>
Sunday, May 03, 2009
Hangul
post_meがもう一歩
Sinatra+DataMapper+JQueryを使った実験として付箋アプリを作っている
- JQueryのDroppableを使ってドロップした付箋をremoveで非表示にできるが
- データベースから削除する方法がわからない
- 付箋のidの取得方法はわかったけど
1 require "rubygems"
2 require "sinatra"
3 require "dm-core"
4 require "dm-timestamps"
5 require "dm-validations"
6
7 DataMapper.setup(:default, ENV['DATABASE_URL'] || "sqlite3://#{Dir.pwd}/post_me.sqlite3")
8
9 class PostMe
10 include DataMapper::Resource
11
12 property :id, Integer, :serial => true
13 property :body, Text, :nullable => false
14 property :created_at, DateTime
15
16 validates_present :body
17 validates_length :body, :max => 200
18 end
19
20 DataMapper.auto_upgrade!
21
22 get '/' do
23 @posts = PostMe.all
24 erb :index
25 end
26
27 post '/' do
28 @post = PostMe.new(:body => params[:post_body])
29 if @post.save
30 redirect '/'
31 else
32 redirect '/'
33 end
34 end
35
36 __END__
37 @@layout
38
39 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
40 <html>
41 <head>
42 <meta http-equiv="Content-type" content="text/html; charset=utf-8">
43 <title>Post Metitle>
44 <style type="text/css" media="screen">
45 body { background:#eed;}
46 #new_post { float:left;}
47 .draggable { width:150px; height:80px; position:absolute; padding:3px 3px 3px 3px; color:#fff;}
48 #droppable { float:right; width:200px; height:120px; background:#999;}
49 #drop_text { color:#fff; padding-left:10px;}
50 #highlight { background:#b55;}
51 style>
52 <script type="text/javascript" src="javascripts/jquery-1.3.2.min.js">script>
53 <script type="text/javascript" src="javascripts/jquery-ui-1.7.1.custom.min.js">script>
54 <script type="text/javascript" charset="utf-8">
55 $(function() {
56 $(".draggable").draggable({ });
57 $("#droppable").droppable({
58 drop: function(event, ui) {
59 $(ui.draggable).hide();
60 var id = ui.draggable.attr("id").split('_')[1]
61 var ok = confirm("Item " + id + " delete?")
62 if (ok) { $(ui.draggable).remove(); }
63 else { $(ui.draggable).show(); }
64
65 // <% p response.ok? %>
66 }
67 });
68 $("#p_<%= @posts.last.id %>").effect("shake", { times: 4 }, 100)
69 });
70 script>
71 head>
72 <body>
73 <%= yield %>
74 body>
75 html>
76
77 @@index
78 <div id="new_post">
79 <form action="/" method="POST" accept-charset="utf-8">
80 <textarea name="post_body" rows="6" cols="25">textarea>
81 <p><input type="submit" value="Save">p>
82 form>
83 div>
84 <div id="droppable">
85 <p id='drop_text'>Trashp>
86 div>
87 <div id="posts">
88 <% @posts.each do |entry| %>
89 <div class="draggable" id="p_<%= entry.id %>" style="top:<%= 150+rand(20)*25 %>px; left:<%= 50+rand(40)*20 %>px; background:#<%= 500+rand(299) %>;"><%= entry.body.gsub(/\n/, "
") %>div>
90 <% end %>
91 div>
92 <p><%= @posts.length %>p>
93 <%= @posts.last.id %>