Python: String split and for each

Categories: Python; Tagged with: ; @ April 23rd, 2014 0:49

This example shows how to split string and do for…each in Python:

>>> rawTags = 'TAG1 TAG2 TAG3 TAGB1 TAGB2'
>>> tags = rawTags.split()
>>> tags
['TAG1', 'TAG2', 'TAG3', 'TAGB1', 'TAGB2']
>>> output = ''
>>> for tag in tags:
... output += '"' + tag + '",'
>>> output
'"TAG1","TAG2","TAG3","TAGB1","TAGB2",'

Haskell helloworld

Categories: Development Notes; Tagged with: ; @ April 23rd, 2014 0:35

Install Haskell in Linux/Mint

sudo apt-get install haskell-platform

Hello World

GDEV guoliangDev # ghci
GHCi, version 7.6.3: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude> putStrLn "hello, world"
hello, world

Simple Function

Prelude> let sayHi name=putStrLn("Hi " ++ name)
Prelude> sayHi "Li"
Hi Li

Put the function into .hs file
example: main = putStrLn(“hello World!”)

Compile & execute :

GDEV helloWorld # vi sayHi.hs
GDEV helloWorld # ghc -o sayHi sayHi.hs 
[1 of 1] Compiling Main ( sayHi.hs, sayHi.o )
Linking sayHi ...
GDEV helloWorld # ./sayHi 
hello World!

How to quit/exit ghci?

Prelude> :quit
 Leaving GHCi.

Links

Input and Output: http://learnyouahaskell.com/input-and-output
Haskell in 5 steps:  http://www.haskell.org/haskellwiki/Haskell_in_5_steps

Ayutthaya 大城游记

Categories: 垃圾山; Tagged with: ; @ April 22nd, 2014 23:38

除了它本身, 选择去Ayutthaya的理由:

1. 离曼谷很近, 约80KM, 交通方便;
2. 没有很多游客;

IMGP6370

交通及住宿

WikiTravel.org 上已有详细介绍: http://wikitravel.org/en/Ayutthaya

我的:

上午到BKK机场, 出海关后问了下info center的人去除了火车站还能在哪买票; 当他了解到我要去Ayutthaya之后, 立刻建议我去Victory Monument [Google Map] 附近坐MiniVan, 大概只需1.5Hrs;

但我是个固执的人, 非要坐火车, 于是:

1. 火车:

列车表可以从泰国铁路网站找到: // 注意: 已经停止网络售票

http://www.thairailticket.com/esrt/Default.aspx?language=1

从BKK坐Airport LinkMakkasan换MRT坐到HuaLamphong / 火车站;

买了一张109去Ayutthaya的三等座: 20 Baht, 没有固定座位, 没有空调;

但是在曼谷市内停靠几乎所有的大小车站, 车速很慢, 大概花了2.5Hrs才到Ayutthaya;

2. Minivan

临走时问了下客栈的小妹, 做Minivan是最方便快速的交通方式,  60 Baht, 1.5Hrs,  在7-11斜对面.  大概有15座,  还不错;

住宿

Agoda上定的Tamarind Guesthouse, 还不错. 木结构小楼, 走路会嘎吱嘎吱响,  晚上还比较安静. 交通位置极好, 对面出门过马路就是Ayutthaya Historical Park.

注意

自行车

据说多数客栈都会有自行车出租服务, 大概50 Baht/天, 街边也会有很多店铺出租自行车.

由于Ayutthaya很小, 所以自行车足够, 但是, 请务必注意野狗!!:

在Ayutthaya左下角, Somdet Phra Srinakaindra Park附近时遭到野狗追击, 换了车道逆行才得以脱险…

Ayutthaya has a lot of hungry stray dogs in poor condition. They can particularly be a problem in the off-season when there aren’t so many people in the streets. While largely docile and harmless, to avoid being chased around by a pack of them it is best not to walk around alone, particularly at night. For those accustomed to travel in developing areas, there should be no problem.

When cycling around the city beware of motorcyclists. Do not put any valuable items in your handlebar basket, as they may be snatched at traffic lights. Also, women travelers have been groped by passing-by motorcyclists, so beware if someone slows down next to you.

http://wikitravel.org/en/Ayutthaya

有用的链接:

Ayutthaya travel guide – Wikitravelการรถไฟแห่งประเทศไทย – State Railway of ThailandKhao Yai National Park and Elephant Ride Day Trip from Bangkok – Bangkok | ViatorAyuthaya – Lonely PlanetAyutthaya – City Island Bicycle Track II (The Historical Park Loop) – Cycling route – Route description | RouteYouTamarind Guesthouse Ayutthaya, Thailand: Agoda.com

“Harvard ManageMentor Time Management” Notes 时间管理 笔记

Categories: Uncategorized; Tagged with: ; @ April 6th, 2014 22:43

Why Manage Your Time?

Time management is the discipline of organizing, allocating, and controlling time you use for activities in such a way that you achieve your desired results. Time management forces you to be explicit about what you value and helps you assign your efforts accordingly.

Identifying and prioritizing Goals

Types of goals:

Critical:  “must be accomplished in order for your department or unit to continue running successfully”

Enabling: “create a more desirable business condition in the long run or take advantage of a business opportunity”

Nice-to-have: “enhance your business—by making activities faster, easier, or more appealing—but don’t revolutionize your business”

Prioritize your goals

Distinguish between urgent and crucial tasks:
”Urgent tasks demand immediate attention. But every urgent matter does not necessarily support a critical goal.”

Breaking Goals into Tasks

Identify required tasks; Prioritize tasks; Sequence tasks; Estimate required time;

Analyzing How You Spend Your Time

Understand how you’re currently spending time;

Assign a priority to each activity: Critical/Enabling/Nice-to-have

Identify ways to improve your use of time

Common ‘Time-Wasters’

Procrastination

Unpleasant or uninteresting task / Fear of failure / Unclear starting point

Unpleasant or uninteresting task

  • Delegate the task—it may not be unpleasant to someone else.
  • Admit you’re procrastinating—and get the job done.
  • Envision how good you’ll feel once you’ve completed the task.
  • Schedule the task in a way that makes turning back impossible.

Fear of failure

  • If you lack the training or resources needed to complete an assignment, say so—and get the help you need.
  • If your fear stems from lack of self-confidence, defuse it by being proactive and planning all the things you’ll have to do to complete the job.
  • Get on with the job: Activity can help dispel fear.

Unclear starting point

  • Jump in anywhere. You’ll likely find a productive way forward.
  • Break the job into component parts, then specify tasks needed to complete each part. Sequence them—then tackle the first task.

Schedule overloading

Know your key responsibilities and goals; Delegate; Don’t assume everything has to be done; Learn to say no to your peers and boss;

Direct reports’ problems

  • Provide feedback on direct reports’ proposed solutions to a problem, but make sure employees—not you—implement the solutions.

Email and paperwork overload

heck e-mail only at assigned times during the day.

Distractions and switching costs

Scheduling Time More Effectively

  • Keep “urgent but unimportant” and low-priority tasks off the list entirely.
  • Block off more “free time” in your daily schedule to “Build flexibility into your schedule”

Dealing with Time-Wasting Bosses

Get clear directions on your boss’s preferences;

Consider how you might be wasting your supervisor’s time

  • Don’t bring problems to your boss to handle. Instead, bring proposed solutions, and seek his or her feedback.
  • Accommodate your boss’s work style. For example, if he or she prefers to receive information in writing rather than in person, honor those preferences.

 

At last, forgot it….

 

image

Python: Parse HTML using Beautiful Soup

Categories: Python; Tagged with: ; @ April 6th, 2014 17:24

Requirement:

Get the FX rate from: http://fx.cmbchina.com/hq

Solution:

Use urllib2 to get the html, use BeautifulSoup to parse the html;

Details:

1.  Get html by urllib2:

import urllib2
html = urllib2.urlopen(“
http://fx.cmbchina.com/hq”).read()

2. parse the html using BeautifulSoup:

install it:

$ apt-get install python-bs4 // http://www.crummy.com/software/BeautifulSoup/bs4/doc/#installing-beautiful-soup

Python Code:

from bs4 import BeautifulSoup
soup = BeautifulSoup(html)   # you may check the HTML by: print(soup.prettify()) 
sgRateString = soup.find(id=”realRateInfo”).find_all(‘tr’)[8].find_all(‘td’)[5].get_text()
sgRate = float(sgRateString)
print ‘SG Rate:’, sgRate

All Code:

Links

urllib2 examples:  https://docs.python.org/2/library/urllib2.html#examples

BeautifulSoup Quick Start: http://www.crummy.com/software/BeautifulSoup/bs4/doc/#quick-start

Newer Posts <-> Older Posts



// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.