tag:blogger.com,1999:blog-71589463087680541642024-03-13T04:26:03.980-07:00New GearsNewGearshttp://www.blogger.com/profile/01269867207464049411noreply@blogger.comBlogger6125tag:blogger.com,1999:blog-7158946308768054164.post-6846530830127360562011-12-30T17:15:00.000-08:002012-01-07T13:16:55.026-08:00Factory Method Pattern in Python<span style="font-family: Verdana, sans-serif;">Ok, here we go again. This time, I will demonstrate Factory Method Design Pattern </span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span><br />
<span style="font-family: Verdana, sans-serif;">Let's say we need to design a module to retrieve 4 statistics counters, </span><br />
<ol>
<li><i style="font-family: Verdana, sans-serif;">Bytes Transmitted</i><span style="font-family: Verdana, sans-serif;"> </span></li>
<li><i style="font-family: Verdana, sans-serif;">Bytes Received</i></li>
<li><span style="font-family: Verdana, sans-serif;"><i>Packet Transmitted</i></span></li>
<li><span style="font-family: Verdana, sans-serif;"><i>Packets Received</i></span></li>
</ol>
<span style="font-family: Verdana, sans-serif;">So, we start with creating a base class and 4 inherited classes:</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span><br />
<pre style="background-image: URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;">1: class StatsClass(object):
2:
3: def __init__(self):
4: self._counter = 0
5: self._name ="Abtract Statistics Class"
6:
7: def Get_Name(self):
8: return self._name
9:
10: def Get(self):
11: return self._counter;
12:
13: def Reset(self):
14: self._counter = 0;
15:
16: def Set(self,counter):
17: self._counter = counter;
18:
19: def PollFromHw(self):
20: print(self._name, "is poll statistics counter from hardware register")
21:
22:
23: class StatsBytesTransmitted(StatsClass):
24: def __init__(self):
25: self._name = "Bytes Transmitted"
26: self._counter = 0
27:
28: class StatsBytesReceived(StatsClass):
29: def __init__(self):
30: self._name = "Bytes Received"
31: self._counter = 0
32:
33: class StatsPacketsTransmitted(StatsClass):
34: def __init__(self):
35: self._name = "Packets Transmitted"
36: self._counter = 0
37:
38: class StatsPacketsReceived(StatsClass):
39: def __init__(self):
40: self._name = "Packets Received"
41: self._counter = 0
42:
</code></pre>
<span style="font-family: Verdana, sans-serif;"><br /></span><br />
<span style="font-family: Verdana, sans-serif;">Then, create a Factory Class</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span><br />
<pre style="background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;">1: # Factory Class
2: class AbstractStatsFactory():
3: def CreateStats(self,strStats):
4: pass
5:
6: class StatsFactory(AbstractStatsFactory):
7: def CreateStats(self,strStats):
8: if( strStats == "Bytes Received"):
9: StatsObj = StatsBytesReceived()
10: elif ( strStats == "Bytes Transmitted"):
11: StatsObj = StatsBytesTransmitted()
12: elif ( strStats == "Packets Transmitted"):
13: StatsObj = StatsPacketsTransmitted()
14: elif ( strStats == "Packets Received"):
15: StatsObj = StatsPacketsReceived()
16: else:
17: StatsObj = None
18:
19: return StatsObj
</code></pre>
<span style="font-family: Verdana, sans-serif;"><br /></span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span><br />
<span style="font-family: Verdana, sans-serif;">Now, let's put them into use</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span><br />
<pre style="background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;">1: def Use_StatsObj(StatsObj):
2: StatsObj.PollFromHw()
3: StatsObj.Set(100)
4: print(StatsObj.Get_Name(), "counter is ", StatsObj.Get())
5: StatsObj.Reset()
6: print(StatsObj.Get_Name(), "counter Reset. Now counter is ", StatsObj.Get())
7:
8:
9:
10: strStats = "Bytes Received"
11: StatsObj = StatsFactory().CreateStats(strStats)
12: Use_StatsObj(StatsObj)
13:
14: strStats = "Bytes Transmitted"
15: StatsObj = StatsFactory().CreateStats(strStats)
16: Use_StatsObj(StatsObj)
</code></pre>
<span style="font-family: Verdana, sans-serif;"><br /></span><br />
<span style="font-family: Verdana, sans-serif;">The output is </span><br />
<pre style="background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> Bytes Received is poll statistics counter from hardware register
Bytes Received counter is 100
Bytes Received counter Reset. Now counter is 0
Bytes Transmitted is poll statistics counter from hardware register
Bytes Transmitted counter is 100
Bytes Transmitted counter Reset. Now counter is 0
</code></pre>
<span style="font-family: Verdana, sans-serif;"><br /></span><br />
<span style="font-family: Verdana, sans-serif;">No bad so far, though</span><span style="font-family: Verdana, sans-serif;">, I am not satisfied.</span><br />
<br />
<span style="font-family: Verdana, sans-serif;">There is still an </span><span style="font-family: 'Courier New', Courier, monospace;">if-elif-else</span><span style="font-family: Verdana, sans-serif;"> statement in the </span><span style="background-color: #f0f0f0; line-height: 20px; text-align: left;"><span style="font-family: 'Courier New', Courier, monospace;">StatsFactory</span></span><span style="background-color: #f0f0f0; font-family: arial; font-size: 12px; line-height: 20px; text-align: left;"> </span><span style="font-family: Verdana, sans-serif;">Class. It will be nice if the Factory class knows how many Statistics Objects are there</span><i style="font-family: Verdana, sans-serif;">, </i><span style="font-family: Verdana, sans-serif;">without explicitly instantiated these concrete objects .</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span><br />
<span style="font-family: Verdana, sans-serif;">In OO theme, you can use Reflection to do so. In Python, this is how I implement it</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span><br />
<pre style="background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;">1: class StatsFactory2(AbstractStatsFactory):
2: def CreateStats(self,strStats):
3: # Get all subclass
4: for childClass in StatsClass.__subclasses__() :
5: obj = childClass()
6: if( strStats == obj.Get_Name()):
7: return obj
8: def ListStatsObjNames(self):
9: objList = list()
10: for childClass in StatsClass.__subclasses__() :
11: # print(childClass)
12: obj = childClass()
13: objList.append(obj.Get_Name())
14: return objList
15:
16:
</code></pre>
<span style="font-family: Verdana, sans-serif;"><br /></span><br />
<span style="font-family: Verdana, sans-serif;">Now, it's time to put the code into test</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span><br />
<pre style="background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;">1: print("--- now use New Factory --- ")
2: strStats = "Bytes Received"
3: StatsObj = StatsFactory2().CreateStats(strStats)
4: Use_StatsObj(StatsObj)
5:
6: print("Counter can be read: ", StatsFactory2().ListStatsObjNames())
7: while(True):
8: strStats = input("Which counter do you want to know ?");
9: StatsObj = StatsFactory2().CreateStats(strStats)
10: if( StatsObj == None ):
11: break
12: Use_StatsObj(StatsObj)
13:
</code></pre>
<span style="font-family: Verdana, sans-serif;"><br /></span><br />
<span style="font-family: Verdana, sans-serif;">This is the Output</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span><br />
<pre style="background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> --- now use New Factory ---
Bytes Received is poll statistics counter from hardware register
Bytes Received counter is 100
Bytes Received counter Reset. Now counter is 0
Counter can be read: ['Bytes Transmitted', 'Bytes Received', 'Packets Transmitted', 'Packets Received']
Which counter do you want to know ?Bytes Transmitted
Bytes Transmitted is poll statistics counter from hardware register
Bytes Transmitted counter is 100
Bytes Transmitted counter Reset. Now counter is 0
</code></pre>
<span style="font-family: Verdana, sans-serif;"><br /></span><br />
<span style="font-family: Verdana, sans-serif;">Now, this is beauty part -- let's add two new statistics counters right after the </span><span style="background-color: #f0f0f0; font-family: arial; font-size: 12px; line-height: 20px; text-align: left;">StatsPacketsReceived </span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span><br />
<pre style="background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;">1: class StatsFcsError(StatsClass):
2: def __init__(self):
3: self._name = "Fcs Error"
4: self._counter = 0
5:
6: class StatsDiscardPacket(StatsClass):
7: def __init__(self):
8: self._name = "Discard Packets"
9: self._counter = 0
10:
</code></pre>
<span style="font-family: Verdana, sans-serif;"><br /></span><br />
<span style="font-family: Verdana, sans-serif;">Then, run my test code <b><i>without </i></b>any change. Voila, the two new classes are automatically recognized and can be used. </span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span><br />
<pre style="background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> --- now use New Factory ---
Bytes Received is poll statistics counter from hardware register
Bytes Received counter is 100
Bytes Received counter Reset. Now counter is 0
Counter can be read: ['Bytes Transmitted', 'Bytes Received', 'Packets Transmitted', 'Packets Received', 'Fcs Error', 'Discard Packets']
Which counter do you want to know ?Discard Packets
Discard Packets is poll statistics counter from hardware register
Discard Packets counter is 100
Discard Packets counter Reset. Now counter is 0
Which counter do you want to know ?
</code></pre>
<span style="font-family: Verdana, sans-serif;"><br /></span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span><br />
<span style="font-family: Verdana, sans-serif;">Beautiful, isn't it ?</span>NewGearshttp://www.blogger.com/profile/01269867207464049411noreply@blogger.com3tag:blogger.com,1999:blog-7158946308768054164.post-42578724038402770322011-12-28T11:33:00.000-08:002011-12-28T11:33:25.946-08:00Decorator Pattern in Python<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">I re-read <a href="http://www.amazon.com/First-Design-Patterns-Elisabeth-Freeman/dp/0596007124">Head-First Design Pattern</a> lately. And decide to implement Decorator Design Pattern in Python.</span><br />
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><br />
</span><br />
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">The following is based on the example from the book</span><br />
<br />
<ol><li><span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">The existing code has base class <b>Beverage, </b>and subclass<b> DarkRoast, Espresso. </b>These code has been fully tested and in production (line 1-21). </span></li>
<li><span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">Three months later, your boss want to have more varieties of drink, .e.g Whip Cream, Vanilla. So, you need to write more code to support that.</span></li>
<li><span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">It's best to use Decorator Design Pattern, as it obeys the OCP(Open-Closed) Principle. (line 24-51)</span></li>
<li><span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><b>Mocha</b>, <b>WhipCream</b>, <span style="background-color: #f0f0f0; line-height: 20px; text-align: left;"><b>Vanilla </b>are all decorator class.</span></span></li>
</ol><br />
<br />
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><b>Source Code</b></span><br />
<br />
<pre style="background-image: URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;">1: class Beverage:
2: """ beverage class """
3: def __init__(self):
4: self._desc = "Abstract Drink"
5: self._cost = 0.0
6:
7: def get_cost(self):
8: return self._cost
9:
10: def get_desc(self):
11: return self._desc
12:
13: class DarkRoast(Beverage):
14: def __init__(self):
15: self._cost = 3.5
16: self._desc = "Dark Roast ($" + str(self._cost) + ")"
17:
18: class Espresso(Beverage):
19: def __init__(self):
20: self._cost = 3.0
21: self._desc = "Espresso ($" + str(self._cost)+ ")"
22:
23:
24: # Design Pattern
25: # Abstract Decorator
26: class Condiments(Beverage):
27: def __init__(self):
28: self._desc = "Abstract Condiments class"
29: self._cost_condiment = 0.0
30:
31: class Mocha(Condiments):
32: def __init__(self, beverage):
33: self._cost_condiment = 1.0
34: self._beverage = beverage;
35: self._desc = "Mocha($"+ str(self._cost_condiment)+ ") " + self._beverage.get_desc()
36: self._cost = self._cost_condiment + self._beverage.get_cost()
37:
38: class Vanilla(Condiments):
39: def __init__(self, beverage):
40: self._cost_condiment = 0.6
41: self._beverage = beverage;
42: self._desc = "Vanilla($"+ str(self._cost_condiment)+ ") " + self._beverage.get_desc()
43: self._cost = 0.6 + self._beverage.get_cost()
44:
45:
46: class WhipCream(Condiments):
47: def __init__(self,beverage):
48: self._cost_condiment = 0.4
49: self._beverage = beverage;
50: self._desc = "WhipCream($"+ str(self._cost_condiment)+ ") " + self._beverage.get_desc()
51: self._cost = 0.4 + self._beverage.get_cost()
52:
53: ########################################################################################3
54:
55:
56: b = DarkRoast()
57: print(b.get_desc(), "Cost is", b.get_cost())
58:
59: b = Mocha(DarkRoast())
60: print(b.get_desc(), "Cost is", b.get_cost())
61:
62: b = Mocha(Espresso())
63: print(b.get_desc(), "Cost is", b.get_cost())
64:
65: b = Vanilla(DarkRoast())
66: print(b.get_desc(), "Cost is", b.get_cost())
67:
68: b = Vanilla(Mocha(DarkRoast()))
69: print(b.get_desc(), "Cost is", b.get_cost())
70:
71: b = WhipCream(Mocha(DarkRoast()))
72: print(b.get_desc(), "Cost is", b.get_cost())
73:
74:
75: b = Vanilla(WhipCream(Mocha(DarkRoast())))
76: print(b.get_desc(), "Cost is", b.get_cost())
77:
</code></pre><br />
<br />
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><b>Output</b></span><br />
<br />
<pre style="background-image: URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> Dark Roast ($3.5) Cost is 3.5
Mocha($1.0) Dark Roast ($3.5) Cost is 4.5
Mocha($1.0) Espresso ($3.0) Cost is 4.0
Vanilla($0.6) Dark Roast ($3.5) Cost is 4.1
Vanilla($0.6) Mocha($1.0) Dark Roast ($3.5) Cost is 5.1
WhipCream($0.4) Mocha($1.0) Dark Roast ($3.5) Cost is 4.9
Vanilla($0.6) WhipCream($0.4) Mocha($1.0) Dark Roast ($3.5) Cost is 5.5
</code></pre><br />
<br />
<span style="font-family: Verdana, sans-serif; font-size: large;"><b>Why not using Python built-in Decorator ?</b></span><br />
<br />
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">This is good question. My reasons are</span><br />
<br />
<ol><li><span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">You have to modify the existing code. In the source code above, you have to add <i>@decorator</i> in <b>DarkRoast </b>or <b>Espresso </b>class. With Decorator Design Pattern, you don't have to modify existing code. </span></li>
<li><span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">You cannot undo the <i>@decorator </i>during run-time<i>.</i> Once it's there, it's there forever. If you use Decorator Design Pattern, you still can enjoy the original espresso. :)</span></li>
</ol><br />
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><br />
</span><br />
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"><br />
</span>NewGearshttp://www.blogger.com/profile/01269867207464049411noreply@blogger.com1tag:blogger.com,1999:blog-7158946308768054164.post-6438954422189526852011-11-30T12:42:00.000-08:002011-11-30T12:43:59.422-08:00PMI-ACP Certification Exam Experience Requirements Spreadsheet<span class="Apple-style-span" style="font-family: Verdana, sans-serif;">I am in the process of getting PMI-ACP certification. According to <a href="http://www.pmi.org/en/Certification/New-PMI-Agile-Certification.aspx">PMI</a>, you would need at least 1500 hours working on agile project teams, and these hours must be earned in last two years. </span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;">I</span><span class="Apple-style-span" style="font-family: Verdana, sans-serif;">n my journey of preparation, I created a spreadsheet to calculate hours spent in Agile Project Management Experience. I am sharing here to help others to prep for this certification.</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;">Please note that, this spreadsheet will ONLY calculate Agile Project Experience. It does NOT cover general project management experience. There are lots of resource on internet to help you to calculate general project management experience. You can google search "pmp experience spreadsheet" to find one suitable for you.</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br />
</span><br />
<b><span class="Apple-style-span" style="color: blue;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;">Down from here : </span><a href="https://docs.google.com/viewer?a=v&pid=explorer&chrome=true&srcid=0B4Q68P2RX-ARMGNiM2VmM2EtMTBhZi00MjI0LTkyNmUtNjFiMzc2ZjJkZTBh&hl=en_US" style="font-family: Verdana, sans-serif;">PMI-ACP Agile Experience Worksheet</a> </span></b><br />
<br />
<ol><li><span class="Apple-style-span" style="font-family: Verdana, sans-serif;">Click the link, t</span><span class="Apple-style-span" style="font-family: Verdana, sans-serif;">hen select menu "File"->"Download original". Your browser will prompt you to save an excel spreadsheet file.</span></li>
<li><span class="Apple-style-span" style="font-family: Verdana, sans-serif;">You need Excel 2007 and above. Or, you can directly edit it if you have google account.</span></li>
</ol><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br />
</span>NewGearshttp://www.blogger.com/profile/01269867207464049411noreply@blogger.com11tag:blogger.com,1999:blog-7158946308768054164.post-71779463128596906322011-08-13T00:19:00.000-07:002011-08-27T15:36:51.784-07:00Install Python Code Coverage in Ubuntu 11.04<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">Just started to learn using Python on Linux. For me, the most troubling stuffs is to get the program installed over Linux. </span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">Anyhow, these are prerequisites,</span><br />
<br />
<ul><li><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">You have Python installed. Ubuntu comes with Python2.7. But, you can install Python 3.2 <a href="http://newgears.blogspot.com/2011/08/install-python-32-on-ubuntu-1104.html">following another post</a> </span></li>
<li><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">Python Setuptools. If you don't have this, you can install it by </span></li>
<pre style="background-color: #eeeeee; border-bottom-color: rgb(153, 153, 153); border-bottom-style: dashed; border-bottom-width: 1px; border-left-color: rgb(153, 153, 153); border-left-style: dashed; border-left-width: 1px; border-right-color: rgb(153, 153, 153); border-right-style: dashed; border-right-width: 1px; border-top-color: rgb(153, 153, 153); border-top-style: dashed; border-top-width: 1px; font-family: 'Andale Mono', 'Lucida Console', Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; width: 100%;"><code><span class="Apple-style-span" style="color: blue;">$ sudo apt-get install python-setuptools</span>
</code></pre></ul><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">These are steps to install Python Code Coverage </span></div><div><ol><li><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">Download the Python Code Coverage from <a href="http://pypi.python.org/pypi/coverage">http://pypi.python.org/pypi/coverage</a>. As of writing, the version is 3.5</span></li>
<li><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">extract the tarball to a folder, .e.g. </span><span class="Apple-style-span" style="color: blue; font-family: 'Courier New', Courier, monospace;">~/Downloads/coverage-3.5</span></li>
<li><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">In Ubuntu, the default python is 2.7. It will install to</span><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"> /usr/local/lib/python2.7/dist-packages/</span></li>
</ol></div><pre style="background-color: #eeeeee; border-bottom-color: rgb(153, 153, 153); border-bottom-style: dashed; border-bottom-width: 1px; border-left-color: rgb(153, 153, 153); border-left-style: dashed; border-left-width: 1px; border-right-color: rgb(153, 153, 153); border-right-style: dashed; border-right-width: 1px; border-top-color: rgb(153, 153, 153); border-top-style: dashed; border-top-width: 1px; font-family: 'Andale Mono', 'Lucida Console', Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; width: 100%;"><code>newgear@ubuntu:~/Downloads/coverage-3.5$ <span class="Apple-style-span" style="color: blue;">sudo python setup.py install -v</span>
</code></pre><br />
Or, you can do this to install to Python 3.2. It will install to<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"> /usr/local/lib/python3.2/dist-packages/</span><br />
<br />
<pre style="background-color: #eeeeee; border-bottom-color: rgb(153, 153, 153); border-bottom-style: dashed; border-bottom-width: 1px; border-left-color: rgb(153, 153, 153); border-left-style: dashed; border-left-width: 1px; border-right-color: rgb(153, 153, 153); border-right-style: dashed; border-right-width: 1px; border-top-color: rgb(153, 153, 153); border-top-style: dashed; border-top-width: 1px; font-family: 'Andale Mono', 'Lucida Console', Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; width: 100%;"><code>newgear@ubuntu:~/Downloads/coverage-3.5$ <span class="Apple-style-span" style="color: blue;">sudo python3.2 setup.py install -v</span>
</code></pre><br />
NewGearshttp://www.blogger.com/profile/01269867207464049411noreply@blogger.com3tag:blogger.com,1999:blog-7158946308768054164.post-71647992870516230622011-08-08T22:25:00.000-07:002012-01-21T19:35:34.821-08:00Install Python 3.2 on Ubuntu 11.04<span class="Apple-style-span" style="font-family: Verdana, sans-serif;">Ubuntu comes with Python 2.7, but I want to try out Python 3.2.x. After some google searches, I cannot just remove Python 2.7 and install 3.2.x, as Ubuntu's other modules requires 2.7</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;">But, you can have Python 3.2.x coexist with Python </span><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> 2.7</span><span class="Apple-style-span" style="font-family: Verdana, sans-serif;">. This is how:</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"></span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br />
</span><br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><i>Launch <b>Ubuntu Software Center</b>, then search <b>Python 3.2. </b>Select Python 3.2 and install</i></span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><b><br />
</b></span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-1PplenSASGs/TkDCZynKT9I/AAAAAAAAAU4/TedpqlSJbmU/s1600/python3.2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="250" src="http://3.bp.blogspot.com/-1PplenSASGs/TkDCZynKT9I/AAAAAAAAAU4/TedpqlSJbmU/s400/python3.2.png" width="500" /></a></div>
<br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;">After that, you can run Python 3.2 in terminal like this</span><br />
<br />
<br />
<pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><code>newgear@ubuntu:~$ python3.2
Python 3.2 (r32:88445, Mar 25 2011, 19:28:28)
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import sys
>>> sys.version_info
sys.version_info(major=3, minor=2, micro=0, releaselevel='final', serial=0)
</code></pre>
<br />
<br />
<br />
<br />NewGearshttp://www.blogger.com/profile/01269867207464049411noreply@blogger.com0tag:blogger.com,1999:blog-7158946308768054164.post-92207013167301314382011-08-05T23:12:00.000-07:002011-08-06T10:12:45.578-07:00ASUS U43JC: Upgrade to Intel Advanced-N 6205 or 6200 Wireless Card<div style="font-family: Arial,Helvetica,sans-serif;">I just recently upgraded the my ASUS U43JC's wireless card to Intel Advanced N 6205. The benefit, comparing to stock Intel Wireless 1000 card, is<br />
<br />
<ol><li><b>Support dual band</b>: 62xx support both 2.4Ghz and 5Hz frequency band.</li>
<li><b>Better wireless performance</b>:</li>
<ul><li>1000 is 1x2 300mbps receive, 150mbps transmit</li>
<li> 6200 is 2x2 300mbps receive, 300mbps transmit</li>
</ul></ol><br />
<br />
<span style="font-size: large;"><b>Instructions</b></span></div><div style="font-family: Arial,Helvetica,sans-serif;"><br />
</div><ol style="font-family: Arial,Helvetica,sans-serif;"><li><span style="font-size: large;"><b>Buy a compatible wireless card</b> </span>: The ASUS U43JC has only two antennas, so your best bet is Intel <b>62xx </b>series. <b>6300 </b>would need 3 antennas, hence it will be waste -- unless you want to mod your U43JC to add a 3rd antenna. You have several options on 62xx,</li>
<ol><a href="http://1.bp.blogspot.com/-hn-LdATvdsc/TjzV6bW9TdI/AAAAAAAAAUo/5zA_mb5fjTM/s1600/IMG_5544.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" height="480" src="http://1.bp.blogspot.com/-hn-LdATvdsc/TjzV6bW9TdI/AAAAAAAAAUo/5zA_mb5fjTM/s640/IMG_5544.png" width="640" /></a>
<li><b>6200 and 6205</b>: Reading the product brief, I did not see any differences in terms of feature sets. So, I end up buying <b>Intel Advanced-N 6205</b> (<b>62205AN.HMWWB</b>) from ebay for $18 + $4 shipping, as it's the cheaper than 6200. </li>
<li> <b>6230</b>: has integrated Bluetooth. If you want Bluetooth option, you can try this. Though I have NOT tested it.</li>
<li><b>6250</b>: has WiMax. Don't know if this will work. Plus, I don't need WiMax servies anyway.</li>
</ol><li><span style="font-size: large;"><b>Download software and driver</b></span> : <a href="http://lmgtfy.com/?q=intel+wireless+6205+driver+download">Google "intel wireless 6205 driver download"</a> should lead the Intel Driver download site. My U43JC is running Windows 7, 64 bits, so I downloaded "ICS_s64.exe". <b><br />
</b></li>
<li><span style="font-size: large; font-weight: bold;">Remove Screws</span><b> : </b>Remove battery, and disconnect power adapter first. Then, start to removes all screws. The screws are in various sizes, so make sure you keep track where the screws are removed. I lined them up on the table, just like the orientation on the notebook. </li>
<div class="separator" style="clear: both; text-align: center;"><a href="http://1.bp.blogspot.com/-Jd5Wn78qZ70/TjzWXVrijdI/AAAAAAAAAUs/yoXOuG2MA0s/s1600/IMG_5546.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em; text-align: left;"><img border="0" height="480" src="http://1.bp.blogspot.com/-Jd5Wn78qZ70/TjzWXVrijdI/AAAAAAAAAUs/yoXOuG2MA0s/s640/IMG_5546.png" width="640" /></a></div><ol><li>Remove all the visible screws in the back.</li>
<li>Remove DVD burner, the screws behind the DVD burner </li>
<li>Take out hard drive bay cover, and hard driver. Then, remove the screws behind the hard drive.</li>
<li>Take out memory bay cover, and remove the screws near the memory</li>
<li>Remove the screws behind the two rubber feet near the hinge.<b><br />
</b></li>
</ol><li><span style="font-size: large;"><b>Lift up the keyboard</b></span></li>
<div class="separator" style="clear: both; text-align: center;"><a href="http://1.bp.blogspot.com/-DZHO6RgXMyk/TjzXLl2ZgiI/AAAAAAAAAUw/vpfJnPSfHik/s1600/IMG_5547.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="300" src="http://1.bp.blogspot.com/-DZHO6RgXMyk/TjzXLl2ZgiI/AAAAAAAAAUw/vpfJnPSfHik/s400/IMG_5547.png" width="400" /></a></div><ol><li>Starting from the corner, I use a plastic card to pry open the keyboard slowly. You only need little force to lift up the entire keyboard. If it gets stuck, it is more likely the screws are not completely removed. </li>
</ol><li><b>Replace the wireless card</b></li>
<div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/-FW_TTifkJZ0/TjzYwjOVeNI/AAAAAAAAAU0/bIMAzzWCjps/s1600/IMG_5552.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" height="480" src="http://2.bp.blogspot.com/-FW_TTifkJZ0/TjzYwjOVeNI/AAAAAAAAAU0/bIMAzzWCjps/s640/IMG_5552.png" width="640" /></a></div><ol><li>You don't have to remove any ribbon cables. Remove the 2 screws around the wireless card and antenna cables. Then, replace with new card.</li>
</ol><li><b>Install Driver and Testing</b></li>
<ol><li>Temporarily put back the hard drive, connects to the power adapter. Your U43JC will boot up, then install the new software driver. After the software driver installation completed, do some testing to make sure the new card is good. In my master bedroom, I used to get poor reception. With the new card, I can get around 24Mbps speed.</li>
</ol><li><b>Put the screws back</b>. </li>
<ol><li>At this point, you are all set. Just put everything back, Hard Disk, DVD burner, and .. etc.</li>
</ol></ol>NewGearshttp://www.blogger.com/profile/01269867207464049411noreply@blogger.com4