作者归档:船长

ruby中10进制和16进制的转换

16进制到10进制:
>> "B0A0".hex
=> 45216

>> "B0A0".to_i(16)
=> 45216
10进制到16进制:
>> 45216.to_s(16)
=> "b0a0"

发表在 Ruby on Rails | 留下评论

My collection of QUOTES

I have not failed. I’ve just found 10,000 ways that won’t work.
  – Thomas A. Edison

Look for the ridiculous in everything and you will find it.
  – Jules Renard

Failure is not the only punishment for laziness; there is also the success of others.
  – Jules Renard

There is no excellent beauty that hath not some strangeness in the proportion.
  – Sir Francis Bacon

When you look at yourself from a universal standpoint, something inside always reminds or informs you that there are bigger and better things to worry about.
  – Albert Einstein

Character is what you have left when you’ve lost everything you can lose.
  – Evan Esar

A goal is a dream with a deadline.

The time to stop talking is when the other person nods his head affirmatively but says nothing.
  – Henry S. Haskins

Efficiency is intelligent laziness.
  – Anonymous

The public is wonderfully tolerant. It forgives everything except genius.
  – Oscar Wilde

I’m kind of jealous of the life I’m supposedly leading.
  – Zach Braff
 
Nothing is as simple as we hope it will be.
  – Jim Horning
 
If the human mind was simple enough to understand, we’d be too simple to understand it.
  – Emerson Pugh
 
  An intellectual is a person who has discovered something more interesting than sex.
  – Aldous Huxley

Education is the ability to listen to almost anything without losing your temper or your self-confidence.
  – Robert Frost
 
The only paradise is paradise lost.
  – Marcel Proust

Laughter and tears are both responses to frustration and exhaustion. I myself prefer to laugh, since there is less cleaning up to do afterward.
  – Kurt Vonnegut

Happiness is not achieved by the conscious pursuit of happiness; it is generally the by-product of other activities.
  – Aldous Huxley

There is still a difference between something and nothing, but it is purely geometrical and there is nothing behind the geometry.
  – Martin Gardner

You can only be young once. But you can always be immature.
  – Dave Barry

A large income is the best recipe for happiness I ever heard of.
  – Jane Austen

A door is what a dog is perpetually on the wrong side of.
  – Ogden Nash

Laugh and the world laughs with you, snore and you sleep alone.
  – Anthony Burgess

It’s never just a game when you’re winning.
  – George Carlin

Never be afraid to laugh at yourself, after all, you could be missing out on the joke of the century.
  – Dame Edna Everage

All work and no play makes Jack a dull boy and Jill a rich widow.
  – Evan Esar

What if nothing exists and we’re all in somebody’s dream? Or what’s worse, what if only that fat guy in the third row exists?
  – Woody Allen

You will do foolish things, but do this with enthusiasm.
    -Collete

Two roads diverged in a wood, and I–/ I took the one less traveled by, / And that has made all the difference.
  – Robert Frost

Against logic there is no armor like ignorance.
  – Laurence J. Peter

It is not the strongest of the species that survives, nor the most intelligent, but those most adaptive to change.
Charles Darwin

You must be the change you want to see in the world. -Gandhi

"It’s better to be a pirate than join the navy."
Steve Jobs

Laughter is the closest distance between two people.
  – Victor Borge
 
Some have been thought brave because they were afraid to run away.
  – Thomas Fuller

By the time a man realizes that maybe his father was right, he usually has a son who thinks he’s wrong.
  – Charles Wadsworth

The trouble with being poor is that it takes up all of your time.
  – Willem de Kooning

The trouble about trying to make yourself stupider than you really are is that you very often succeed.
  – CS Lewis

At my lemonade stand I used to give the first glass away free and charge five dollars for the second glass. The refill contained the antidote.
  – Emo Phillips

Most turkeys taste better the day after; my mother’s tasted better the day before.
  – Rita Rudner

Men live in a fantasy world. I know this because I am one, and I actually receive my mail there.
  – Scott Adams

Happiness makes up in height for what it lacks in length.
  – Robert Frost

You probably wouldn’t worry about what people think of you if you could know how seldom they do.
- Olin Miller

“敢问夫子恶乎长?”曰:“我知言,我善养吾浩然之气。”
“敢问何谓浩然之气?”
曰:“难言也。其为气也,至大至刚,以直养而无害,则塞于天地之间。…”
《孟子·公孙丑上》

A man can be happy with any woman as long as he does not love her.
  – Oscar Wilde

When a thing has been said and well, have no scruple. Take it and copy it.
- Anatole France

It is always the best policy to speak the truth–unless, of course, you are an exceptionally good liar.
  – Jerome K. Jerome

Many a man who falls in love with a dimple make the mistake of marrying the whole girl.
  – Evan Esar

A wise man will make more opportunities than he finds.
  – Sir Francis Bacon

The important thing is not to stop questioning.
  – Albert Einstein

Any word you have to hunt for in a thesaurus is the wrong word. There are no exceptions to this rule.
  – Stephen King

You have to know how to accept rejection and reject acceptance.
  – Ray Bradbury

Education is a method whereby one acquires a higher grade of prejudices.
  – Laurence J. Peter

The nine most terrifying words in the English language are, ‘I’m from the government and I’m here to help.’
  – Ronald Reagan

The key to being a good manager is keeping the people who hate me away from those who are still undecided.
  – Casey Stengel

The important work of moving the world forward does not wait to be done by perfect men.
  – George Eliot

Nothing succeeds like the appearance of success.
  – Christopher Lasch

Always get married early in the morning. That way, if it doesn’t work out, you haven’t wasted a whole day.
  – Mickey Rooney

发表在 成败几何, 我思我在 | 留下评论

闻王昌龄左迁龙标遥有此寄 李白

杨花落尽子规啼, 闻道龙标过五溪.
我寄愁心与明月, 随君直到夜朗西.

发表在 诗词精选 | 留下评论

次北固山下 唐 王湾

客路青山外, 行舟绿水前.
潮平两岸阔, 风下一帆悬.
海日生殘夜, 江春入旧年.
乡书何处达? 归雁洛阳边.

发表在 诗词精选 | 一条评论

Ruby中如何复制对象 (deep clone)

用Ruby复制一个对象(object)也许没有你想像的那么容易. 今天我google了半天, 做个总结吧.
先从最简单的开始, b = a 是复制吗? 看代码说话:
>> a= [0,[1,2]]
>> b=a
>> b[0]=88
>> b[1][0]=99
>> b 
=> [88, [99, 2]]
>> a 
=> [88, [99, 2]]
从上面代码发现, 一但修改b, 原来的a也同时被改变了. 甚至:

>> b.equal?(a)
=> true
原来b跟a根本就是同一个object, 只是马甲不一样罢了. 所以b = a不是复制.
那 b = a.dup呢?? 还是看代码:
>> a= [0,[1,2]]
>> b=a.dup
>> b[0]=88
>> b[1][0]=99
>> b
=> [88, [99, 2]]
>> a
=> [0, [99, 2]]
情况似乎有所好转, 在修改b后, a还是有一部分被修改了.(0没有变,但原来的1变成了99).
所以dup有时候是复制(如在Array只有一级时), 但有时不是复制哦.
再来一个, b = a.clone呢? 上代码:
>> a= [0,[1,2]]
>> b=a.clone
>> b[0]=88
>> b[1][0]=99
>> b
=> [88, [99, 2]]
>> a
=> [0, [99, 2]]
情况几乎跟dup一模一样. 所以clone也不一定可以相信哦!
原来ruby中的dup和clone都是shallow复制, 只针对object的第一级属性.
汗, 难道在Ruby中没有办法复制对像吗? 也不完全是, 看这个:
>> a= [0,[1,2]]
>> b=Marshal.load(Marshal.dump(a))
>> b[0]=88
>> b[1][0]=99
>> b
=> [88, [99, 2]]
>> a= [0,[1,2]]
=> [0, [1, 2]]
修改b后a没有被改变!!! 似乎终于成功找到复制的办法了!!!
为什么要加"似乎"呢? 因为有些object是不能被Marshal.dump的.如:
>> t=Object.new
>> def t.test; puts ‘test’ end
>> Marshal.dump(t)
TypeError: singleton can’t be dumped
    from (irb):59:in `dump’
    from (irb):59
更完善的复制方案可以考虑给ruby增加一个deep clone功能, 可以参考以下链接:
http://d.hatena.ne.jp/pegacorn/20070417/1176817721
http://www.artima.com/forums/flat.jsp?forum=123&thread=40913
好了, 复制这个小问题, 没想到也能引出这么长的文章来, 没想到吧?

发表在 Ruby on Rails | 留下评论

CR, LF, CR/LF 回车 换行

在文本处理中, CR, LF, CR/LF是不同操作系统上使用的换行符.
Dos和windows采用回车+换行CR/LF表示下一行,
而UNIX/Linux采用换行符LF表示下一行,
苹果机(MAC OS系统)则采用回车符CR表示下一行.
CR用符号’\r’表示, 十进制ASCII代码是13, 十六进制代码为0x0D;
LF使用’\n’符号表示, ASCII代码是10, 十六制为0x0A.
所以Windows平台上换行在文本文件中是使用 0d 0a 两个字节表示, 而UNIX和苹果平台上换行则是使用0a或0d一个字节表示.
一般操作系统上的运行库会自动决定文本文件的换行格式. 如一个程序在windows上运行就生成CR/LF换行格式的文本文件,而在Linux上运行就生成LF格式换行的文本文件.
在一个平台上使用另一种换行符的文件文件可能会带来意想不到的问题, 特别是在编辑程序代码时. 有时候代码在编辑器中显示正常, 但在编辑时却会因为换行符问题而出错.
很多文本/代码编辑器带有换行符转换功能, 使用这个功能可以将文本文件中的换行符在不同格式单互换.
在不同平台间使用FTP软件传送文件时, 在ascii文本模式传输模式下, 一些FTP客户端程序会自动对换行格式进行转换. 经过这种传输的文件字节数可能会发生变化. 如果你不想ftp修改原文件, 可以使用bin模式(二进制模式)传输文本.

发表在 信息处理 | 4 条评论

中国大学信息库

蜘蛛网增加了中国大学信息库. 目前为止收录了近3000家国内大学/学院/职业学院的信息, 应该是网上最全的了. 每个学院的信息包含概况, 专业设置, 联系电话email网址等. 个人最喜欢的是里面的校园风光图片. 信息库还带了学校的电子地图, 不过有时候地图会不准, 因为有些学校地址信息不全, 而有些学校呢有好几个校区, 只选出了一个, 所以只能做个参考. 同时蜘蛛网新增加的还有大学专业百科. 里面有各大学专业课程的介绍, 如主要课程, 就业方向等, 还有带有开设本专业的大学列表. 相信这些功能对即将择校的高考生时帮助最大.

发表在 信息处理 | 留下评论

Google地图API key和127.0.0.1

前几天在本地服务器测试Google地图的API时发现google报错, 说这个key不能使用. google了一下, 在一个外国论坛发现原来可以为http://127.0.0.1/单独申请一个key, 专用于本地测试使用. 于是马上效仿, 测试通过.

发表在 站长文档 | 2 条评论

全部链接在新窗口中打开

上网提速入口中有很多站外链接, 要让这些链接都在浏览器新窗口中打开, 可以在每个<a>tag中加入target="_blank"标识, 但如果链接很多, 就会有非常大量的重复代码. 其实可以在head中加入<base target="_blank"> tag,让页面内所有链接(包括form提交)都指向新的浏览器窗口, 让代码更加简洁.

发表在 站长文档 | 一条评论

蜘蛛网在线汉语字典使用方法

查找找一个汉字的读音或意思? 试试蜘蛛网在线汉语字典吧!
蜘蛛网在线汉语字典提供了多种查询方法:
其中的拼音索引, 偏旁部首索引, 按汉字笔画索引是三种比较传统的查字典办法, 但在汉语字典三种索引任意组合使用相信是蜘蛛网的首创, 使用这个组合索引, 你可以找出所有笔画数为8并且读音为ban的汉字.
另一个蜘蛛网推出的新字典功能是”全文索引”.  有了这个功能, 网友可以通过汉字的读音, 注音, 五笔编码, 郑码, GBK, UNICODE代码,甚至汉字注解中的词语搜索到所寻找的汉字的.
当然, 在蜘蛛网在线汉语字典中查询汉字的最简便方法是把待查汉字直接加到 http://www.weeeeb.com/w/后面直接打开. 如打 http://www.weeeeb.com/w/龘 就可以知道”龘”这个字典中笔画数最多的汉字的意思和读音了.

发表在 信息处理 | 留下评论