2008年10月8日星期三

十月的雨

国庆回了家,虽然是请假回去的。国庆于我意义不大,我似乎天天都在假期中,但回家就不一样了。我上大学后还没有在秋天回过家。以前到这个时候,我在校园里就会想家乡那边人们在忙什么,割麦子,起山药,拔菜籽,打苍蝇。这个时候已经有点冷了,人们穿着线衣,线裤,满脸堆笑的老农们,满脸堆笑的老农们站在晴朗的天空下拿着爬犁或者拿着铁锹或者其他什么工具,他们的手里总会拿着工具的。在早上阵阵的寒意里,在下午徐徐的暖风中。
但事实证明四年的时间让我的记忆出现了偏差,回家的前俩天天气好的很,接着俩天下起了雨。我没看到麦子,没看到老农,只看到了苍蝇,于是痛痛快快感受了一把当年一下打死七个的雄风。现在我们的小镇大不如从前景象,人走的越来越多,街道越来越破,今年很多人种了胡萝卜,但似乎收成也一般,只剩下苍蝇们还依旧生机盎然,成群结队。不对,还有漫街边巷的小狗,现在大家治安不靠狗了,那些个大饭量也大的big guy都换成了小毛犬,每天争斗于剩饭剩菜旁,make love于光天化日下,不避老幼男女。
行文至此,BTV6正在直播的“利物浦vs曼城”是高潮一波又一波,曼城上半场进了俩个,下半场由被扳回三个。这是红军的专长,所以利物浦球迷是幸福的。相比之下我们国米球迷气短了很多,荡气回肠的球很长时间与国米无关了。
这篇文章的题目是我很喜欢的俩首歌的结合,October, November Rain.



2008年9月22日星期一

JQuery: Drag Drop Sort

updated: add the html,

this is the html,


    <% @pages.each do |p| %>
  • ">
    <%= p.title %>
    <% if p.has_children? %>
      ">
      <% p.children.each do |c| %>
    • " class="sortable_submenu"><%= c.title %>

    • <% end -%>

    <% end -%>

  • <% end -%>


if you know the rails, it is easy :) .

--------------------------------------------------------------------------------------------------------------------------------

I need a "Drag Drop Sort " tree in my project. I found some jquery plugins, but all of them seems can't solve my problem, so I decided to solve it use JQuery UI.
All I need are 'jquery-ui-core', 'jquery-draggable', 'jquery-droppable','jquery-sortable',
these you can download from JQuery site.
Then some code like this:


$(".assets li").draggable({
helper: 'clone'
});
$(".drop").droppable({
accept: ".drag",
activeClass: 'droppable-active',
hoverClass: 'droppable-hover',
drop: function(ev, ui){
var drag = ui.draggable;
drag.appendTo($(this).siblings('ul.assets'))
$.ajax({
dataType: "script",
type: "PUT",
url: url,
data: "asset[category_id]=" + $(this).attr('id')
});
}
});
$("#sort").sortable({
items: '.sortable',
stop: function(e, ui){
var data = $(this).sortable("serialize")
$.ajax({
url: "/back/pages/sort",
type: "POST",
data: data,
dataType: "script"
});
}
});



The code is simple, there are some useful callbacks you can use, like start, stop, drop..., you can find them in the doc.

In the sort, this function "$(this).sortable("serialize") " will return the sort result.It works by default by looking at the id of each item in the format 'setname_number', and it spits out a hash like "setname[]=number&setname[]=number".

So do you think JQuery is amazing? Let's Rock!

2008年8月29日星期五

Add Paypal checkout for Spree

The RailsEnvy guys begin their own casts business---Envycast .They used the Spree to build the site, and allow customer checkout by Paypal.
Some days ago, I use Spree in a site.I think it's better than substruct,because it's more simple and extendable. I also needed to integrate Paypal to it, but some thing make me confused.
1) There are many ways to integrate Paypal, and many articles introduced these ways.First you need to know which way would you like to use? I used Website Payments Standard , if you don't use this way, this article maybe not help you.

2) For test it, you need signup a develop account,then use this account to create a buyer account, and a seller account.

3) When you test your application, you must login the develop account.

4) install the Spree Paypal extension , this extension isn't mature, but can be used.

5) change the extension's default account and some urls to your own

5)there are some html field the paypal server can accept, you need to find what you would like to use.

2008年8月22日星期五

rails crop image use paperclip and jquery

More and more sites begin to allow user to crop their avatar.
After some time google, I haven't found a easy way to implement this in rails use jquery and paperclip.
So I think maybe this article is helpful.

First I install a jquery plugin imaareaselect , it works well.

I add it in the view,
 
<% content_for :head do %>
<%= javascript_include_tag 'jquery-areaselect' %>
<% javascript_tag do -%>
$(window).load(function () { $('#duck').imgAreaSelect({ x1: 120, y1: 90, x2: 280, y2: 210, onSelectEnd: set_crop });
});
function set_crop(img, selection){
$('#crop_left').val(selection.x1)
$('#crop_top').val(selection.y1)
$('#crop_width').val(selection.width)
$('#crop_height').val(selection.height)
}
<% end -%>
<% end %>


and these lines in a form

 

<%= hidden_field_tag "crop_left", "0" %>


<%= hidden_field_tag "crop_top", "0" %>


<%= hidden_field_tag "crop_width", "1" %>


<%= hidden_field_tag "crop_height", "1" %>



<%= image_tag current_user.photo.url(:large), :id => "duck" %>


then I write some codes in a moudle, this is the file:


I will extract this as a paperclip extention later. In fact, you can this with prototype too.

2008年8月9日星期六

Todo on MAC

Im not a 'getting things done' fan,but sometimes TODO list is necessary.You know, the fun of TODO list is writing it, not implement it.
I found two useful tools on Mac, Tasks bundle of Textmate and evernote .

Tasks bundle is pretty simple, but useful. when you install the bundle, then it is there.
The Tasks grammar and commands by default apply to files with the .todo, .todolist and .tasks extensions.

There is a littel problem, the default hotkey use ⌅, which sometimes make you confused.
so I just changed it in the bundle editor, this is the easist way to fix this.For more info,you need to read the original article.

Evernote is another amazing software,it allows you to easily capture information in any environment using whatever device or platform you find most convenient, and makes this information accessible and searchable at any time, from anywhere.

when you find some useful pictures or web pages, Evernote is a great tool to store them and write some note for them.


2008年8月7日星期四

四年前

四年前的现在,我正在享受上学以来最悠长美妙的一个假期。我试图沿着残留的记忆追溯回去,但来时的路已然模糊。我只记得我们玩得很开心,在故乡的我们,很少会有压抑的时候。
四年过去了,我没有长高,也没有变胖,没有什么可以赢得掌声的事在我身上发生。幸好我不是那种不赢得聚光灯就无法快乐的人,我希望我可以享受自己的生活。享受不算健壮但还很是健康的身体,享受编程,每一次刷新浏览器看到新页面时的成就感,享受对音乐,对阅读,对体育活动的热爱,享受有限的全家人呆在一起的假期,享受总给我带来烦恼但总让我独自傻笑的木头,享受我的小黄猫(我知道我很对不起你),享受我家的小白狗和她的我未曾谋面的小黑狗孩子。享受我选择做自己的网站的勇气,我知道,也许我不会成功,但我想,带给你们一点我创造的东西。
我不知道我能不能让你们快乐,但我真的想那么做。

2008年8月2日星期六

下一个腾讯?

我接触电脑是从初中时开始。和大多同学一样,电脑游戏成了我的新大陆。到现在仍然念念不忘当年玩游戏的激情澎湃,感叹现在有了自己的电脑,但再无当初的热情了。
我接触网络是从初三开始。和大多同学一样,qq让我惊诧于网络的魅力。那时候我们以为聊qq就是上网的全部。
时至今日,我从事了互联网行业, 也可以拍着胸脯讲自己是半个互联网人了。我几乎天天都要上网,有比牛毛多的web2.的网站我也注册了比牛毛多的帐号。国外的网站界面大都很美观舒服,功能也有特别之处,我试着把他们介绍给我的同学,但大家似乎都不怎么感冒。我想原因很简单,因为上面没几个和我们有关的人。
如果你有机会去网吧看看,你会明白为什么你觉得很酷的网站用户很少的原因了。上网对大多数中国网民来说就是聊qq,六七年前是这样,六七年后似乎还是这样。当然大家多了一个选择叫网络游戏。这个情况让我失望了很长时间,我希望我们都能多一点geek精神,但这仅仅是个希望。
最近的一俩个月情况有点改变(多少有那么一点)。我突然发现我的同学们似乎都在使用一个网站,地球人都知道,我就不给出链接了。这个网站我是去年十月份注册的,那时候我的大学同学有一部分已经开始使用这个网站了,我不知道那个时候它的用户量是多大,但到了现在,我觉得可能它的用户量增长了能有一倍。因为我的高中,初中,甚至小学同学都开始现身了。衡量一个站点的影响力,可以去网吧观察,看人们在打开ie后第一个登录的网站是什么。我确实这样做了,我以我并不是完全善意的眼光去观察,发现有不少人开机后做了俩件事,一曰上qq,一曰上校内。
我不是说校内会成为下一个qq,但校内确实成为了qq之后又一个让你不能忽视的东西。不能忽视的意思就是你周围的大多数人都向你说起过这个东西,你感觉这的却是个时髦又有些用处的东西。我也不是说校内会不成为下一个qq,现在我们确实不像原来那样重视qq了。互联网越来越普及,人们的选择越来越多。几年前有几个人想到开网店,网上购物,到现在我的很多一直呆在县城里的同学都开始托我网上买点东西。腾讯也发布了自己的sns,但我们可以肯定它不会威胁到校内的。
我还想说的是中国的sns市场竞争是不已经结束了,真得没有机会去和校内扳手腕了?事实上这不是一个问题。互联网是一片充满奇迹的土地,任何成功在它实现以前都是一件不可能的事。如果你做一个网站总是要考虑已经有了那些‘大家伙’,你的网站该如何立足的话,那么你还不具有互联网的创业精神。
话说回来,什么样的sns可以和校内叫板?我自己认为,太酷的不行,功能太花哨的不行,没新意的不行。在中国互联网混,一定要有草根精神,明白用户真正需要的是什么,不能看了国外的酷站眼光就高了。也不能想当然,觉得这么好的功能一推出肯定火,事实上喜欢尝试新东西的人不多,而且你的新功能也许并没有你想象中的那么好。至于新意嘛,在一个已经有人做大了的市场里推出新产品,总是要有点不一样的东西,有个词叫做差异化竞争。你不能指望那些去网吧上网的人也和你一样有空申请那么多帐号只是为了进去看看是个什么网站。

最后表达一下我对豆瓣和土豆的敬意。他们坚持自己的东西,用优秀的产品,优秀的服务来吸引人,而不是用那些无聊,污染视觉的东西壮大声势。事实上,只要你的产品足够好,就不怕没人用。