Total Pageviews

Saturday 30 November 2013

WoW Next 0.1.3-安全 方便 快捷 一键科学上网

http://wowlegacy.ml/
下载地址:http://pan.baidu.com/s/11l3fi


全新的软件,具有超乎 Chrome Sync 的神级同步配置能力。
请 XP 和 Windows 7 用户在使用前务必下载 .NET Framework 4.0 并进行安装。

中国人其实不了解日本

作者:信力建
中国近代,面临“千年未遇之大变局”,若要问在这千年大变局中哪一个国家对我们影响最大,恐怕非我们的近邻日本莫属。这原因除了地缘上我们都属于东亚国家外,更因为在文化上我们有许多的共同性的同时,又有那么对水火难容的不同,也因此造成了那么多的冲突纠结与伤痕。
首先当然是战争。近代中日爆发过两次大战,而这两次大战都给中国社会造成极大影响,其余痛至今犹存。第一次中日战争发生于1894年~1895年 中国和日本之间的战争,史称甲午战争。这次战争对中国而言无疑影响是负面的,具体说来,甲午战争是帝国主义的候选国——中国与日本的命运决定战,战胜国日 本加入了帝国主义阵营的末班车,成为亚洲唯一晋升帝国主义之国家;战败国中国转为半殖民地的地位,变成列强争夺利权的一块肥肉。日本在一八九八年五月得到 的赔偿有:军费赔偿二亿两、威海卫守备军费三年份一百五十万两、辽东半岛退还补偿三千万两,合计二亿三千一百五十万两。中国在甲午战争时岁计不到一亿两, 战费和募集内债都不成,只好向英德借外债六百六十三万余英镑。战败后对对巨额的赔偿更形无力,只好再更依赖外债。此外,甲午战争的赔款除了使日本除了工业 化、扩张军备,并建立金本位制之外,在市场与关税方面日本也获得极大好处。所以甲午战争其实是帮助日本现代化,助长了日国内轻工业 的发展,造成日本第一次产业革命。而与此同时,中国则自此堕入半殖民地位,五年之内面临被瓜分命运。包括:俄国租旅顺、大连,德国占领胶州湾,法国占领广 州湾,英国占领威海卫及九龙半岛。日本则因为三国干涉还辽而进入对俄十年准备战争,一九○二年英日同盟成立,打破“满韩交换” ,一九○四年对俄宣战,最后因日俄战争成功而取得满州。
还值得一提的是,甲午战争的失败不仅直接导致了中国的戊戌变法,而且在此后的留日风潮中,大量留日学生的出现还为清王朝的灭亡准备了掘墓人。从 1896年起,大量中国学生涌入日本学习,仅1906年就有大约8,600人。这样大的数字,是到当时为止世界史上规模最大的留学运动。有趣的是,大部分 留日学生的目的不是学习日本文化,而是学习西洋文化。或者叫,学习日本人学习西洋文化的方法,当然也包括从日本转手得到的,已经打上浓厚的日本色彩的西方 知识。这些留学生集中了中国的有志之士和少年才俊,赴日本寻找科学救国、教育救国、文学救国、军事救国……,乃至改良和革命的方略。他们中有章太炎、陈天 华、邹容、黄兴、蔡锷、宋教仁、汪精卫、蒋介石、陈独秀、李大钊、周恩来、鲁迅、周作人、郭沫若、郁达夫、李叔同、胡风、周扬、田汉、夏衍、欧阳予 倩,……。辛亥革命的先驱,国民党的绝大部分元老,共产党创始人“南陈北李”,三分之一的中共一大代表(李达、李汉俊、周佛海、董必武),都曾东渡日本留 学。可以说,甲午战争不仅在军事上打败了满清王朝,也在政治上打垮了满清王朝。
第二次中日战争发生于1937年~1945年 二战期间中国与日本之间的战争,史称抗日战争。此次战争对中国的现代化进程也发生过重要影响。具体说来,就是日本这次侵华战争打断了中国原有的现代化进 程。如果说甲午战争已经表明日本的侵略对中国的现代化进程产生了重大影响,那么到了20世纪30年代,日本对中国发起的全面侵略战争,则完全地打断了中国 原有的现代化进程。在抗日战争爆发前的10年里,中国现代化工业每年的平均增长率约为7.6%,而且这种增长突出地表现在基础工业上 ,1936年资本主义生产已占工业总产值的65%,占工农业总产值的24.48%。 假设没有日本对中国的侵略,中国的工业化步伐必将大大加快。这日本对中国的侵略,彻底地打断了中国原有的现代化进程。先是日本对中国东北的占领,使中国丧 失了1/3的森林、铁矿和煤矿;4/10的铁路;7/10的大豆产量;2/5的出口贸易;以及93%的石油;55%的黄金。 另据统计,至1932年底,中国政府在东北的损失达178亿元,加上私人损失,不下200亿元。 在全面侵华的8年间,日本占领了中国城市总数的47%以上,其中包括大城市的80%以上。这些城市聚集着中国几乎全部的现代化工业。这些工业,有的直接损 毁于炮火之中,有的因战争而失去运转的条件导致关闭,有的被迫内迁损毁于途中。在沦陷区,日军不仅任意掠夺公私财产,还截留税收,把持金融,并建立起依附 于日本的以掠夺中国资源财富为目标的殖民地经济体系。据1995年中国政府公布的数字,中国在抗日战争中的直接财产损失是1000亿美元,间接损失是 5000亿美元。对于一个本来就十分贫穷的中国来说,上述战争损失不仅使中国原有的现代化进程难以为继,还足以使它的经济全面崩溃。
有意思的是在这场战争中,双方将领中许多都有在日本军校学习的历史。日方就不用说了,便是国民党方面国军将领中,留日群体也最为最庞大。自晚清到民 国二十五年,进入日本陆军士官学校学习的中国留学生就达到1500人以上,还有大量在候补阶段就退学的学生,比如最有名军委会委员长蒋介石、参谋总长何应 钦、二战区司令长官阎锡山、一战区司令长官程潜、蒋介石侍卫长钱大均,军事教育家蒋方震等等。此外,还有一批曾留学于日军兵种教育学校(日军称之为实施学 校)的军官,如刘斐、宋希濂等,以及在日本上过陆军大学的将领,如黄慕松、陈仪、朱绶光等。
还值得一提的是,在其后对中国影响至深的所谓解放战争中,日本在东北地区遗留的大量日式武器以及数以十万计训练有素的伪军,最终成为林彪在东北坐大,并会师南下的资本。
其次是思潮。甲午战争后,中国知识界意识到原先的“蕞尔小国”的日本,在现代化道路上已经远远走在了原本是它文化母国的中国前面,于是,承认风水轮 流转,赶紧向日本学习。日本书籍的翻译也随之进入高潮。民国建立前十五年间,共有956本日文书译成汉文;同一时间内,日本从汉文译过去的书只有16本; 民国成立后十五年间,日译汉的书有1,759本。日文以汉字构成,大量译书尤其是翻译教科书刊行中国,对文化和教育的影响可想而知。就拿近代对中国影响最 为深刻广泛的马克思主义而言,中国人正式接受的马克思主义,是经由日本中转的。德国汉学家李博教授在其《汉语中的马克思主义术语的起源与作用》一书中特别 指出,五四时期“中国人对欧洲各社会主义流派的了解,包括对马克思、恩格斯创立的社会主义学说的了解几乎全部来自日语,或是欧洲语言原著的日文翻译,或是 日语的社会主义著作。”对此,郭沫若后来的回忆也强调了这点,他说:“中国民众是从通过日语书籍介绍马克思和恩格斯的中国记者那里听说了马克思和恩格斯。 这些书被译成了汉语,于是人们知道了马克思和恩格斯的存在。如果查阅一下文献资料,同样可以得出这一饶有兴趣的结论,即最先介绍马克思主义的是日本知识分 子。我本人是在河上肇的书时了解了一点关于马克思的东西。”中国人早期接触马克思主义同日本刚刚兴起的社会主义运动有重要关系。当时在日本留学的中国知识 分子,在这种思潮的影响下,翻译了一些马克思、恩格斯的著作,并通过自己出版的刊物进行介绍。属于翻译性介绍,中国先进分子充当了先锋。另外,中国新文化 运动的主要内容之一,是白话文运动,而它的前身“文言合一”运动,则源于明治时代的日本。前面说到的大量新名词,实际上也就是吸收了日本的这一文化资源, 对于中国文体的演变,发挥了直接的作用。中国的新小说、新诗、新戏剧,也都受益于日本文学的启迪。郭沫若的第一本诗集《女神》在日本写成;郁达夫的《沉 沦》看得出日本私小说的印痕;周作人的散文明显带有日本茶道的形式之美;鲁迅的杂文里总有一个黑黑瘦瘦的影子,那就是藤野先生。
最后是经济。两次中日战争拖垮了中国经济,延缓了中国现代化进程,这是不争的事实。然而,在改革开放三十多年以来中国现代化建设时期,也正是日本给 了中国最大的经济援助,这也是客观存在的事实。据统计1979年至今,中国共获得日本约2248亿元人民币的开发贷款以及各种形式的技术合作和无偿援助, 特殊的历史原因以及复杂的民族情感,使这个规模巨大的援助行动并不为大多数中国人所知。1970年代末,中国改革之初,缺少大量资金,当时的世界对中国还 缺乏明确感。那时,日本是第一个支持中国的国家。不管是对放弃战争赔款的善意感谢,还是中日贸易的客观需求,日本对华开发援助成为早期中日关系改善的一个 象征,也为中国早期的基础设施建设作出了重大贡献。1989年之后,日本也是第一个恢复对华援助的国家。从1997年到2001年,日元对华贷款进入了高 峰期,2001年达到2144亿日元(约142亿元人民币)的峰值。与中国经济发展的脉搏跳动相一致,30年间,日本对华援助从沿海到内地,几乎涉及中国 发展的各个领域——从中国早期的能源、运输等基础建设,到农业项目,再到环保、人才培养。迄今在国内已有200多个项目。除日元贷款之外,在中日关系风风 雨雨的30年间,日本通过派遣海外协力队、年长志愿者等方式,为中国提供大批志愿者、专家,遍布中国的文化、教育、卫生、环保等领域。曾经因历史问题水火 不容的两国,因为援助,在扶贫、传染病防治、水资源利用等领域搭起了交流的平台。30年后,2007年日本与中国双边贸易额达到2630亿美元,中国也首 次超过美国成为日本第一大贸易伙伴。2008年3月,日本最后一次向中国提供日元贷款后,日本对华贷款即将结束,不过日本的对华援助还将存在。“雪中送 炭”如同干涸的大地,经历动荡岁月的中国需求大笔基础建设资金。日元贷款对于当时的中国来说,可谓雪中送炭。日元对华开发援助的总额在1994年占到中国 GDP的0.29%。正如中国社科院日本研究所副所长金熙德所言“必须看到,在中国经济的起飞过程中,日本对华贷款为中国的基础设施建设作出了重大贡 献。”
遗憾的是,对这样一个对我们影响甚深,甚至改变了我们国家命运的国度,我们却知之甚少。甲午海战后,虽然留日学生如过江之鲫,但为人们所常常称道的 研究成果只有黄遵宪的《日本国志》等寥寥数种。非但如此,两本“旧书”———初版于1928年的戴季陶的《日本论》,以及初版于1946年美国学者本尼迪 克特的《菊与刀》,在2005年仍然颇为畅销。不仅仅是这两本书写得不错之故,更由于这么多年来,在日本民族性的研究方面,尚未出现超越性的扛鼎之作。与 此同时,日本对中国问题的研究,却非常重视,往往“国家总动员”。在日本,学术界10000多人研究中国,例如史学界,日本研究中国史学的学者分的很细宋 史、明史、清史学会都各有几百名专家,日本人口少你想想他们的一亿多人口与我们的十三亿人口来比这10000名学者在中国应该是多少呢?!事实上,中国真 正研究日本问题的专家也许还不到1000人。解放前,尚有诸如周作人、钱稻孙这样真正精通日本文化的学者,现在却一个也没有。日本看我们是透明,我们看日 本是铁幕。  
70多年前,戴季陶在《日本论》中有这样一番话:“我劝中国人,从今以后,要切切实实的下一个研究日本的工夫。……要晓得他的过去如何,方才晓得他的现在是从哪里来的。晓得他现在的真相,方才能够推测他将来的趋向是怎样的。”这话至今听来,仍发人深省。

美国学生的数学为什么差?

美国著名的政治讽刺网站“洋葱”今年二月刊出一篇煞有介事的“报道”,题目是“中国小学三年级学生的数学和科学成绩落后于美国高中生!”
“报道”说,根据“国际教育评估协会”在麻州核桃山发表的最新报告,中国小学三年级学生的数学和科学成绩开始落后于美国高中生。该“报告”是基于最新一项包括了63个国家的统一测验,其结果显示中国8岁学生的成绩稍稍落后于美国14岁到18岁的学生。
“对于中国这是一个警示信号。”该“协会”的发言人说。“很简单,如果他们小学三年级学生受到的教育只相当于美国的高中教育,将来他们怎么可能在全 球化的市场竞争中占优呢?”“报道”进一步说:除了中国,日本、韩国、德国、瑞士,和新几内亚的10岁到12岁年龄组的儿童,其数学和物理考分也开始稍稍 落后于美国高中三年级的学生。这个结果在这些国家都引起了普遍的担心,很多人对自己国家小学基础教育的质量产生了严重的疑问。
“报道”说,中国的反应尤其激烈。很多中国人呼吁对基础教育全面改革,对教师实行更严格的考核,延长学期,增加更有效果的教学材料。中国“教育部发 言人袁贵仁(音译)”说,“坦率地说,这个结果是不可接受的,我们必须采取果断措施立即扭转这个趋势。”如果不这么做,“我们怎么能指望我们十三岁的孩子 为上美国的大学做好准备呢?”
政治讽刺做到这个地步,表现了美国文化深刻的幽默感。美国基础教育之差已经不可救药,但组织此类测验来体现自己重要性并人为制造紧张的“国际教育评 估协会” 和那些在这个名次面前战战兢兢的各个国家则在另一个极端受到了讽刺。“麻州核桃山”这个地名暗讽美国东部教育重镇主张与国际接轨的自由派文化精英,而把教 育明明很落后的“新几内亚”和韩日德等国放在一起则是对这些“先进国家”的搞笑。但最“受伤”的,当然是中国。中国被描绘成一个用分数和名次拔苗助长几乎 要把孩子逼疯的社会,八岁的孩子已经上三年级了,但最终—最具有讽刺性的—还是要把孩子送到美国来读大学!忙了半天,成了美国大学的预备班。
数学成绩差—美国的国家形象
讽刺归讽刺,美国中小学生数学成绩差,已经在国际上定格为美国国家形象的一部分。几乎每过一年半载,国际新闻界就会报道说在最近的国际竞赛或者国际 评估中,美国学生或者名落孙山或者总体排名在很多国家之后。和美国学生形成对照的,往往是中国学生,或者总体来说东亚的学生,还有新加坡和西欧一些国家。 很多中国人相信中国小学生的数学教育拿到美国来应付初中是没有问题的。
在美国国内,这个问题也一直是公共讨论的话题。总体来说,谁都不认为这是个可以置之不理的问题。冷战结束以来,国际竞争更多地反映在经济和技术领 域,而新技术革命和经济全球化给了很多国家在很多方面后来居上迅速超越美国的有利条件,实际上美国面临的国际竞争比冷战时期更复杂更激烈。在这种国际竞争 中,国家基础教育的质量和人口整体智力的发展无疑是一个长期因素。这些都是老生常谈,美国人不是不懂。但具体落实到数学教育上,几十年来不进反退。
作为世界上科技最发达、创新最有活力的国度,美国基础教育中一些学科(数学尤甚)为什么长期以来一直比较差,这是一个值得思考的问题。一个学科在国 家范围内的整体水平差,一定有它制度和文化上的原因,反过来也是如此,就像凡是中国人都知道为什么中国学生数学比很多国家的同龄人要强,其原因何在一样。 这和人种没有关系,东亚和欧洲一些国家以数学强著称的国民并不特别聪明,除了极少数天才,多数是被塑造成这样的。
有些人或许会说,美国学生数学成绩差是比较而言的。这个“比较”有两重含义,第一是和国际上的“先进国家”相比,第二,是和美国在国际科学技术发展 上的领先地位相比。换句话说,如果不是“美国学生”,那么这些测验和竞赛的结果在国际上或许不是特别让人皱眉头。这个角度无疑有道理。但另一方面,美国学 生平均数学水平,用美国国内的标准来衡量也是比较差的。这个事实,在大学招收新生和大学中对那些对数学有特别要求的学科的统计数字中都有充分反映,是美国 教育界的常态。
笔者对数学教育完全是外行,但在美国社会的所见所闻告诉我:美国教育界对数学教育为什么一直上不去,在数学教育中究竟应该怎样改革怎样提高,是有很 多具体专业的讨论的,外行难以置啄。例如,有的研究者指出,美国数学教育最大的问题是它的最终目标不清楚:小学,初中和高中究竟应该让学生掌握多少数学知 识和技能,在实践中含糊不清。有的说美国数学教育的一个倾向是重过程轻概念,老师只是要求学生一步步按照过程来演算,而不是从整体概念上培养他们举一反三 的能力,学生知其然不知其所以然,思维受到限制,容易觉得数学就是牢记那些法则,难以培养对它的兴趣。还有学者就什么时候开始让学生接触几何,什么时候让 他们接触代数之类的问题做过详尽的数据分析。
一个人文学者显然没有资格讨论这些争议,这里只能从自己学科和知识的角度对一些长时段的、制度性和文化性的原因提出一点看法,供关心这个问题的中国 读者参考。这里的讨论只涉及美国的公立学校,私立学校一般的水准要高于公立学校,但它的对象主要是精英家庭和对宗教有特别要求的家庭的孩子,总体上只吸收 百分之十几的学龄儿童和青少年,不是这个国家教育体制的主体部分。
美国初等教育的总体问题
首先,我想说不但是数学,而且是小学甚至初中的知识灌输和方法培养在整体强度上(所谓强度这里指教的压力和学的效果),美国学校要弱于中国学校。数 学问题必须放在这个整体上来观察才说得清楚,而这种整体的薄弱是由美国社会很复杂的原因造成的,必须在破除对美国社会的一些误解的基础上才能理解。很多亚 洲和东欧国家的新移民来到美国后,常常会通过自己的子女在美国的学校中的表现获得自信甚至优越感,因为他们的孩子在数学和科学上成绩一般高于美国土生土长 的学生。很多人因此会认为美国孩子懒,被宠坏了,美国老师工作不努力。有人会说美国孩子思维方式有问题,尤其表现在数学上。更有人说美国人自以为了不起, 他们的文化优越感使他们觉得不用好好学习,尤其是那些比较抽象的东西,数学就是如此,反正有外来移民帮他们做,等等。这些问题从现象上看都不是没有根据, 但问题是如何理解。
从制度上说,由于联邦制把教育权基本给了州,美国的教育在国家水平上就没有一个系统的目标,或者说缺乏有力的贯彻国家目标的渠道,尤其在面临世界性 的竞争、迫切需要有全国统一的战略目标的时候。美国联邦教育委员会主要起一个协调的作用,只可以为各州的基础教育制定一些建议性的目标和原则。它的权威和 知名度,更不用说掌握的资源,远远不及中国中央集权下的国家教委。在“举国一致”的发展模式中,中国国家教委的意志可以一直贯彻到小学的教室,而站在美国 小学教室里,联邦教育委员会是一个很飘渺的存在,真正受重视的是本州的教育总监和本州的议会。在联邦制下,美国经济文化发达的州和相对保守封闭的州之间在 教育目标和财政支持上也就存在着实际上的差别,而且在同一个州,各个市县的公立中小学之间也有很大的差别,这从各地(州市县)从税收中提取作为教育经费的 比重就可以看得出来。尽管它们在原则上都会唱不断提高教育水平,迎接国际挑战这样的高调。
制度上的原因之二,是美国公立学校本身的问题。举个实例,对美国中小学—尤其是小学—有一定了解的华人家长都会觉得教师布置的作业量远远不够。很多 时候,小学四、五年级的小孩回家后家长根据中国的习惯问他们有没有家庭作业,回答竟然是没有。其实,就我接触到的很多美国家长来说,他们对此也很不满。很 多华人家长或是因为文化原因或是因为谋生压力大,平时无暇了解美国社会,不知道其实美国家长对小学教育的松垮现状可能比他们意见还大。美国初等教育对学生 的压力不够可能有两个制度上的原因。第一,教师在美国这个职业竞争很强烈的社会中有些例外,它既是铁饭碗,但待遇又不和业绩挂钩,学校内部教师之间不像中 国那样有强烈的竞争意识,在各项考核中看成绩比名次。第二,他们有教师工会保护他们的利益。这些原因一定程度上降低了教师工作积极性,造成了对学生的低要 求。
和中国学制相比,美国的小学本来全年实足上课的天数就不足(中国是240天,美国是180天),而且每天实际上课的时间也要短一两个小时,但很多公 立学校还找出理由来设立“教师进修日”等等名目,放学生回家。由于这些原因,美国公共舆论对公立教师整体很有看法,认为他们由于缺乏竞争而懒惰,不肯在提 高教学效果上下功夫。在美国左右和自由保守两派的对立中,教师无疑都倾向于前者,是民主党的票仓。这是由他们的利益决定的。而保守派一直呼吁从法律上削弱 教师工会的权力,减少保护,增强竞争。
除了教育制度的原因,还有社会原因,即种族和阶级差别带来的问题。美国是一个多族群和移民社会,由于文化传统的关系,各个族群对教育的重视程度不一 样。学而优则仕和学而优则富的观念并不是对所有族群的人有同样的影响。非裔和西裔人口集中的社区,学校的要求一般低于平均水平;白人和亚裔集中的地方则相 反。这种局面时间长了,也就积重难返,成为教育制度中的痼疾,一定程度上还受到美国社会政治正确性的保护。这无疑从整体上拖了美国教育的后腿。
美国童年文化的因素
除了这些制度和社会的原因,我想,美国学校教育在中小学、尤其是小学阶段显得力度不够,还有一个文化上的原因值得中国读者思考。
在美国,小学教育和实际生活之间的距离要比在中国小得多。走进美国小学教室,你会感觉到浓厚的生活气息。中国的教室是全体学生面对老师,教室内只有 整齐排列的四、五十张课桌椅和老师的讲台。这样的教室在美国到了中学才会有。美国小学教室里,基本上是几张座椅围绕一张桌子,几个学生分成一个组,一个教 室有几个这样的圈圈,每个学生都有自己的一块空间(如橱柜之类)放自己的衣服用具和书籍。教师有自己的一块地方,既有讲台也有写字台。所以美国小学教师一 般是没有自己的办公室的,他们和学生同享一个空间。教室里有书架放置日常阅读的图书杂志,用具架,现在有电脑。一般教室里有自来水和水池。墙上是每个学生 的照片和自我介绍,还有应时应景(各种节日和社会事件)的装饰,也有世界地图和本国地图。天花板上还常常悬挂各种装饰。学生的教科书是不带回家的,放在教 室里供几届学生轮着使用。学生的所有作业和品行纪录都放在老师的办公区域。开家长会时,家长们可以随时检查。在教室里,学生除了学习,还有丰富的人际关系 活动,例如给同学庆生(可以把蛋糕给进教室给全班分享),每逢情人节相互送礼物(即使是小学生),甚至还有做游戏,等等。
这样一个教室,和中国教室相比,更像是一个家庭。它的功能不止是上课、做作业和考试,而是让孩子们也感到是他们的第二个家庭。和中国学校的班级以某 年级某班相称不一样,美国的班级是以主讲老师的名字来命名的,某先生某女士某小姐,他们就像是这些孩子的监护人。即使是教学,老师也尽量用生动的形式,包 括做游戏来进行。这样人性化的教学环境当然是有代价的,这代价就是学习气氛。
而一进中国教室,孩子们就感觉这是一个和家庭以及邻里完全不同的社会环境和人际环境,到了这里,他们唯一能做的就是学习学习再学习,他们的全部注意 力和精力只能往学习上灌注,他们的观念是在教室里的时间应该是分秒必争。在这两个不同的教学环境下,学生连坐的姿势都是不一样的。毫无疑问,对于严格的训 练来说(用中国话说是“上规矩”),尤其是那些难以通过趣味和生动的方法灌输给孩子的抽象知识,中国的教学环境无疑更有效果。而美国小学的很多活动,在习 惯了像中国这样的教育制度的人看来会百思不解:难道这也是教育吗?这不是玩吗?这样能学到什么知识呢?
但美国小学教室内的活动如此安排,是建立在童年这个人生阶段在美国文化中的地位上的。像中国这样,一年有二百多天时间七、八岁的儿童每天要规规矩矩 正襟危坐朝着同一个方向,“眼睛看老师,耳朵听老师,嘴巴闭起来”,美国文化是无法接受的(这是我小时候从幼儿园老师那里记住的,最近又听中国派到这里的 公立幼儿园教一年汉语的老师也这样对美国儿童要求,每天在教室里重复,成了汉语教学的一部分,不禁愕然。此事听上去很搞笑,但却千真万确。)。
美国文化也不能接受生活的这一个阶段就是为了下一个阶段作准备这样的观念。它强调人的不同生活阶段的即时当下性,各个阶段有它自己独立的地位。儿童 时代童稚初开,更是为了享受生活而不是承担压力的,哪怕在学校也是如此。学生到学校不单是学习,也是生活,应该让他们尽量觉得学校也是家庭。从这个角度出 发,教室环境如此安排也就不奇怪了。美国人对儿童—甚至不但是儿童–最常说的话是“好好玩”(have fun)和“玩得开心吗?”(did you have good time?),而不是“听老师话”或者“遵守纪律”。这种生活态度看重人生的愉乐,当然就不利于向儿童灌输大量和他们实际生活无关的抽象知识。在一定程度 上,这是游乐场和竞技场的区别,也是夏令营和军训营的区别。
这些重视童年生活本身价值的“美国特色”,总的来说都不利于数学作为一门最抽象的学科在早期教育中的效果。有的因素本身虽然值得推崇和借鉴,尤其是 初等教育尽量照顾学生的心理和情感需求,在知识灌输和方法训练上让他们相对轻松,让他们的个性也获得自由和充分的发展。但这在越来越激烈的国际竞争中变得 像是不合时宜的奢侈品,过去有条件享受,现在在那些不惜以牺牲童年生活拼命竞争的国家面前变得越来越负担不起。这个问题最终涉及到一个社会的价值选择,就 像今天为了反恐必须相当程度上牺牲个人隐私和便利一样。
还要看到美国学生固然抽象思维差,但他们在生活实践中动手能力强,团体协作意识强,这也是公认的。这两点都是在初等教育中培养起来的,一定意义上是 用数学成绩差换来的,因为人的时间和精力都是有限的。这和中国学生的情况正好倒过来。中国学生成绩再好,往往也是一个人死读书,从小心里就被灌满了危机意 识和竞争意识,不知觉地接受了社会达尔文主义,丧失了童年的天真和乐趣。美国小学生相互是玩伴,中国已经是竞争对手。中国是一个牡丹园,开满了用化肥催生 和除虫出来的同一个品种的鲜花,而美国是一个百花园,有不同的花色,也有灌木和杂草。
意识形态的影响
最后,我想美国社会的三大意识形态传统,即平等主义、实用主义和反智主义(或民粹主义)的纠结,也直接间接地影响了社会和学校对数学教育的重视。
美国的平等主义体现在初等教育的数学教育中,就是迁就中等程度的学生。具体表现在不是尽量把一个班级的“普罗大众”往少数成绩好的学生那个方向去引 导或施压,而是尽量照顾他们现有的程度,并把重点放在帮助落后生提高成绩上。毫不奇怪,很多中国学生的家长对美国小学数学教学的程度之低和进展之缓慢可以 说是到了张口结舌的地步。这样的数学教育当然容易缺乏生机和挑战。中国数学教育不但承认而且提倡的“心算”(mental computation)在美国很难受到推崇也和这个因素有关。网上有关数学教育的讨论中,一个美国网民说他小时候心算很好,他自己也不清楚是什么原因, 但他的几个数学老师都要求他在同学面前一步步用手算(hand computation)把心算过程列出来,让大家都看得懂,结果他反而常常出错,后来对数学就失去了兴趣。
美国杜克大学公共政策教授杰克布 费克多前两年发表过一个有影响的研究报告,指出了平等主义给数学教育带来的问题和后果。费克多的研究证明,美国数学教育失败,是因为它为了平等牺牲了效 率,或者说为了普罗大众而牺牲了精英,从长远来看普罗大众也没有得益。他说很多老师有一个误解,认为那些数学天份高一些的学生总是会自己努力或者一直保持 这个成绩的,但这完全错了。这些学生得不到鼓励和支持,很多人就慢慢变得和一般学生一样,到头来美国大学很多对数学有特别要求的学科常常缺乏生源。他认为 近两届美国联邦政府资助的“一个也不拉下”计划也是犯了这个错误。
一些刚移民来到美国的华人家长常常碰到这样的问题:因为他们子女的数学水平超过了他们的美国同学,当他们要求美国老师给自己的小孩额外加点压力的时 候,很多美国老师觉得不解–你孩子的成绩已经在班上是很最好的了,还要再加干什么?换句话说,作为老师,他们的任务就是保证每个人“达标”就行了。
平等主义就是反精英主义。与此相联系,美国也是一个有着实用主义和反智主义传统的国家,这一点很多只看到美国高端科技和发达的人文学术的人可能会吃 惊。实际上,和其他国家相比,美国文化最大的特点并不在于它的发达,而是多元化。所谓实用主义和反智主义,反映在教育上就是对很多在实际生活中很难找到应 用价值的学科和知识报怀疑和消极甚至是否定的态度,主张教育应该多和生活相结合。美国文化虽然是从欧洲文化中继承下来的,但它在科学和哲学上的抽象思维发 展得很晚,在西方科学的祭师(即抽象思维)和工匠这两种传统中,美国代表的更多的是后者,它的重要人物都是工匠型的,如最早的富兰克林和后来的福特,莱特 兄弟等等。直到今天,美国得诺贝尔科学奖的很多人都不是在美国受初等教育甚至大学本科教育的。受这种传统的影响,高深一点的数学(不是算术)被看作是智力 的奢侈,逻辑的游戏,让少数人去发展可以,但让多数学生去花功夫是浪费时间,长大后在实际生活中毫无用处。
中国人应该对毛泽东时代的教育革命有印象。那个教育革命的一个方面就是把教育完全实用主义化,凡是在“三大革命”实践中没有直接应用价值的知识都受 到排斥,中学的物理和化学被简化成“工业基础知识”和“农业基础知识”,目标是要培养“全面发展的劳动者”而不是“精神贵族”。这样的教育革命并不是毛泽 东的发明,而是苏联在二十年代的实践,后来也像中国的教育革命一样失败了。古巴上个世纪60年代也在卡斯特罗领导下经历了和中国一模一样的教育革命。
但很多人不知道的是,就是这样的教育革命,吸引了很多对西方教育制度不满的欧美知识分子。他们对西方教育制度的批判的一个重要方面就是它的精英主义 和脱离生活的倾向,认为培养出来的学生会动脑但不会动手。美国二十世纪最著名的哲学家也是教育家的杜威当时就代表了这种实用主义和反精英主义。他在二十年 代末访问苏联,专门考察苏联的中小学和职业技术教育,对那个教育革命赞不绝口。当时美国另一个著名教育家乔治 康治 (George Counts1889-1974)和杜威对苏联教育革命问题有相似的经历和看法。杜威和康治等人不但说,而且做,在美国开展了相关的教育实验。前面提到的 杜克大学费多克教授的文章中就说,以杜威为代表的实用主义教育思潮和实践,在一定程度上也融合进了美国公共教育的观念,不利于数学作为一门抽象学科的发 展。毫不奇怪的是,中国文革和卡斯特罗革命的西方赞美者中很多也是教育工作者,他们也是文革高潮过后第一批来华访问的外国人。
屠龙之技与基本技能:中美对数学的不同要求
以数学为坐标对比中美两国的初等甚至中等教育,美国的不足是显而易见的。但我们的对比不能到此为止。应该说,如果美国是不足,那么中国则是过剩,尤 以今天的“奥数”热为甚。一个不足一个过剩,说明两个国家初等教育的整体目标很不一样,彼此都为自己的目标付出了代价,都应该以对方作为借鉴。和物理化学 生物这些学科不一样,数学除了培养人的分析和综合能力之外,在实际生活中主要是一门工具,所使用的范围很有限。中国初等教育的数学比美国要高深,这在一方 面有利于人的早期逻辑思维的发展,但在另一个方面它的灌输和强化所需的时间和精力又确实让孩子们的童年和少年付出了太大的代价。而且对于多数人来说,辛辛 苦苦学得的那些高深的数学知识(工具)将来在日常生活中不过是屠龙之技,而物理化学生物等等多少还是有用的,或者只要你想发现它的用处就能发现。
在这个意义上,美国全国研究生入学考试的GRE一般测试中包括数学,表达了美国社会对数学重要性的理解,值得在这里一提
GRE一般测试有三个项目,第一是Verbal Reasoning,即语言理解能力;第二是Analytical Writing,即分析问题的能力;第三是Quantitative Reasoning,即对基本数量关系的理解和处理能力,这基本是考你的算术和数学。所谓一般测试就是不管你是考哪个专业,这是必考的。这就很有意思。中 国和其他重视数学的国家到了研究生入学考试这一级,人文和社科类是不包括数学的。而美国虽然之前不如中国重视,但此刻却必考。考什么呢?即使用美国的标准 来衡量,其内容基本上不超过初中水平,而另外两个科目的程度设定为大学本科毕业,它们之间隔了8年的教育程度!这说明美国教育制度基本是把数学作为工具来 看的,所以哪怕你是文科研究生也需要它,但需要的程度又有限,因为毕竟是工具。可以说,一般人的生活经验都可以证明,他们日常生活中需要的数学知识确实不 超过初中数学的水平。这种对待数学的态度,虽然是实用主义,但又未尝不可以拿来给对它“始严终弃”的其他国家提供一个参考。
-------------------
人家美国人讲究的是创造性,creativity,不是死记硬背。

在linux vps上搭建基于python的静态博客程序-acrylamid

pip install acrylamid 
(这样安装的acrylamid是0.7版,这个版本有init功能,正是所需要的版本。不要“克隆它的源码,然后在源码目录里运行python setup.py install”,这样安装的acrylamid是最新版-0.8版而0.8版去掉了init功能,所以这个0.8版就不太好用了,之前就是卡在这里。如果你这样安装了0.8版,请做操作如下:
pip uninstall acrylamid
pip freeze | grep acrylamid (确保输出内容为空)
pip install acrylamid )

as3:~# acrylamid --version
Acrylamid 0.7.7
as3:~# acrylamid -h
usage: acrylamid [-h] [-v] [-q] [-C] [--conf /path/to/conf] [--version]  ...

positional arguments:

    compile             compile blog
    view                fire up built-in webserver
    autocompile         automatic compilation and serving
    info                short summary
    ping                notify resources
    check               run W3C or validate links
    deploy              run task
    import              import content from URL or FILE
    new                 create a new entry
    init                initializes base structure in PATH

as3:~# acrylamid init acrylamid-blog (在当前目录下,该命令会生成acrylamid-blog目录)
as3:~# cd acrylamid-blog
as3:~/acrylamid-blog# ls
conf.py  content  theme
as3:~/acrylamid-blog# acrylamid compile (这个就是生成/更新静态网站的命令)
as3:~/acrylamid-blog# ls
conf.py  content  output  theme  (新出现了output目录)
as3:~/acrylamid-blog# cd output
as3:~/acrylamid-blog/output# ls
2012  articles  atom  index.html  rss  sitemap.xml  style.css  tag
as3:~/acrylamid-blog/output#
(可见,~/acrylamid-blog/output/就是静态网站的根目录)
as3:~/acrylamid-blog/output# nohup Rwebserver 45375 > /dev/null &
(这样访问http://as3.brite.biz:45375/,即可看到网站效果)

as3:~/acrylamid-blog/output# acrylamid new (这是建立新帖子的命令)
Entry's title: test1 (输入帖子的标题)
     create  content/2013/test1.txt
   critical  Could not launch an editor
as3:~/acrylamid-blog/output# cd ..
as3:~/acrylamid-blog# ls
conf.py  content  output  theme
as3:~/acrylamid-blog# nano content/2013/test1.txt
as3:~/acrylamid-blog# cat content/2013/test1.txt
---
title: test1
date: 30.11.2013, 14:34
---
这是测试1.  (header部分已自动建立。只需在此行写正文)
as3:~/acrylamid-blog# acrylamid compile (这个就是生成/更新静态网站的命令)
(当然也可手动新建帖子:
as3:~/acrylamid-blog# nano content/2013/test2.txt
按~/acrylamid-blog/content/sample-entry.txt的内容,得知格式如下:
---
title: test2
date: 30.11.2013, 14:40
tags: [misc1, misc2]
---
这是测试2.

然后:
as3:~/acrylamid-blog# acrylamid compile  )

演示站点:http://as3.brite.biz:45375/,HTTP://arlm.brite.biz
项目地址:https://github.com/posativ/acrylamid,https://posativ.org/acrylamid/commands.html
这个程序真不错,它能对长文自动生成摘要。推荐!






Deep Web(深网)

While many of deep web content is illegal, there’s also good guys that trying to spread information quickly and anonymously to avoid legal or ethical ramification, such things like WikiLeaks has circulated around deep web even before WikiLeaks exist. Because of it, I found this whole anonymity concept is interesting and should be studied further.
Now you think you’re ready to dive in the deep web? Before that there are tips and some preparations you must do first:
  • First, I recommend to turn off javascript and cookies on your browser, enabling this would be very dangerous. Also, you might want to disconnect your webcam, just to make sure its not gonna be hijacked.
  • Don’t go around clicking every links you could see, always proceed carefully.
  • Some understandings of HTML/Javascript/PHP or any knowledge about internet and how it works somehow needed to ensure you are accessing a safe website.
  • If anything happens, DON’T PANIC. Disconnect your internet, clear your session and history, pretend nothing happened .
And here’s how to connect to deep web. First get Tor bundle on http://torproject.org, you could choose to download the whole browser and Tor bundle, or you could download Tor and Vidalia bundle. Unzip the bundle, start it, and if you download the Vidalia bundle you have to configure your browser’s proxy to localhost port 8118. And that’s it! You are connected to Tor network, to start exploring deep web, start with going to .onion entry point (eqt5g4fuenphqinx.onion), the TorDir (dppmfxaacucguzpc.onion) or The Hidden Wiki (kpvz7ki2v5agwt35.onion). And that’s it, have fun and stay safe.
Sources:
查看图片
------------

https://www.deepweb-sites.com/

一个简洁的cms-getsimple(无需数据库)


I found this lately and got kinda addicted with it. GetSimple CMS is a very simple and lightweight CMS, it require no database, simple installation, yet highly customizable. GetSimple CMS use flat file database, means all database entry on the web are stored into XML files. GetSimple CMS is perfect for individual or small companies to advertise their business or just to put anything on the web, but has low budget to do it, because it didn’t need RDBMS means you don’t have to pay more for RDBMS service on webhosting.
The web app design itself is very simple, it consist only pages and files. Page could be shown as menu, so it could be accessed. The page that are not menu has to be linked somewhere in another page so it could be accessed. File, like images, are inserted manually to the page. Pages also have some options, such as set parent page, set private page, and set page metadata. There’s also themes and plugin feature so user could customize the look.

The feature I love most of this CMS is, its like a blank canvas for a web developer like me, I got addicted installing plugins and theme so the web looks the way I want. And this “simple” feeling that I could understand their code and fork their project.
Also get it now from http://get-simple.info
下载地址:http://get-simple.info/dreamhost-pickup/GetSimpleCMS_3.2.3.zip

在linux vps上搭建基于ruby的静态博客程序-dorothy/toto

git clone http://github.com/cloudhead/dorothy dorothy-site
cd dorothy-site
as3:~/dorothy-site# ls
articles  config.ru  public  Rakefile  README  templates
as3:~/dorothy-site#
as3:~/dorothy-site# cd articles
as3:~/dorothy-site/articles# ls
1900-05-17-the-wonderful-wizard-of-oz.txt 
按1900-05-17-the-wonderful-wizard-of-oz.txt的格式,新建帖子2013-11-30-test1.txt,格式如下:
title: test1 (不支持中文标题)
author: ym
date: 2013/11/30

这是测试1.


(注意:postslug必须跟title的值一致。postslug如果有多个英文单词,建议用连字符连起来。比如
this-app-seem-not-to-support-180kb-long-article,而在源帖子中,title的值则不必用连字符连起来,不连起来更好看些,比如:
as3:~/dorothy-site/articles# cat 2013-11-30-this-app-seem-not-to-support-180kb-long-article.txt
title: this app seem not to support 180kb long article
author: ym
date: 2013/11/30

这个程序好像不支持发表180kb的长文。)


然后:
as3:~/dorothy-site/articles# gem install unicorn
as3:~/dorothy-site/articles# cd ..
as3:~/dorothy-site# nohup unicorn --port 23461 > /dev/null & (必须先进入~/dorothy-site/,然后才运行该命令。这条命令在后台运行,它会监视articles目录的变化而自动更新网站。所以在建立第2条帖子后,网站就会自动更新而无需再运行此命令)
或者:
as3:~/dorothy-site# killall unicorn
as3:~/dorothy-site# nohup unicorn --port 23461 > /dev/null &

demo site: http://as3.brite.biz:23461/
项目地址:http://github.com/cloudhead/dorothy
这个程序有点怪,竟然没找到它的根目录在哪,因此无法绑定域名。不过可用nginx或apache做反向代理来绑定域名。
-------------------------------------------------------------

Getting Started With Toto,
a Tiny WordPress Killer

A couple of months ago I migrated UsabilityPost from WordPress to Toto and am really enjoying the switch. Toto is a tiny blogging engine by Alexis Sellier (creator of LESS) that on the face of it appears so simple, and yet is able to do so much.
Toto stores all your posts as text files. The engine is written in the Ruby programming language and so you can use Ruby throughout your template files to add extra functionality. Additionally, Toto works extremely well with Heroku, a Ruby cloud host, which makes deployment especially easy—you can actually get a new blog up and running in about 10 seconds.
I’m really excited about this because Toto isn’t just very easy to style, customize and deploy, it’s also secure and can handle huge traffic loads. Before Toto, WordPress would be my first choice if I wanted to start a new blog. Now, Toto has completely replaced WordPress for me. Need to start up a new blog for a project? Grab Toto, style a couple of template files, deploy on Heroku and it’s live, ready to handle everything you throw at it. No messing around with databases, config files and admin panels. Read my introduction to Toto to find out more about why I think Toto is so great.
Now, let’s get to the main subject of this post. I’d like to walk you through how to get started with Toto and share with you the little modifications and updates I’ve implemented on my template files to make the most of this little blogging engine.

Contents:

  1. Installation
  2. Writing posts
  3. Running Toto locally
  4. Modifying the template
    • SEO-friendly description
    • SEO-friendly page titles
    • Navigation
    • Feedburner
    • Scheduled posts
    • Custom categories
    • Disqus comments
    • Blog configuration
    • www redirect

1. Installation

Edit 2012/09/06: If you’re on a Mac, I’ve written up new installation instructions for the latest version of OS X at this time, which is OS X Mountain Lion. If you’re on Mountain Lion, read the new guide instead and then skip to Section 2 below.
And here comes a little “catch”. While Toto is incredibly easy to use and customize, it does need a couple of things to get it running. You need Ruby and RubyGems to install and run Toto, and you’ll need Git to deploy it to Heroku. Ruby is the programming language of Toto, and Git is a distributed version control system used to record code changes and deploy the latest version to Heroku.
If you’re on a Mac (OS X 10.5 and higher), you should already have Ruby installed. To install Git you can use this installer. Linux people probably already know the drill, but if you don’t there’s more info on Ruby’s official site and the Git site.
Unfortunately, Windows is trickier. There is however a really good screencast that goes through all the steps involved with installing Git, Ruby and Ruby gems on Windows. It also shows you how to use Heroku on Windows.
(NOTE: You may also need to also install the Ruby development kit on Windows to get Toto working — get it before you install the Toto gem)
To use Heroku to host your blog, go there and get a new account for free if you haven’t already got one. Additionally, you’ll need to install the Heroku Ruby gem (gems are little Ruby tools). On OS X or Linux, open up a Terminal window (search for Terminal if you’ve never used it before) and type the following to get it installed:
sudo gem install heroku
It may ask you for your password, so be sure to type that in when required. Once it’s installed you can go ahead and get the Toto gem (the actual engine), together with a Ruby server to run it, if you don’t already have one. I recommend the Thin server.
NOTE: If you’re on Mac OS X, you’ll need to also install XCode before you try and install both, the Thin server and Toto. XCode is free and is available on any OS X installation disk, in the extras folder. Once you’ve got it installed you can install both gems with this command:
sudo gem install toto thin
After this, we’re ready to get stared. The first thing we need to do is grab a copy of Dorothy. Dorothy is the generic template for Toto—it basically has the set of folders and layouts you need together with a configuration file. Clone a copy of Dorothy using the following command, changing “myblog” to whatever folder name you want to put your new blog into:
git clone git://github.com/cloudhead/dorothy.git myblog
Note: this creates your blog folder in the directory you’re currently in (i.e. by default it will be the “Home” location on OS X). Now we need to set up Heroku for this newly created blog. We’ll navigate to our new folder and do this using the following commands (again substitute “myblog” to your blog’s name):
cd myblog
heroku create myblog --stack bamboo
The “—stack bamboo” bit specifies a Heroku stack which supports Varnish, the caching engine Toto uses (newer stacks on Heroku no longer have it). And that’s it. To deploy and view the new blog just type:
git push heroku master
heroku open
You should now see a newly deployed Toto blog running on Heroku. If you have a custom domain, there is a free module in Heroku that will let you use it (more info over at Heroku docs) I also recommend using their section on deployment with Git to learn more about it if you’re not familiar with Git—it’s very simple once you learn the basics.
Now…it may seem like it’s a lot of work just to get one blog running, but actually, once you do this first set up once, the next time you want to launch a blog you can do it with about 3 commands (clone Dorothy, initialize Heroku, deploy), which really does take about 10 seconds. This combination of a cloud hosting platform, Heroku, and a version control system, Git, really makes things incredibly simple and fast once you get the hang of it.

Migrating from WordPress?

Scott Stout has a Ruby script over at Github which will convert a WordPress XML export to slugified toto articles. I’ve used a similar, though a much simpler, script to migrate UsabilityPost over to toto. You can even migrate existing comments over to Disqus—the comments engine I recommend for toto—by first installing Disqus on your WordPress blog and then using their import service to get the old comments into Disqus.

2. Writing posts

Posts are all stored in the /articles/ folder. To create a new post just save a text file in that folder with its name in the following format:
yyyy-mm-dd-post-permalink.txt 
So if you’re publishing a post on 7th May 2010 called “Blog Updates”, you’ll name the file like: 2010-05-07-blog-updates.txt
Right at the top of each post text file you can add additional post information. The one bit of info that is absolutely required is the title. You can use a different title to the permalink, as long as you specify it in the post as a custom “slug”. So for the above example I’d write the following at the very start of the post:
title: "Blog Updates And News"
slug: blog-updates
Then right below this, leave an empty line and start writing the post. Toto uses Markdown for formatting. If you’ve never used it before, check out the site, it’s a very easy way to format your content without writing any HTML. If you do want to use HTML, no problem, you can do that too.
That’s basically it, just write new posts and put them in the articles folder. I keep draft posts in a /articles/drafts/ folder. These posts don’t show up on the blog until I move them to the the articles folder.
If you’re using Heroku and are ready to publish, you’ll need to add these files to Git and push them to Heroku. You’ll use the following commands:
git add .
git commit -a -m "written some new articles"
git push heroku master

3. Running Toto locally

Ok, you’ve written some posts but what do they look like in your template—indeed, what does the site look like? How do we test it locally? Remember, we grabbed the Thin server when getting Toto installed. This will come handy here. Just open the Terminal, navigate to your blog folder, and type:
thin start
This will launch the Thin Ruby server. To see the site running on your machine, open a browser and navigate to: “http://localhost:3000”

4. Modifying the template

The HTML template is located in the /templates/ folder, with CSS, JavaScript and other assets located in /public/. “layout.rhtml” is the core template, with everything else being rendered inside it. If you edit this file, you’ll see a bit of code in the middle that reads:
<%= yield %>
This is where all the posts or the page content goes—i.e. it will replace “yield” when you load the page. All the other code around “yield” will show up on every page, so this is where you’ll add your navigation, header, footer and so on.
Let’s go ahead and make some updates to make this template more robust.

SEO-friendly description

A good practice is to have a different page description (this is the meta description bit between the head tags) for each page, especially article pages. This description will show up on search results pages and so is useful for making the most of that traffic source. To get custom description to show up for each post, use the following code:
<meta name="description" 
content="<%= @context[:description] || 'Default description' %>" />
“Default description” will be used unless a bit of meta info called ‘description’ is provided in the post text file. When you want to use a custom description just add this to the top of the post file:
title: "Some Interesting Post"
date: 2010/05/07
description: "Custom description goes here..."

SEO-friendly page titles

Page titles (the bit between the <title> tags) are very important for a search friendly site, so we need to update that code a little bit to make the most of it. I use the following code:
<title>
<% if @path == 'index' %>
    Your Blog Name
<% elsif @path.split('/').compact.length == 4 %>
    <%= title %> - Your Blog Name
<% else %>
    <%= @path.capitalize.gsub(/[-]/, ' ') %> - Your Blog Name
<% end %>
</title>
Basically, “Your Blog Name” on the 3rd line will show up as the title if you’re on the home page. The 5th line will render the title of the blog post before the blog name when you’re on a blog post page. Finally, the 7th line will will show the title as: “About – Your Blog Name” when you’re on the About page—the @path... bit will be replaced with the title of the page you’re on. So edit the three instances of “Your Blog Name” to whatever you wish. The code here isn’t particularly clean, but it works well enough.

Navigation

Dorothy comes with a few pages by default. You’ve got the index, the about page, the article page and a custom archive page. These templates are all located in the “/templates/pages” folder. If you want to add a page, just create a new template in this folder and call it whatever you like. So if you want a books page, create a “books.rhtml” file in the pages folder. You’ll then be able to access this new page by going to “yourwebsite.com/books”
If you’d like to highlight the current location on the navigation bar you can use a simple conditional statement using the @path variable. So for example, our navigation code may look something like this:
<ul>
    <li><a href="/">Home</a></li>
    <li><a href="/archive">Archive</a></li>
    <li><a href="/books">Books</a></li>
</ul>
The @path variables gives us the current location we’re at. So if we’re at the books page, @path will be “books”. The home path is called “index”. We can use this to set up some simple conditional statements to add an “active” class to the list items, which we can then target with CSS to add custom highlighting. The code will look as follows:
<ul>
    <li <%= ' class="active"' if @path == 'index' %>>
        <a href="/">Home</a>
    </li>
    <li <%= ' class="active"' if @path == 'archive' %>>
        <a href="/archive">Archive</a>
    </li>
    <li <%= ' class="active"' if @path == 'books' %>>
        <a href="/books">Books</a>
    </li>
</ul>

Feedburner

If you want to use Feedburner to serve RSS you’ll want to make a couple of quick changes. First of all, Feedburner has a limit on how much information it can store in its cache, so we’ll want to trim our RSS output a little so that it only shows a few posts at a time, and not all of your blog’s articles. Edit the “/templates/index.builder” file (it may be called “feed.builder”, in which case you should rename it to “index.builder” as the name should match your index page) and look at the articles loop. The first line should read something like:
articles.reverse.each do |article|
We want to limit the output to only a few items…say 10. This way we won’t fill up Feedburner’s cache. I changed this line to read:
articles.reverse[0..10].each do |article|
Now, to use Feedburner you’ll obviously want to place a subscribe link on your “layout.rhtml” file to point to your Feedburner subscribe URL. What you’ll also want to do though is add a bit of meta at the top of the layout file to say that the RSS for this page is located at Feedburner. Edit “layout.rhtml” and add this line between the <head> tags:
<link rel="alternate" type="application/rss+xml" 
title="myblog" href="http://feeds.feedburner.com/myblog" />
Make sure to change the two instances of “myblog” above to whatever it is your blog is called and your Feedburner URL is. This will make sure that if someone uses a browser-based RSS reader, they’ll be redirected to Feedburner for the feed.

Scheduled posts

Want to write a bunch of posts in one go and then schedule the days on which they’ll be posted? This is possible by modifying just a couple of lines of code. First of all, to schedule a post, just set the posts’s date to whatever date you want the post to go out at (remember to set it both in the file name and in the “date:” meta inside the actual post). Then, we’ll want to edit the template files so it only shows posts that have their dates set to today or older. We’ll need to edit the “index.rhtml” file and the “index.builder” file (which generates the RSS).
In the “index.rhtml” template, edit the opening line of the posts loop (the default one will start something like “for article in articles…”) to read as:
<% articles.select {|a| a[:date] <= Date.today}[0...10].each do |article| %>
This will show the latest 10 articles on the index page, published today or earlier, but will not show any articles with a date set in the future. When that date arrives, they’ll automatically show up.
We’ll also want to edit the RSS builder to ensure the same thing happens with our RSS feed. Edit the “index.builder” file (it may be called “feed.builder”, in which case you should change it to “index.builder” as it needs to match the name of your index). If you’ve read the Feedburner section above, you saw me limit the number of posts to 10. Here I’ve got the same change incorporated, and I’m adding the date selection as well:
articles.select {|a| a[:date] <= Date.today}.reverse[0...10].each do |article| %>

Custom categories

Want to add custom categories to your posts? No problem, you can do this with the meta tags you add at the top of each post. The default tags are of course the title, date and the optional slug (permalink), but you can really add anything you like here. These tags are then accessible from your template files, allowing you to do some interesting things.
For example, over at UsabilityPost I’ve written a few book reviews. I don’t want my book reviews to show up together with normal blog posts, so I’ve given them a special category. The top of my book reviews' text files looks like this:
title: "Rocket Surgery Made Easy"
date: 2010/01/18
category: book
thumbnail: http://img.usabilitypost.com/books/rocketsurgery.png
book_author: Steve Krug
I’ve got a couple more tags in there, but you get the idea. I’m adding all the extra stuff I need about this type of post here, and I’m using the “category: book” as the key to sorting these types of posts on the index pages.
So for example, I’ve create a separate page to display the book reviews at. I’ve called it “books.rhtml” and put the new template in the “/templates/pages” folder. To show only the books posts I use the following loop:
<% @articles.select {|a| a[:category] == 'book' }[0...10].each do |article| %>
    <a href="<%= article.path %>"><%= article.title %></a>
    <img src="<%= article.thumbnail %>" />
    by <%= article.book_author %>
    etc ...
<% end %>
Basically, you open the loop by selecting just the book posts. You can then access their special tags by simply calling them out, like “article.thumbnail” or “article.book_author”. This gives you a lot of flexibility for setting up custom categories and types of posts on your blog.

Disqus comments

Because Toto doesn’t use a database, the commenting engine has to be outsourced. Disqus is a popular choice for this right now. By default Toto comes with Disqus support. Disqus integration itself is no hassle at all, it’s only a few lines of code pasted into your template files, so you may want to update the default code in Dorothy to the most recent code Disqus give you.
To get started with Disqus you’ll need an account, so head over to their site to get a free one. Once you set up an account, you’ll be provided with some code to paste into the templates (ignore the WordPress plugins and so on, and choose custom website integration in their information section). One bit of code goes in the bottom of “article.rhtml” template file (where you want the comments to be shown), and the other bit on the bottom of “layout.rhtml”, which will get you the comment counters.
I have a comment counter shown next to my post headline on the index page and on the article page. To do this simply append “#disqus_thread” to the end of the link. So the code for the comment counter/link would look like this:
<a href="<%= article.path %>#disqus_thread">0 Comments</a>
When you load the page, for a moment you’ll see everything as “0 Comments”. Once Disqus loads though, it will change all the counters to their proper values, and the link will point to the comments section of that particular post.

Blog configuration

All the settings for your blog are located in the “config.ru” file. There are some helpful comments there to tell you how to go about modifying the settings. The main configuration takes place in the format of:
set [:setting], [value]
So if you want to set the default blog author, you’d add the following line:
set :author, "Dmitry Fadeyev"
Now, if you don’t specify a blog author in the post meta, the default one will be used. The settings I’ve got for this blog look like this:
set :author, "Dmitry Fadeyev"
set :date, lambda {|now| now.strftime("%d %b %Y") }
set :summary, :max => 1000, :delim => /~\n/
set :disqus, 'fadeyev'
set :title, 'Dmitry Fadeyev'
set :url, 'http://fadeyev.net'
Note the “:delim” setting. This sets a delimiter for the post summary. To use this, I just type “~” at the end of a paragraph in a post, and add an extra line break afterwards. Everything before the delimiter becomes part of the post summary shown on the index page (called with “article.summary”). I’ve also customized the date to look how I want it. Here’s a list of the Ruby date symbols you can use to format the date.

www redirect

Want to redirect the “www” address of your blog to a non-www version? For example, for this blog, “www.fadeyev.net” redirects to “fadeyev.net”. To do this I use the rack-rewrite gem. First of all, you need to install the gem:
sudo gem install rack-rewrite
If you use Heroku, you’ll need to add the new gem to the “.gems” file in your blog’s directory. The .gems file will then look something like:
builder
rdiscount
toto
rack-rewrite
Finally, add the following code to your “config.ru” file, above the “run toto” line:
# Redirect www to non-www
gem 'rack-rewrite', '~> 0.2.1'
require 'rack-rewrite'
if ENV['RACK_ENV'] == 'production'
    use Rack::Rewrite do
        r301 %r{.*}, 'http://yoursite.com$&', :if => Proc.new {|rack_env|
        rack_env['SERVER_NAME'] != 'yoursite.com'
    }
    end
end
Change the two instances of “yoursite.com” above to your blog’s domain. You can also do it the other way around, i.e. redirect non-www requests to www. To do this just add www to the two instances of “yoursite.com”, making it “www.yoursite.com”.

Parting words

So if you’re not scared of the command line, I really urge you to give Toto a try. It has really simplified blog deployment and management for me. My posts are no longer tucked away in a database somewhere—they’re all backed up in a folder on my drive. There’s very little, if no, security risks, because Toto doesn’t have an admin panel or a database. Everything also gets cached, which makes this little engine extremely fast and flexible. To add to all of this, it’s very easy to modify the template files and you’ve got the power of Ruby on your side.

from http://fadeyev.net/getting-started-with-toto/

http://blog.jlank.com/ (一个基于toto的博客)

Friday 29 November 2013

MongoDB介绍以及Python的相关库

MongoDB是一个高性能,开源,无模式的文档型数据库,是当前NoSql数据库中比较热门的一种。MongoDB提供了比较丰富的数据库查询接口,是目前最接近关系数据库的NoSql数据库。
近两年MongoDB的发展速度非常的快,不少公司已经将MongoDB应用到实际产品中。在这些公司中最著名的应当是foursquare,国内的淘宝等公司也部分使用了MongoDB。MongoDB更完整的应用列表可以在MongoDB的Production Deployments(http://www.mongodb.org/about/production-deployments/)找到。
技术人员普遍有追新的爱好,看到一个不错的东西就想在自己的项目中用少。在对MongoDB做了些了解后,感觉使用MongoDB作为普通web应用的主数据库或许并不是一个很好的主意。
  • MongoDB的优势是速度以及海量数据的支持,另外一个有点就是schemeless。真正需要用到schemeless的地方似乎并不是太 多。目前很多 MongoDB 封装,也都增加了scheme的定义功能,基本上放弃了schemeless特性。另外如果过度的schemeless,日子久了后可能自己都搞不清楚自 己到底在数据库里放了什么东西。
  • MongoDB的特性决定了某些关系数据库很容易做的操作在MongoDB中会很不容易实现(比如多表关联查询等,而且据说分页性能也不怎么样?)。为配合MongoDB,在构架设计乃至产品功能需求方面都需要做些调整。
  • MongoDB的另外一个问题是太费内存,在内存不够大的时候性能很可能还不如mysql。所以有人称MongoDB是有钱人用的东西。
  • 可能大多人都不太会有机会遇到真正需要MongoDB的海量数据。
在V2EX上发了一个关于MongoDB的帖子(有谁在用 MongoDB 体验怎么样),引来不少关于MongoDB的吐槽。不是说MongoDB不够优秀。MongoDB有着自己特定的应用场景,如果只是为了尝鲜而贸然使用,可能并不会得到预想的效果。
下面简单的介绍一下MongoDB相关的一些Python库:
  • PyMongo MongoDB的Python接口开发包。PyMongo提供了最原始的MongoDB访问接口,其他的Python MongoDB库基本上都是基于该库进行开发的。
  • MongoEngine 为MongoDB提供了类似Django ORM的API。支持定义Scheme定义,同时提供DynamicDocument类用于支持schemeless。MongoEngine内置了 Django提供支持。如果你之前使用过Django,MongoEngine会让你觉得非常舒服。
  • MongoKit 和MongoEngine类似的一个库。个人更倾向于MongoEngine所以对MongoKit没有太多了解.

SpringSide2vik


 JAVA号称是要简化C++的复杂度,但事实上JAVA也并不简单。JAVA在发展过程中和C++一样走上了条复杂化的不归路。只是C++是语法的复杂,而JAVA是框架。
我一直认为,如果能对JAVA的那些框架进行一个有效的整合,JAVA的WEB开发可以简化很多。SpringSide2vik的出现就是为了实现这个整合。 SpringSide2vik是基于SpringSide2的一个quickstart,对springside2做了少量的修改。主要增加了一个代码生成器,实现由POJO生成完整的CRUD(浏览/添加/删除/修改),最大程度的简化重复劳动:)。
由于SpringSide2本身就是一个quickstart,因此也可以将SpringSide2vik看成是一个基于quickstart的quickstart。
相关链接:

DjangoSide


DjangoSide介绍

名字主要受springside( http://springside.org.cn/ )的启发,主要目的是实现一个基础的django脚手架。
Django是一个优秀的web开发框架,其app系统可以实现组件的高可重用性。但Django似乎没有一个比较严格的开发规范。
加上每个人对django的理解都不一样,使本该积木式的搭建变得不太可能。
这个djangoside可以看做是我对django开发模式的理解。
目前计划先完成一个基础的门户,实现用户的注册/登陆功能,并演示如何与一个第三方的blog模块进行整合。

目录结构

  • djangoside 主项目文件
  • pylogs blog系统(这个blog系统为denghaibo开发,项目地址http://code.google.com/p/pylogs/
  • registration 一个第三方的app,实现注册功能(http://code.google.com/p/django-registration/
  • media 存放静态资源文件
  • scripts 一些辅助性脚本
    • clear.bat 清除python编译的中间文件
    • clear_svn.bat 删除svn信息(注:直接运行bat似乎无法正常工作,切换到控制台复制bat内的命令并执行)
    • init_prj.bat 初始化主项目,将各个工程的静态文件复制到主目录中
    • runserver.bat 启动开发服务器
    • syncdb.bat 初始化数据库

DjangoSide HOW TO

其中djangoside目录和pylogs目录为两个独立的Django工程,这两个工程都可以独立运行(执行各自scripts目录中的脚本syncdb.bat/runserver.bat)。
同时,根目录下的scripts目录通过使用同一配置文件,并配置urls转发的功能,将这两个独立的工程统一到同一项目下(执行根目录下的scripts里的脚本init_prj.bat/syncdb.bat/runserver.bat)

from http://code.google.com/p/djangoside/

用python+django搭建的论坛-lbforum

https://github.com/vicalloy/LBForum
https://github.com/vicalloy/lbforum-site
http://code.google.com/p/lbforum/

简介

LBForum 用django开发的论坛系统,
项目的地址为:http://github.com/vicalloy/LBForum
界面部分抄的 FluxBB(一个开源的PHP论坛 http://fluxbb.org/ )。
虽然Django写的论坛也不少,不过还真没什么好用的。
大多Django论坛都是独立的app,而且不少还缺模板,想我这样有经验的Django用户要跑起来都觉得麻烦,其他普通用户就更别说了。
LBForum主要注重部署的方便性和易用性,功能方面目前还比较简单。
LBForum一开始就是以整站的形式提供,所以以LBForum做为基础项目进行二次开发是很容易的。
同时LBForum的开发尽量遵照Django可复用app原则,因此即使需要将LBForum做为独立的app集成到其他项目也并不会太难。

主要功能

目前功能还比较简单,而且还有些小问题有待修正。
  1. 论坛分类,分版块
  2. 发帖,回帖
  3. BBCode支持
  4. 置顶贴
  5. 使用django admin提供论坛管理功能

用开发服务器把LBForum跑起来

  1. 先把代码down下来。LBForum托管在github上,http://github.com/vicalloy/LBForum 。如果你没有安装git,你可以直接用界面右上方的download
    source功能下载代码。
  2. 运行\scripts\create_lbforum_env.py初始化lbforum的python虚拟环境。该脚本会自动创建一个python的虚拟环境并使用easy_install安装对应的依赖包,同时将一些依赖包解压到对应的目录中。
    注:django使用的是svn版本,所以机器上必须要安装有SVN,不然脚本会运行失败。如果因为由于svn的问题导致脚本运行失败,可以运行lbforum_env.bat进入lbforum环境,手动安装django的svn版本。
  3. 环境初始化好后,运行lbforum_env.bat进入lbforum环境
  4. 运行%mg% syncdb初始化数据库
  5. 运行%mg% runserver启动django开发服务器
  6. 进入admin,创建论坛分类和版块
  7. 进入版块发帖

LBForum的目录结构说明

|+lbforum_env/#lbforum运行的python虚拟环境,运行create_lbforum_env.py后自动创建
|+requirements/#lbforum用的第三方库和app,运行的时候会将该目录加到python路径
|~scripts/#工程相关脚本
| |-create_lbforum_env.py#初始化python虚拟环境,并自动安装easy_install/django依赖库
| |-helper.py#提供其他脚本所需的辅助函数
| -lbforum_env.bat*#启动lbforum运行的虚拟环境及,并为lbforum的manage.py提供快捷方式%mg%,比如初始化数据库%mg%
syncdb
|~sites/#站点配置/模板/静态文件
|
~default/#默认站点
|   |+static/#静态资源文件,如css等
|   |+templates/#Django模板目录
|   |+templates_plus/#Django模板目录,用户将自己重写过的目标放到该目录
|   -......
|~src/#django的app目录
| |+account/#account相关app。具体站点通常会对用户中心进行定制,所以该app在实际应用中很可能需要针对实际情况进行修改。
| |+djangohelper/#一些django的辅助函数等,
| |+lbforum/#lbforum的主app,论坛功能都在改app中
| |+lbregistration/#registration app的lbforum扩展,主要去掉邮件地址认证功能
| |+onlineuser/#显示在线用户的app(可复用的django app,可脱离lbforum单独使用)
|
+simpleavatar/#头像功能的app(可复用的django app,可脱离lbforum单独使用,依赖djangohelper)
|+tools/#工程用到的辅助工具,目前只有一个virtualenv的脚本

注:

  1. 由于计划在以后做i18n,所以目前只提供英文界面
  2. django的错误提示是显示在字段后面,fluxbb的错误全部都显示在表单前面。由于模板没有调好,所以目前按照fluxbb的方式显示错误,所以错误显示有些不太正常。
  3. bbcode的输入框本想做成自适应大小的,不过也调得有些问题,所以现在输入框的大小固定。
  4. 文档… ,感觉好难写-_-,目前文档不全(项目中没有带任何的文档),日后补上。
  5. 应用程序的目录结构主要查看pinax
  6. simpleavatar模块部分代码来自django-avatar
  7. 依赖包除用easy_install在线安装的外,尽量使用zip包的方式附带在项目中,减少安装依赖包的困难。
  8. 远程部署脚本计划使用fabric,但fabric本身安装比较麻烦,所暂未处理.


与java开发相关的2款工具-Eclipse 和Netbeans


我对Eclipse一直都颇有微词,但Eclipse的优点还是很明显的,长得够漂亮,而且我用了这么久,很多使用习惯还不是这么容易改的。很多用 Eclipse做J2EE开发的人都会使用myeclipse,不过我没用。主要是觉得用个免费软件,再去用个D版的插件,实在有些别扭。 官网


Netbeans确实是一个不错的Java开发环境,特别是它的swing界面设计器给了我很大的好感。我觉得netbeans的界面设计器在某些地方甚 至比Delphi还要方便。也尝试将Java的开发环境切换到Netbeans上,但发现使用习惯还是很主要,有些地方还是不太习惯。 官网

UliPad- 国产的python开发工具

我现在python主要就用这东西了(有时候改代码用VIM)。 官网

What is UliPad

Ulipad is a wxPython powered, programmer oriented and flexible editor. It has many features such as class browser, code auto-complete, html viewer, directory browser, wizard and many others. The most interesting and distinctive feature is the use of mixin technique which makes Ulipad an easy-to-extend programming environment. You can write your own mixins, plugins or simple scripts, and all of them can be integrated in Ulipad in a seamless way.

Why named it UliPad?

The name comes from Claudio Grondi (thank you!).
Claudio Grondi said:
As we are on the way to make NewEdit THE programmer editor I think, that
a new unique name will help here much (NewEdit is just cheap...).

I suggest to use 'UliPad'.
It has the shortcut of UnLImited.
It tells it is a plain text editor (Pad).
It tells something about the original author (LImodou).
But the most important advantage is:
 
    Google has no entry for 'UliPad' yet!
Wonderful! It seems many people like it.

Description

UliPad uses Mixin and Plugin technique as its architecture. Most of its classes can be extended via mixin and plugin components, and finally become an integrity class when creating the instance. So UliPad is very dynamic. You can write the new features in new files, and hardly need to modify the existing code. And if you want to extend the existing classes, you could write mixins and plugins, and this will be bound to the target class that I call "Slot Class". This technique will make the changes centralized and easily managed.
Requirements:
  • Python 2.3+
  • wxPython 2.4.2.4+ Unicode Version
Recommends:
  • Python 2.4+
  • wxPython 2.8+ Unicode Version
Some plugins may have additional requirements, please read the readme information before installing them.

Objective

Make a clean, powerful, flexible general editor, and even an application framework. And adding extensions should be very easy.
Tasks:
  • Mixin and Plugin framework
  • Unicode support
  • User defined plugin management
  • User custom window integration
  • User custom wizard function 
from http://code.google.com/p/ulipad/
程序作者的博客:http://hi.baidu.com/limodou


 

Mac初体验

初次使用Mac下倒也没感到什么太多的不适应。如果说真有什么不适应,主要还是一些windows下的软件没有Mac版,或是Mac版的功能要比windows版的简陋很多。
下面推荐些Mac下的软件
  • TotalTerminal
    命令行增强工具。增加多Tab功能,多个配色方案可选。
  • 启用命令行颜色显示
    在linux下不同类型的文件会以不同颜色显示,Mac下没有默认开启该功能。
  • 安装 brew 为Mac增加类似apt-get的功能。

让你的python程序同时兼容python2和python3

python邮件列表里有人发表言论说“python3在10年内都无法普及”。在我看来这样的观点有些过于悲观,python3和 python2虽然不兼容,但他们之间差别并没很多人想像的那么大。你只需要对自己的代码稍微做些修改就可以很好的同时支持python2和 python3的。下面我将简要的介绍一下如何让自己的python代码如何同时支持python2和python3。
  • 放弃python 2.6之前的python版本
    python 2.6之前的python版本缺少一些新特性,会给你的迁移工作带来不少麻烦。如果不是迫不得已还是放弃对之前版本的支持吧。
  • 使用 2to3 工具对代码检查
    2to3是python自带的一个代码转换工具,可以将python2的代码自动转换为python3的代码。当然,不幸的是转换出的代码并没有对python2的兼容做任何的处理。所以我们并不真正使用2to3转换出的代码。执行 2to3 t.py 查看输出信息,并修正相关问题。
  • 使用python -3执行python程序
    2to3 可以检查出很多python2&3的兼容性问题,但也有很多问题是2to3发现不了的。在加上 -3 参数后,程序在运行时会在控制台上将python2和python3不一致,同时2to3无法处理的问题提示出来。比如python3和python2中 对除法的处理规则做过改变。使用-3参数执行4/2将提示 DeprecationWarning: classic int division 。
  • from __future__ import
    from __future__ import”后即可使使用python的未来特性了。python的完整future特性可见 __future__ 。python3中所有字符都变成了unicode。在python2中unicode字符在定义时需要在字符前面加 u,但在3中则不需要家u,而且在加u后程序会无法编译通过。为了解决该问题可以 “from future import unicode_literals” ,这样python2中字符的行为将和python3中保持一致,python2中定义普通字符将自动识别为unicode。
  • import问题
    python3中“少”了很多python2的包,在大多情况下这些包之是改了个名字而已。我们可以在import的时候对这些问题进行处理。
  • 使用python3的方式写程序
    python2中print是关键字,到了python3中print变成了函数。事实上在python2.6中已经带了print函数,所以对 print你直接按照2to3中给出的提示改为新写法即可。在python3中对异常的处理做了些变化,这个和print类似,直接按照2to3中的提示 修改即可。
  • 检查当前运行的python版本
    有时候你或许必须为python2和python3写不同的代码,你可以用下面的代码检查当前系统的python版本。
  • six
    six 提供了一些简单的工具用来封装 Python 2 和 Python 3 之间的差异性。我并不太推荐使用six。如果不需要支持python2.6之前的python版本,即使不用six也是比较容易处理兼容性问题的。使用 six会让你的代码更像python2而不是python3。
python3的普及需要每位pythoner的推动,或许你还无法立即升级到python3,但请现在就开始写兼容python3的代码,并在条件成熟时升级到python3。
注:

Python LiveReload


LiveReload Server in Python Version.
Web Developers need to refresh a browser everytime when he saved a file (css, javascript, html), it is really boring. LiveReload will take care of that for you. When you saved a file, your browser will refresh itself. And what's more, it can do some tasks like compiling less to css before the browser refreshing.

Installation

Python LiveReload is designed for web developers who know Python.

Install python-livereload

Install Python LiveReload with pip:
$ pip install livereload
If you don't have pip installed, try easy_install:
$ easy_install livereload

Install Browser Extensions

A browser extension is not required, you can insert a script into your html page manually:
<script type="text/javascript" src="http://127.0.0.1:35729/livereload.js"></script>
But a browser extension will make your life easier, available extensions:
  • Chrome Extension
  • Safari Extension
  • Firefox Extension
Visit: http://help.livereload.com/kb/general-use/browser-extensions

Quickstart

LiveReload is designed for more complex tasks, not just for refreshing a browser. But you can still do the simple task.
Assume you have livereload and its extension installed, and now you are in your working directory. With command:
$ livereload [-p port]
your browser will reload, if any file in the working directory changed.

LiveReload as SimpleHTTPServer

Livereload server can be a SimpleHTTPServer:
$ livereload -p 8000
It will set up a server at port 8000, take a look at http://127.0.0.1:8000. Oh, it can livereload!
IF YOU ARE NOT USING IT AS A HTTP SERVER, DO NOT ADD THE PORT OPTION.

Guardfile

More complex tasks can be done by Guardfile. Write a Guardfile in your working directory, the basic syntax:
#!/usr/bin/env python
from livereload.task import Task

Task.add('static/style.css')
Task.add('*.html')
Now livereload will only guard static/style.css and html in your workding directory.
But python-livereload is more than that, you can specify a task before refreshing the browser:
#!/usr/bin/env python
from livereload.task import Task
from livereload.compiler import lessc

Task.add('style.less', lessc('style.less', 'style.css'))
And it will compile less css before refreshing the browser now.

Linux

If you're using python-livereload under Linux, you should also install pyinotify, as it will greatly improve responsiveness and reduce CPU load.
You may see errors such as:
[2013-06-19 11:11:07,499 pyinotify ERROR] add_watch: cannot watch somefile WD=-1, Errno=No space left on device (ENOSPC)
If so, you need to increase the number of "user watches". You can either do this temporarily by running (as root):
echo 51200 > /proc/sys/fs/inotify/max_user_watches
To make this change permanent, add the following line to /etc/sysctl.conf and reboot:
fs.inotify.max_user_watches = 51200

Others

If you are on a Mac, you can buy LiveReload2.
If you are a rubist, you can get guard-livereload.

from https://github.com/lepture/python-livereload

相关帖子:http://briteming.blogspot.co.uk/2013/10/livereload.html

在linux vps上安装基于python+django的博客程序-dpress

git clone https://github.com/vicalloy/DPress.git dpress
cd dpress
pip install -r requirements.txt (安装必要的python模块)
cd sites
python manage.py syncdb
python manage.py migrate
python manage.py runserver > /dev/null &
(这命令是运行在默认的8000端口。如果想运行在其他端口,比如56477,则
nohup python manage.py runserver 0.0.0.0:56477 > /dev/null &)
立马可以访问http://as3.brite.biz:56477/,后台地址:http://as3.brite.biz:56477/admin
默认用户名为root.
它的数据库是sqlite.无需操心数据库问题。

其他配置
config
    copy sites/settings/pre.sample to sites/settings/pre.py and config it.
    copy sites/settings/local.sample to sites/settings/local.py and config it.

use theme moment
    moment is a theme designed by Hsiaoming Yang
    copy sites/settings/pre.sample to sites/settings/pre.py
    modify pre.py and set "SETTINGS = 'theme_moment'"

演示站点:http://as3.brite.biz:56477/
项目地址:https://github.com/vicalloy/DPress


从备份的文件还原网站数据后, SELinux 导致 httpd(apache2) 无法启动

SELinux 是美国国安局开发的一个能有效增强 Linux 安全性的套件,现在现在很多 Linux 发行版都默认集成。这个东西用好了能极大的增强服务器性能,然而,有时候也会带来一些不便和困惑。如果对它不了解的话,有时候出的问题甚至能把人搞迷糊 了。建议大家去了解一下它,至少要知道它的用途、如何禁用、启用它,和由它引发的一些常见问题,以免碰到了一些由它引发的问题的时候一头雾水,不知所措。
比如我今天碰到这这个问题,要是事先不知道 SELinux 的话,估计会把人搞疯了,不过好在哥们我比较 professional,哪能随便被一些小 case 磕倒啊,哈哈  :-)
今天的事情是这样的,我今天把服务器重装了,重装好了以后把之前做好的网站备份还原到了新系统上,但启动 httpd 时报错,提示:
[root@www vhosts]# service httpd restart
Stopping httpd:                                            [  OK ]
Starting httpd: Syntax error on line 290 of /etc/httpd/conf/httpd.conf:
DocumentRoot must be a directory
[FAILED]
我看了下配置文件,DocumentRoot 指向的目录确确实实是存在的,权限设置也是没问题的,但 apache 就是不认,WTF????
反复确认了几次后,我100%确认配置是没有问题的,权限也是没有问题的,那会是什么原因捏~~ SELinux,只有这个可能了。先确认一下:
[root@www vhosts]# ls -Z
drwxr-xr-x  root  root  root:object_r:user_home_t www.mydomain.com
[root@www vhosts]# grep denied /var/log/audit/audit.log
type=AVC msg=audit(1278157850.075:163): avc:  denied { search } for  pid=10100 comm=”httpd” name=”vhosts” dev=dm-1 ino=4391538 scontext=root:system_r:httpd_t:s0 tcontext=root:object_r:user_home_t:s0 tclass=dir
看到没,文件夹的 SELinux 属性必须是 httpd_sys_content_t 才能被 web 服务器访问,但现在却是 user_home_t
[root@www vhosts]# cd ..
[root@www www]# chcon -R -t httpd_sys_content_t vhosts/
检查一下结果:
[root@www www]# ls -Z vhosts/
drwxr-xr-x  root  root  root:object_r:httpd_sys_content_t www.mydomain.com
好了,已经正确改回来了,重启下 httpd:
[root@www www]# service httpd start
Starting httpd:                                            [  OK ]
OK,访问一下网站,也能正常访问了。
总结:
当时我是先把备份文件解压到自己的用户目录下,结果就被自动设置上了 user_home_t 属性,把移动到网站目录下后,没有被重新设置为 httpd_sys_content_t 属性,导致 httpd (以 apache 用户身份启动) 无权限访问该文件夹。使用 chcon 修改属性为 httpd_sys_content_t 后,httpd 即可以正常访问,问题解决。

一个用 PHP 写的 Memcache 管理器

查看 memcache 服务器状态的最简单的办法是直接 telnet 上去:
[liang@iMac: ~]$ telnet localhost 11211
Trying ::1…
Connected to localhost.
Escape character is ‘^]’.
stats
STAT pid 6404
STAT uptime 8865
STAT time 1279025383
STAT version 1.2.8
……
END
但这个结果实在是太简陋了,很不直观。而且有些情况下是无法使用 telnet 连接 memcache 服务器的(比如在外网),这时候如果有一个像 PhpMyAdmin 那样的 Web 程序来管理 memcache 服务器的话,是一件非常方便的事情。
我在网上找了找,找到了这个 memcache 管理程序直接下载连接),该程序主要的功能有:
  1. 管理多个 memcache 服务器
  2. 实时查看各个服务器的内存使用状况
  3. 实时查看缓存命中情况
  4. 直接浏览缓存内容,删除指定缓存项
  5. 等等等。。。自己发掘吧
该程序只有一个 php 文件,使用非常方便,只要把它上传到网站上任意一个能访问到的地方就行了。
使用方法:
下载后解压,使用文本编辑器打开 memcache.php,根据自己的情况修改用户名密码和 memcache 服务器地址:
define(‘ADMIN_USERNAME’,'admin’);     // Admin Username
define(‘ADMIN_PASSWORD’,'adminpassword’);    // Admin Password
define(‘DATE_FORMAT’,'Y/m/d H:i:s’);
define(‘GRAPH_SIZE’,200);
define(‘MAX_ITEM_DUMP’,50);
$MEMCACHE_SERVERS[] = ‘localhost:11211′; // add more as an array
//$MEMCACHE_SERVERS[] = ‘mymemcache-server2:11211′; // add more as an array
然后把 memcache.php 上传到网站,使用浏览器打开就可以看到 memcache 服务的状态。

SELinux 导致 PHP 无法使用 fsockopen 连接到Memcached 服务器

使用 memcache.php 来监控 Memcache 状态。然而却发现该工具无法连接上 Memcached 服务器。经检查,Memcached 服务器已经正常启动,使用 telnet 能够正常连接上去,使用 Memcached 的应用程序(PHP程序)也正常工作。查看 memcache.php 代码发现其是使用 fsockopen 来连接 Memcached 服务器,遂怀疑 Socket 扩展的问题。然而,检查发现可以在命令行中使用 fsockopen 连接到任意地址的任意端口,说明 Socket 扩展没问题。但在 httpd 中使用 fsockopen 来就只能连接本机的 80、8080、443 端口,连接其他端口均失败。

检查 httpd 的 log 也没发现任何问题。上网搜索也没发现类似问题,郁闷ing……

于是又想到是否是 SELinux 的问题。grep 了下 /var/log/audit/audit.log,发现以下线索:



    [liang@www ~]$ sudo grep denied /var/log/audit/audit.log

    type=AVC msg=audit(1280882021.681:780): avc:  denied  { name_connect } for  pid=3822 comm="httpd" dest=11211 scontext=user_u:system_r:httpd_t:s0 tcontext=system_u:object_r:http_cache_port_t:s0 tclass=tcp_socket
    type=AVC msg=audit(1280885410.800:805): avc:  denied  { name_connect } for  pid=3790 comm="httpd" dest=11211 scontext=user_u:system_r:httpd_t:s0 tcontext=system_u:object_r:http_cache_port_t:s0 tclass=tcp_socket

看来又是 SELinux 搞的鬼。继续检查,发现 /var/log/messages 有以下错误信息:

    Aug  4 08:11:59 www setroubleshoot: SELinux is preventing the http daemon from connecting to the itself or the relay ports For complete SELinux messages. run sealert -l 23d1381f-9d4b-439a-9ad6-d52f1025f247

果然是 SELinux 引起的问题。根据提示继续检查:

    [liang@www ~]$ sealert -l 23d1381f-9d4b-439a-9ad6-d52f1025f247

    Summary:

    SELinux is preventing the http daemon from connecting to the itself or the relay
    ports

    Detailed Description:

    SELinux has denied the http daemon from connecting to itself or the relay ports.
    An httpd script is trying to do a network connect to an http/ftp port. If you
    did not setup httpd to network connections, this could signal a intrusion
    attempt.

    Allowing Access:

    If you want httpd to connect to httpd/ftp ports you need to turn on the
    httpd_can_network_relay boolean: "setsebool -P httpd_can_network_relay=1"

    The following command will allow this access:

    setsebool -P httpd_can_network_relay=1

    Additional Information:

    Source Context                user_u:system_r:httpd_t
    Target Context                system_u:object_r:http_cache_port_t
    Target Objects                None [ tcp_socket ]

    ———————省略若干输出———————

错误信息说得很明了了:SELinux 阻止了 httpd 的连接。修改方式也给出来了,以 root 身份运行以下命令即可:

    [liang@www ~]$ sudo /usr/sbin/setsebool -P httpd_can_network_relay=1

注意该命令成功运行后没有任何输出。要检查是否设置成功,可以查看运行 getsebool 命令或者直接查看 log:

    [liang@www ~]$ /usr/sbin/getsebool httpd_can_network_relay
    httpd_can_network_relay –> on

    [liang@www ~]$ sudo tail /var/log/messages

    Aug  4 10:50:23 www setsebool: The httpd_can_network_relay policy boolean was changed to 1 by root

设置成功了。重新刷新下 memcache.php, 发现已经能够正常工作了。

在linux vps上搭建基于python的静态博客程序-chisel

git clone https://github.com/dz/chisel.git
cd chisel
as3:~/chisel# ls
chisel.py  contents  export  README  templates
as3:~/chisel# nano chisel.py
(可以修改主页显示的条目的数目:
HOME_SHOW = 5 #numer of entries to show on homepage )
as3:~/chisel# cd export
as3:~/chisel/export# ls
2013  archives.html  index.html
as3:~/chisel/export#
(可见~/chisel/export就是静态网站的根目录)
as3:~/chisel/export# cd ../contents/
as3:~/chisel/contents# nano test1.md
格式如下:
test1 (标题不能为中文)
11/29/2013

这是测试1.


然后:
as3:~/chisel/contents# cd ..
as3:~/chisel# python chisel.py (这个就是更新静态网站的命令)

演示站点:http://as3.brite.biz:23487/,Http://cs.brite.biz
项目地址:https://github.com/dz/chisel

sourceforge上的博客程序

http://sourceforge.net/directory/internet/www/dynamic/blogging/os:windows/freshness:recently-updated/

在linux vps上搭建基于PERL的静态博客程序-BAZINGA

mkdir ~/.bazinga/
cd  ~/.bazinga/
git clone  https://github.com/ap0calypse/bazinga.git
cd bazinga
as3:~/.bazinga/bazinga# ls
AUTHORS  bzg   examples  LICENSE  README 
as3:~/.bazinga/bazinga# ln -s ~/.bazinga/bazinga/bzg /usr/local/bin/bzg
as3:~/.bazinga/bazinga# cp examples/* ~/.bazinga/bazinga
 as3:~/.bazinga/bazinga# ls
AUTHORS  bzg  example-config  examples  index.template LICENSE  README  style-improved.css
as3:~/.bazinga/bazinga# cp  example-config  ~/.bazinga/bazinga.conf
as3:~/.bazinga/bazinga# cp style-improved.css   ~/.bazinga/style.css
as3:~/.bazinga/bazinga# cp  index.template   ~/.bazinga/index.template
as3:~/.bazinga/bazinga# cd  ~/.bazinga/                                      
as3:~/.bazinga# nano  bazinga.conf
as3:~/.bazinga# cat  bazinga.conf
显示:
# bazinga configuration file

# user identification
BLOG_OWNER: "ym"
BLOG_EMAIL: "xx@12.com"
BLOG_WEBSITE: "http://bzg.brite.biz"  (此处改为自己的域名地址)

# directory where the local bazinga structure is created
BLOG_DIRECTORY: "/root/bazinga-blog"  (此处指定创建博客的根目录的地方)

# blog title
BLOG_TITLE: "ym's bazinga blog"

# blog subtitle
BLOG_SUBTITLE: "it is only half the truth ..."

# other stuff
# max entries of articles on main page
MAX_ARTICLES_MAIN: "5"

# color theme for syntax highlighting
# for a complete list, execute "highlight --list-themes"
HIGHLIGHT_THEME: "zenburn"

# blog look and feel
LATEX_FGCOLOR: "rgb 1.0 1.0 1.0"
LATEX_BGCOLOR: "Transparent"
LATEX_DPI: "150"

# FTP push information
PUSH_HOST: "YOUR_HOSTNAME"
PUSH_LOGIN: "YOUR_USERNAME"
PUSH_PASSWD: "YOUR_PASSWORD"
PUSH_PATH: "/PATH/TO/FTPDIR"
PUSH_PORT: "21"

as3:~/.bazinga# bzg (查看bzg的用法)

发贴方法:(分为3步)
as3:~/.bazinga# bzg generate article > test4.txt
(在当前目录下,会生成test4.txt)
as3:~/.bazinga# nano test4.txt
as3:~/.bazinga# cat test4.txt
category: "articles"
title: "test4(测试4)" (标题不支持纯中文。可先写英文,再写中文)
author: "ym"
website: "http://bzg.brite.biz"
email: "xx@12.com"
date: "2013-11-29"
time: "14:35"
tags: "misc"
START_TEXT
这是测试4.    (这是正文)
END_TEXT  (这里
START_TEXT和END_TEXT不要删除。正文就写在这2者的中间)

as3:~/.bazinga# bzg add test4.txt
 >> Content file seems to be correct.
 >> Added 'fa17db6884183b40' to articles.
as3:~/.bazinga#
bzg update

as3:~/.bazinga# cd  /root/bazinga-blog
as3:~/bazinga-blog# ls
articles  css  feed.xml  index.html  pages  tags
可见 ~/bazinga-blog/果然是静态网站的根目录。

演示站点:http://bzg.brite.biz/
项目地址:https://github.com/ap0calypse/bazinga

注意:博客的首页只能显示最近5篇文章,更多的文章不能显示。它也没有分页功能。要查看最近5篇文章之前的文章 ,可点击首页右上角的get feed链接,通过feed reader去查看。



在linux vps上,搭建基于python3+jdk1.7的静态博客程序-chaosblog


首先你要编译python3环境,
需先编译python3.3.3环境:

wget http://python.org/ftp/python/3.3.3/Python-3.3.3.tar.bz2
tar jxvf Python-3.3.3.tar.bz2 
cd Python-3.3.3
./configure --prefix=/usr/local/python-3.3.3
make           
make install
ln -s /usr/local/python-3.3.3/bin/python3.3 /usr/local/bin/python3.3

还要安装python3.3的markdown模块:
# wget http://python-distribute.org/distribute_setup.py
# python3.3 distribute_setup.py
(这2步是安装easy_install程序)
会显示:
 ...
Installing easy_install script to /usr/local/python-3.3.3/bin
Installing easy_install-3.3 script to /usr/local/python-3.3.3/bin
...
# /usr/local/python-3.3.3/bin/easy_install-3.3 markdown
/usr/local/python-3.3.3/bin/easy_install-3.3 pip)


然后是安装jdk1.7,运行java -version
须显示
java version "1.7.0_03"。我机子上运行java -version后,显示openjdk1.6,这是不行的。解决办法:
mv /usr/bin/java /usr/bin/java-openjdk-version
ln -s /root/jdk1.7.0_03/bin/java /usr/bin/java
( jdk1.7.0_03的压缩包文件请到www.oracle.com去下载)

git clone https://github.com/chaopeng/chaosblog.git
cd chaosblog
as3:~/chaosblog# ls
builder  LICENSE  publish  README.md  to-be-publish
as3:~/chaosblog# cd to-be-publish
as3:~/chaosblog/to-be-publish# ls
buildBlog.bat  _component          index.html  navibar
buildblog.sh   _config.json        _layout     post
chaosblog.jar  _config_linux.json  log.log     _template
as3:~/chaosblog/to-be-publish# ./buildblog.sh
2013-11-29 10:12:56 INFO [main] [main.ChaosBlog] - start...
2013-11-29 10:12:58 INFO [main] [main.ChaosBlog] - output finish
as3:~/chaosblog/to-be-publish# nano _config_linux.json (编辑配置文件)
as3:~/chaosblog/to-be-publish# cat _config_linux.json
显示:
BlogConfig
{
        site: "chaosblog.brite.biz",  (这里英文双引号里替换为你的域名)
        path: "/blog", (这里path的值不能为/,必须为某个子目录,比如/blog)
        author: "ym",
        blogname: "ym的Pensive",
        # set the markdown engine which you like
        markdownengine: "/usr/local/python-3.3.3/bin/python3.3 -m markdown -x toc -x footnotes -x fenced_code -x tables",
        inputpath: "/root/chaosblog/to-be-publish",
        outputpath: "/root/chaosblog/publish/" (这里不要加英文逗号)
}
...
(这里/root/chaosblog/publish/就是静态网站的根目录)
as3:~/chaosblog/to-be-publish# mkdir /root/chaosblog/publish/blog
as3:~/chaosblog/to-be-publish# cd /root/chaosblog/publish/
as3:~/chaosblog/publish# ls
blog
as3:~/chaosblog/publish# git clone https://github.com/chaopeng/chaopeng.github.com.git
as3:~/chaosblog/publish# cd chaopeng.github.com
as3:~/chaosblog/publish/chaopeng.github.com# ls
assets CNAME httpserver.bat index.html
blog favicon.ico httpserver.sh publish.sh
as3:~/chaosblog/publish/chaopeng.github.com# mv assets ~/chaosblog/publish/
as3:~/chaosblog/publish/chaopeng.github.com# cd ~/chaosblog/publish/
as3:~/chaosblog/publish# ls
assets  blog chaopeng.github.com
as3:~/chaosblog/publish# rm -rf chaopeng.github.com
as3:~/chaosblog/publish# nano index.html
(新建一个跳转用的index.html,这样访问静态网站的根目录~/chaosblog/publish/时,就会跳转到~/chaosblog/publish/blog/)
as3:~/chaosblog/publish# cat index.html
<meta HTTP-EQUIV=REFRESH CONTENT="0;URL=http://chaosblog.brite.biz/blog/">
as3:~/chaosblog/publish# ls
assets  blog  index.html
as3:~/chaosblog/publish# cp index.html assets/
(复制index.html到assets目录,这样当有人访问http://chaosblog.brite.biz/assets时,这样就会跳转到
http://chaosblog.brite.biz/blog/,从而保护~/chaosblog/publish/assets/不被人访问)

发贴方法:
as3:~/chaosblog/publish# cd ~/chaosblog/to-be-publish/post/
as3:~/chaosblog/to-be-publish/post# ls
2013-01-05-test-markdown.md 2013-01-06-why-chaosblog.md
按2013-01-05-test-markdown.md的格式,新建帖子2013-11-29-test1.md,格式如下:
{
layout: "pages",
title: "测试1",
category: "misc",
tags: ["test"]
}

这是测试1.


然后:
as3:~/chaosblog/to-be-publish/post# cd ..
as3:~/chaosblog/to-be-publish# ./buildBlog.sh (这个就是生成/更新静态网站的命令)

演示站点:http://chaosblog.brite.biz/
项目地址:https://github.com/chaopeng/chaosblog



苑中之兰

苑中之兰独吐芳,伊人伫立盼郎君。
郎君,郎君你在哪?嗯,god knows.
---------------------
高,实在是高