小桑博客

如果渡不过这不可渡的海,将成为这海中捞不起的沙

便签做原型设计,要能往小了想

中午坐车,随手拾起便签,设计我的项目:

  • 分功能,每个功能1页面
  • 每个功能列出最多6项小列表
  • 每一步都有仔细,不然纸就不够用了

我们做项目的时候是假设有无限扩展的,只是想增加功能,而不是考虑成本或局限。我的偶得是给自己假定一个局限(这里是便签,以后可以考虑成时间,财力,人员,市场、、、),在局限中完成才是最实际的。

如果一个月做不完的项目就放弃吧!

自省录1,2,3

读后感

看《简笔画技法图谱》一书,简笔画是老少皆宜的东西,我从中看出来的所有事物都是一样,想做好,就要分析,观察,做草图,再细化。

与《精益创业》无差异

付费的人群归类

付费的人群归类

-> 发烧友,小孩,女人,别人,良心

  • 对于一些人,如90后,富二代中的各种极品来说,我归类为发烧友,其有冲动好玩阔绰炫富享乐的成分,只要他们敢兴趣就会付费

  • 小孩,国人父母都溺爱孩子,大部分自己省吃俭用,但对待孩子的教育却大方的很。

  • 女人,一个伤不起的群体,爱美是天性,25岁之后又为美而担心,于是乎手笔很大。

  • 礼下于别人,国人很令人不解的一点是,自己可以省吃俭用,对朋友,长辈,亲人,上级却可以大手大脚。礼是付费的一个大头,游戏早有此模式

  • 良心,若不重视知识产品,版权,谁也没办法啊

总结一句话,凡事还是要带给人价值,才是产品的真正价值。

红海和蓝海

做前无古人的事是需要勇气的 直面竞争也需要勇气

以前我觉得创造更容易成功

现在我觉得都一样,成功是件很复杂的事情

一个人应该善于面对竞争,竞争不是件坏事,说的俗点,没有对手你超谁去啊?没有对手就没有回档凌绝顶的感觉。 于竞争中发展,并找到机遇,这就是创新,一个良好的循环必然要以此长存。

学管理的时候学企业的生命周期,其寿命长度,我觉得是如此道理。

Ruby20周年聚会归来

ruby20年生日回来,最大的收获是听peter讲创业 我把我的想法和peter说了,他觉得很好,给出了几点建议

  • 确定是否有足够的热情,是否可以10年如一日的坚持下去
  • 不要一个人战斗
  • 开源非常好,与商业不冲突

真是听君一席话,胜读好几年书啊。我最近2年看了很多创业相关的书,但大部分都是教你怎么创业,如何想好的点子,如何经营,如何拿投资而已

成功并不是偶然的,坚持下去,找到自己喜欢的方向,这就足够了。

Rails 插件 Ancestry用法

简单总结一下用法 是对1.3版本做的

第一步增加gem

1
gem 'ancestry'

第二步对模型增加ancestry:string字段

1
2
3
bundle
rails g migration add_ancestry_to_messages ancestry:string
rake db:migrate

修改migration.rb

1
2
3
4
5
6
7
8
9
10
11
class AddAncestryToMessages < ActiveRecord::Migration
  def self.up
    add_column :messages, :ancestry, :string
    add_index :messages, :ancestry
  end

  def self.down
    remove_index :messages, :ancestry
    remove_column :messages, :ancestry
  end
end

第三步修改model

1
2
3
4
class Category < ActiveRecord::Base
  attr_accessible :desc, :name ,:parent
  has_ancestry
end

注意:增加:parent和has_ancestry 这步是别的教程里没有强调的

第四步 测试

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
require 'test_helper'

class CategoryTest < ActiveSupport::TestCase
  # test "the truth" do
  #   assert true
  # end

  test "dump category" do
    @b = Category.create! :name => 'bbbbb', :parent => Category.create!(:name => 'aaaaaaaaa')
    @d = Category.create! :name => 'dddddddd', :parent => @b
    @e = Category.create! :name => 'eeeeeee', :parent => @d
    @c = Category.find_by_name 'bbbbb'

    # ap @d
    # ap @d.parent
    # ap @d.root

    ap @d.subtree_ids
    # ap @c.parent


    # parent           Returns the parent of the record, nil for a root node
    # parent_id        Returns the id of the parent of the record, nil for a root node
    # root             Returns the root of the tree the record is in, self for a root node
    # root_id          Returns the id of the root of the tree the record is in
    # is_root?         Returns true if the record is a root node, false otherwise
    # ancestor_ids     Returns a list of ancestor ids, starting with the root id and ending with the parent id
    # ancestors        Scopes the model on ancestors of the record
    # path_ids         Returns a list the path ids, starting with the root id and ending with the node's own id
    # path             Scopes model on path records of the record
    # children         Scopes the model on children of the record
    # child_ids        Returns a list of child ids
    # has_children?    Returns true if the record has any children, false otherwise
    # is_childless?    Returns true is the record has no childen, false otherwise
    # siblings         Scopes the model on siblings of the record, the record itself is included
    # sibling_ids      Returns a list of sibling ids
    # has_siblings?    Returns true if the record's parent has more than one child
    # is_only_child?   Returns true if the record is the only child of its parent
    # descendants      Scopes the model on direct and indirect children of the record
    # descendant_ids   Returns a list of a descendant ids
    # subtree          Scopes the model on descendants and itself
    # subtree_ids      Returns a list of all ids in the record's subtree
    # depth            Return the depth of the node, root nodes are at depth 0
  end
end

说明:ap是awesome_print

在rails console中执行

rake test

需要什么方法尽可在官方的文档里找,整体看还比较完善

参考地址

  • https://github.com/stefankroes/ancestry
  • http://railscasts.com/episodes/262-trees-with-ancestry

随想

智利经济学家曼弗雷德·麦克斯-尼夫(Manfred Max-Neef)和他的同事们在他们1987出版的 “人类规模发展”一书中指出,人的基本需求可归为生存,安全,感情,理解,参与,休闲,创意,人格和自由九类。每一类又可按其状况(质量),获取(物质),操作(行动)及互动(环境)分项而形成36个单元。

  • 生存:创造,健康,食物,住所,技能,工作,反馈
  • 保护:安全,社会
  • 感情:友谊,家庭,爱
  • 认识:好奇心,教育
  • 参与:责任,相互交往,社会活动
  • 休闲:玩耍,幻想,性,隐私
  • 创造:技能,工作,反馈
  • 身份:财产,团体,认可
  • 自由:人身自由,权利,异议

其实最近1年多,我都是在去想做一些事情,想做的事情很多而做成的事却很少,非我欲望或想法过多,而是年龄长彼事成而心有不甘。

诗歌之美其一是思,其二为幻,当此道,反复锤炼方有成。我去年很少写东西,失去了很多可以胡思乱想的机会,现在想想真是有些不该,假设每天都花上15分钟胡乱的想想,是浪费时间呢,还是算休息? 当一件事情形成习惯,才有威力,而一直奔跑的人看不到风景,于悖论中感到悲哀,生之无奈啊

换个角度,换一个思路,看不一样的书,发呆,洗衣做饭,或者泡一杯好喝的咖啡,这些琐碎的细节无不冲淡了一些本该有的节奏。曲子要不同调,饭菜要有咸淡之分。

近日读书《番茄工作法》,其核心在于每25分钟做一次休息,在一个番茄钟内尽力工作,完成之后必定休息5到10分钟,一定不做与工作相关的事情。其核心仍是俗的不能再俗的“可持续发展”。

《the lean startup》一书将从最小的可用原型开始,《敏捷武士》一书将需求切分为user story,其粒度可以尽量细,是不是一个番茄钟25分钟呢?此为戏言,但这些东西若组合到一起,相信对未来的工作方式是有一定改进的。

人生在勤,不索何获,路慢慢其修远兮!

无处不在的pry

http://lucapette.com/pry/pry-everywhere/

Pry Everywhere

about a year ago in pry I have to confess that I’m generally skeptical about alternatives for tools that work so fine like IRB. And I really like IRB. So why Pry? And why everywhere? Because Pry features blew my mind. When I wrote about IRB customization, I was doing what I always do when I like a tool: customize it in order to feel the tools more familiar with my way of thinking. So, when I run into Pry, some of its features blew my mind because they were exactly what I really would like to have in IRB. For example, sometimes you would like to explore a class or an object quickly. The way you can do it with Pry feels just natural. It just seems the right way too do it:

1.9.2 (main):0 > cd Array
1.9.2 (Array):1 > ls -m
[:[], :allocate, :new, :superclass, :toy, :try_convert, :yaml_tag]
1.9.2 (Array):1 > show-
show-command  show-doc      show-input    show-method   show-source
1.9.2 (Array):1 > show-method toy

From: /home/lucapette/.pryrc @ line 15:
Number of lines: 3

def self.toy(n=10, &block)
  block_given? ? Array.new(n,&block) : Array.new(n) {|i| i+1}
end

Toy is a little method I have in my .pryrc (and previously in my .irbrc) that I use when I want to play with arrays. Pry comes with wonderful commands like cd that operates both with classes and instance objects or like ls that you can use to list all the class methods (-m option) or instance methods (-M option). And a very long list of other terrific features as editor integration, shell integration or gist integration. But I don’t need to persuade you to use Pry because I’m sure you will use it after taking a look at these wonderful resources.

So the title of this post is “Pry everywhere” and now I’m going to show you quickly what I’ve done to migrate to Pry. There are a lot of solutions about this topic but all of them involve something I don’t like especially about rails integration. My requirements were fairly simple:

  • I don’t want to lose the customizations I’ve done with IRB
  • The same for rails console
  • I don’t want to add any gem (although this is very nicely done) to my Gemfile in rails projects.

After a bit of researching, I came up with the following solution:

My current .irbrc:

# https://github.com/carlhuda/bundler/issues/183#issuecomment-1149953
if defined?(::Bundler)
  global_gemset = ENV['GEM_PATH'].split(':').grep(/ruby.*@global/).first
  if global_gemset
    all_global_gem_paths = Dir.glob("#{global_gemset}/gems/*")
    all_global_gem_paths.each do |p|
      gem_path = "#{p}/lib"
      $LOAD_PATH << gem_path
    end
  end
end
# Use Pry everywhere
require "rubygems"
require 'pry'
Pry.start
exit

Pratically, everytime I start IRB I will start a Pry session. It feels like a dirty solutions and I have to confess I don’t know if it has any issues. For now, it’s working just fine with my requirements. The bundler code is necessary to require pry and other gems from rvm global gemset in a rails console without declaring them in the Gemfile. Then, in the .pryrc I have:

code in .pryrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# vim FTW
Pry.config.editor = "gvim --nofork"

# My pry is polite
Pry.hooks = { :after_session => proc { puts "bye-bye" } }

# Prompt with ruby version
Pry.prompt = [proc { |obj, nest_level| "#{RUBY_VERSION} (#{obj}):#{nest_level} > " }, proc { |obj, nest_level| "#{RUBY_VERSION} (#{obj}):#{nest_level} * " }]

%w{map_by_method hirb}.each { |gem| require gem }

# Toys methods
# Stealed from https://gist.github.com/807492
class Array
  def self.toy(n=10, &block)
    block_given? ? Array.new(n,&block) : Array.new(n) {|i| i+1}
  end
end

class Hash
  def self.toy(n=10)
    Hash[Array.toy(n).zip(Array.toy(n){|c| (96+(c+1)).chr})]
  end
end

# loading rails configuration if it is running as a rails console
load File.dirname(__FILE__) + '/.railsrc' if defined?(Rails) && Rails.env

If you compare this file with my previous .irbrc you’ll notice that this one is shorter. This means that Pry is doing a piece of the job I would like to have by default, like colors and history commands. My .railsrc is very similar to the previous one but it has a different that could interest you if you are an hirb user:

# https://github.com/cldwalker/hirb/issues/46#issuecomment-1870823
Pry.config.print = proc do |output, value|
  Hirb::View.view_or_page_output(value) || Pry::DEFAULT_PRINT.call(output, value)
end

Hirb.enable

In this way, Hirb is working flawlessly. And the combination of Rails and Pry is just fantastic. Give it a try. I have been able to migrate to Pry with a fair effort, hoping this kind of configuration can help you too!