Hi,
Today I have found that using math.sqrt(x) generally take a longer period of time than x**0.5 to get a result. I was using Python 2.7 on Windows 7 with CPU i5 5200u coupled with 8GB of RAM to produce the claim. I am curious that this may vary with machines. If you have a few minutes, please try yours and let me know how it was.
Thanks,
Saran
Wednesday, October 5, 2016
Monday, November 23, 2015
Understanding Adaptive Replacement Cache (ARC) through a simple Python code
Hello,
Recently, I had a rather annoying problem of understanding Adaptive Replacement Cache (ARC) algorithm. ARC is an efficient, self-tuning, and patented cache algorithm proposed by folks at IBM about ten years ago. It is much more efficient than LRU and requires just minimal additional overhead. Nevertheless, this cache algorithm is a bit complicated to follow. So I decided to implement it by myself using Python. Note that there is already a nice Python code of ARC. However, that code utilizes wrapper and decoration functions, being quite a bit complex. My code is straightforward and may be more understandable to some Python beginners.
Warning: The code is only for educational purposes. The ARC algorithm is protected by US patent law.
Link to my code on GitHub
Code
Now you know what to do next. Have fun! :)
-
Saran
Recently, I had a rather annoying problem of understanding Adaptive Replacement Cache (ARC) algorithm. ARC is an efficient, self-tuning, and patented cache algorithm proposed by folks at IBM about ten years ago. It is much more efficient than LRU and requires just minimal additional overhead. Nevertheless, this cache algorithm is a bit complicated to follow. So I decided to implement it by myself using Python. Note that there is already a nice Python code of ARC. However, that code utilizes wrapper and decoration functions, being quite a bit complex. My code is straightforward and may be more understandable to some Python beginners.
Warning: The code is only for educational purposes. The ARC algorithm is protected by US patent law.
Link to my code on GitHub
Code
Now you know what to do next. Have fun! :)
-
Saran
Sunday, June 7, 2015
Tips for Academic Writing and Other Formal Writing
I find this topic is a good read and very useful.
Thursday, November 20, 2014
Wednesday, October 22, 2014
Sympy: A Python Library for Symbolic Mathematics
SymPy is a Python library for symbolic mathematics. It aims to become a full-featured computer algebra system (CAS) while keeping the code as simple as possible in order to be comprehensible and easily extensible. SymPy is written entirely in Python and does not require any external library.
To find out more, check this.
Saran
Thursday, October 16, 2014
WHAT IS THE DIFFERENCE BETWEEN A THEOREM, A LEMMA, AND A COROLLARY?
I find this useful for me.
WHAT IS THE DIFFERENCE BETWEEN A THEOREM, A LEMMA,
AND A COROLLARY?
PROF. DAVE RICHESON
Definition — a precise and unambiguous description of the meaning of a mathematical term. It characterizes the meaning of a word by giving all the properties and only those properties that must be true.
Theorem — a mathematical statement that is proved using rigorous mathematical reasoning. In a mathematical paper, the term theorem is often reserved for the most important results.
Lemma — a minor result whose sole purpose is to help in proving a theorem. It is a stepping stone on the path to proving a theorem. Very occasionally lemmas can take on a life of their own (Zorn’s lemma, Urysohn’s lemma, Burnside’s lemma, Sperner’s lemma).
Corollary — a result in which the (usually short) proof relies heavily on a given theorem (we often say that “this is a corollary of Theorem A”).
Proposition — a proved and often interesting result, but generally less important than a theorem.
Conjecture — a statement that is unproved, but is believed to be true (Collatz conjecture, Goldbach conjecture, twin prime conjecture).
Claim — an assertion that is then proved. It is often used like an informal lemma.
Axiom/Postulate — a statement that is assumed to be true without proof. These are the basic building blocks from which all theorems are proved (Euclid’s five postulates,Zermelo-Fraenkel axioms, Peano axioms).
Identity — a mathematical expression giving the equality of two (often variable) quantities (trigonometric identities, Euler’s identity).
Paradox — a statement that can be shown, using a given set of axioms and definitions, to be both true and false. Paradoxes are often used to show the inconsistencies in a flawed theory (Russell’s paradox). The term paradox is often used informally to describe a surprising or counterintuitive result that follows from a given set of rules (Banach-Tarski paradox, Alabama paradox, Gabriel’s horn).
Wednesday, October 1, 2014
Working with Excel Files via Python
You may find yourself working with excel file (.xls) and Python is your main language. Don't worry, there is an efficient tool that can help you get through most basic tasks.
To find our more, visit Python Excel.
http://www.python-excel.org/
Cheers,
Saran Tarnoi
To find our more, visit Python Excel.
http://www.python-excel.org/
Cheers,
Saran Tarnoi
Friday, August 22, 2014
Accelerating Python with Numba
Python is one of the most popular programming languages in my opinion. It is beautiful and easy to learn. However, for some exhausted tasks, Python is relatively slow compared to C. Try using Numba to convert your native python code to optimized machine code. It surprisingly helps a lot in some cases.
Please visit the following link provided that you are interested in it.
http://numba.pydata.org/
Cheers,
Saran Tarnoi
Please visit the following link provided that you are interested in it.
http://numba.pydata.org/
Cheers,
Saran Tarnoi
Friday, August 8, 2014
Let's Make a Poster Using Latex
Creating a nice poster will never be a tired and frustrated task once you know how to use Latex for making one. I think "baposter" is a highly recommended tool to start with. Please visit the site below:
http://www.brian-amberg.de/uni/poster/.
Cheers,
Saran
http://www.brian-amberg.de/uni/poster/.
Cheers,
Saran
Sunday, July 20, 2014
A Very Useful Grub Organizer for Ubunto: Grub Customizer
There is a nice tool for customizing grub on Ubunto with an intuitive user interface available. It is Grub Customize in LuanchPad. I suggest you visit the official site of the tool at https://launchpad.net/grub-customizer.
Thanks developers for there efforts.
Thanks developers for there efforts.
Tuesday, June 10, 2014
Bar Graph with Texture
Improving the visibility of a bar graph created by Matlab will no longer bring an headache, just visit the site below:
Tuesday, May 20, 2014
To configure CPLEX for Python
There is a good tutorial on the following site.
http://minpower.readthedocs.org/en/v1.1.2/install-linux.html
Cheers
Saran Tarnoi
Thursday, March 6, 2014
To fix the problem of "fonts not embedded" in WinEdt
When I was about to upload a manuscript to EDAS, the problem regarded as "fonts not embedded" was showing up.
I had been spending several minutes to eventually meet a solution to the problem.
The solution for WinEdt 6.0 worked, I was using WinEdt 8.0 with gswin64c.exe though.
TeXify-> DVI to PS (DVIPS)->PS to PDF (ps2pdf)
Reference:
http://inside.mines.edu/~djyang/embeddedfont-WinEdt.html
I had been spending several minutes to eventually meet a solution to the problem.
The solution for WinEdt 6.0 worked, I was using WinEdt 8.0 with gswin64c.exe though.
WinEdt 6.0:
- Open WinEdt
- Select: Options, Execution Modes
- Select ps2pdf
- Click on "Browse for Executable" (lower left corner)
- Browse to the gswin32c.exe executable in C:\Program Files\gs\gs9.02\bin
- Enter the following switches:
-dBATCH -dNOPAUSE -sDEVICE=pdfwrite -r600 -dCompatibilityLevel=1.4 -dPDFSETTINGS=/printer -dMaxSubsetPct=100 -dSubsetFonts=true
- Enter the following parameters:
-sOutputFile="%N.pdf" "%N.ps"
(you might have another version than 9.02, so please adjust this number) and select it.
WinEdt 5.5:
- Open WinEdt
- Select: Options, Execution Modes
- Select ps2pdf
- The Command Line Switches for gswin32c.exe are
-dBATCH -dNOPAUSE -sDEVICE=pdfwrite -r600 -dCompatibilityLevel=1.4
Add the following switches to this line:-dPDFSETTINGS=/printer -dMaxSubsetPct=100 -dSubsetFonts=true -dEmbedAllFonts=true
TeXify-> DVI to PS (DVIPS)->PS to PDF (ps2pdf)
Reference:
http://inside.mines.edu/~djyang/embeddedfont-WinEdt.html
Thursday, January 9, 2014
Thursday, December 19, 2013
Sunday, December 1, 2013
The myth of using "None of" in a sentence
So many times I have to check my grammar for writing. "None of" usually makes me go over several websites and books emphasizing on the use of it.
The following sentences always give me an acceptable conclusion.
None of students are lazy.
None of meat is delicious.
Some people argue that "none of" must be treated as a singular pronoun.
I think I will use it in a more intuitive way as both "none of" and "most" are the words that indicate portions.
It is worth dropping by the website for the reference.
The following sentences always give me an acceptable conclusion.
None of students are lazy.
None of meat is delicious.
Some people argue that "none of" must be treated as a singular pronoun.
I think I will use it in a more intuitive way as both "none of" and "most" are the words that indicate portions.
It is worth dropping by the website for the reference.
Friday, November 15, 2013
ขั้นตอนการอัพเดต nexus 7 (2013) เป็น android 4.4 (Kitkat) ด้วยตนเอง
เป็นที่ทราบกันว่า nexus 7 ของเราๆกำลังอยู่ในระหว่างรอการปล่อยอัพเดตจาก Google สำหรับผู้ใช้ทั่วๆไป ก็นั่งรอกันไปตามลำดับ แต่เราสมาชิค Droidsans ย่อมคันไม้คันมือ อยากจะเห็นว่า Kitkat บน nexus 7 จะเจ๋งลื่นไหลสมคำร่ำรือจริงหรือ
ขั้นตอนการอัพเดตด้วยตัวเองนั้น มีโพสต์อยู่ทั้วไปบนอินเตอร์เนต แต่เป็นภาษาอังกฤษบ้าง ยาวบ้าง และแอบงงบ้าง
ผมจะสรุปวิธีที่ผมได้ทำไปแล้วสำเร็จด้วยเครื่อง Windows 7 64bit ดังต่อไปนี้
ทำตามไปทีละข้อ น่าจะไม่หลงทางกันนะครับ
อนึ่ง ผมใช้บทความจาก phandroid.com (http://phandroid.com/2013/11/13/how-to-install-kitkat-nexus-7/) ในการอ้างอิงนะครับ และวิธีต่อไปนี้ที่ผมจะกล่าวได้ถูกปรับแก้บ้างแล้ว
สิ่งที่ท่านต้องเตรียม
1. จะใช้วิธีนี้ได้ nexus ของท่านจำเป็นต้องเป็น stock build ตัวล่าสุด ของ android 4.3 เพราะจะเป็นการอัพเดตเพิ่มไปจากสิ่งที่เคยมีอยู่
2. ไปดาวน์โหลด Android SDK จาก http://developer.android.com/sdk/index.html แตก Zip file ออกมาท่านจะเจอโฟล์เดอร์ 2 อัน เราจะสนใจเฉพาะ โฟลเดอร์ ที่ชื่อ sdk ครับ ไม่ต้องกดติดตั้งอะไร ลากไปวางไว้ที่ไหนก็ใช้งานได้ครับ
ผมลากไปวางไว้ที่ไดร์ C:
3. ไปดาว์โหลดไฟล์อัพเดตครับ (http://android.clients.google.com/packages/ota/google_razor/3a3951e8243c82bc01a620ab858f4454c8ebd65c.signed-razor-KRT16O-from-JSS15R.3a3951e8.zip)
ชื่อมันยาวสุดจะทน เปลี่ยนเป็นชื่อสั้นๆว่า update.zip ครับเพื่อง่ายต่อการหา
เอาล่ะ ถ้าท่านเตรียมตัวเตรียมใจพร้อมแล้ว ก็เริ่มพิธีกันเถอะ!
1. เข้าไปที่ Development menu และ เปิด USB Debugging ในเครื่องของท่าน เนื่องจาก android version 4.2 เป็นต้นมาจะซ่อน Development menu ไว้ วิธีเรียกกลับมาคือ แตะที่ แถว Build number ใน About tablet จำนวน 7 ครั้ง
2. นำไฟล์ update.zip ไปวางในโฟล์เดอร์เดียวกับ platform-tools ซึ่งอยู่ในโฟล์เดอร์ชื่อ sdk
3. ปิดเครื่อง nexus 7 จากนั้นกดปุ่มเปิดเครื่องและปุ่มลดเสียง พร้อมๆกัน ย้ำว่า พร้อมๆกัน สักครู่เดียวเราจะเข้าสู่ fastboot mode มีหุ่นเขียวนอนหลายพร้อมกับพุงเปิดอยู่ และเมนูต่างๆ ณ จุดๆนี้ หน้าจอจะไม่รับรู้การสัมผัสแล้ว แล้วจะใช้ปุ่มเปิดปิดและปุ่มปรับเสียงในพิธีของเราจากนี้ไป
4. กดปุ่มลดเสียงสองครั้ง ท่านจะได้เจอคำว่า Recovery mode กดปุ่มเปิดปิดเครื่องเพื่อเข้าสู่ Recovery mode
ท่านจะเจอหุ่นหงายท้องพร้อมด้วยเครื่องหมายตกใจบนสามเหลี่ยมสีแดง แน่นอนท่านจะตกใจครับ ผมก็ตกใจ จากนั้น กดปุ่มเปิดเครื่องพร้อมกับปุ่มเพิ่มเสียงพร้อมกัน กดแล้วปล่อยไม่ต้องค้างนาน ท่านจะเจอเมนูต่างๆขึ้นมาให้อุ่นใจ ผมกดหลายรอบกว่าจะสำเร็จ ไม่รู้เป็นอะไร
5. ต่อเครื่องคอมพิวเตอร์ของท่านเข้ากับ nexus 7 ด้วยสายยูเอสบี ตรงนี้ไม่แน่ใจว่าต้องลง driver อะไรเพิ่มไหม เพราะผมปล่อยให้เครื่องคอนพิวเตอร์หาเอาเอง
6. ใช้ปุ่มเพิ่มหรือลดเสียง เพื่อเลือกเมนู apply update from ADB แล้วเลือกโดยใช้ปุ่มเปิดปิด
7. เปิดหน้าต่างสีดำแห่งวันวานคือ cmd โดยค้นหาว่า cmd ใน search ของ Windows เปลี่ยนไดเรกทอรี่ไปยัง platform-tools
8. เมื่อเรามายังไดเรกทอรี่ที่ถูกต้องแล้ว พิมพ์ adb sideload update.zip เครื่องท่านจะส่งไฟล์ไปให้ nexus 7 และทำที่เหลือเอง
9. ปล่อยให้ nexus 7 อัพเดตตัวเอง มี progress bar ให้ลุ้นเล็กๆ แต่ถึงจุดนี้ ไม่มีปัญหาให้ลุ้นแล้วล่ะครับ
10. รีสตาร์ทเครื่องโดยเลิก reboot system now เป็นอันเสร็จพิธี
มีข้อสงสัยตรงไหนก็ถามไว้นะครับ ผมและเพื่อนๆจะได้ช่วยท่านนำ Kitkat มาสู่เครื่องด้วยความภาคภูมิใจของท่านเอง
ผิดพลาดจุดไหน ช่วยกันบอกนะครับ ขอให้สนุกทุกท่านครับ
ขั้นตอนการอัพเดตด้วยตัวเองนั้น มีโพสต์อยู่ทั้วไปบนอินเตอร์เนต แต่เป็นภาษาอังกฤษบ้าง ยาวบ้าง และแอบงงบ้าง
ผมจะสรุปวิธีที่ผมได้ทำไปแล้วสำเร็จด้วยเครื่อง Windows 7 64bit ดังต่อไปนี้
ทำตามไปทีละข้อ น่าจะไม่หลงทางกันนะครับ
อนึ่ง ผมใช้บทความจาก phandroid.com (http://phandroid.com/2013/11/13/how-to-install-kitkat-nexus-7/) ในการอ้างอิงนะครับ และวิธีต่อไปนี้ที่ผมจะกล่าวได้ถูกปรับแก้บ้างแล้ว
สิ่งที่ท่านต้องเตรียม
1. จะใช้วิธีนี้ได้ nexus ของท่านจำเป็นต้องเป็น stock build ตัวล่าสุด ของ android 4.3 เพราะจะเป็นการอัพเดตเพิ่มไปจากสิ่งที่เคยมีอยู่
2. ไปดาวน์โหลด Android SDK จาก http://developer.android.com/sdk/index.html แตก Zip file ออกมาท่านจะเจอโฟล์เดอร์ 2 อัน เราจะสนใจเฉพาะ โฟลเดอร์ ที่ชื่อ sdk ครับ ไม่ต้องกดติดตั้งอะไร ลากไปวางไว้ที่ไหนก็ใช้งานได้ครับ
ผมลากไปวางไว้ที่ไดร์ C:
3. ไปดาว์โหลดไฟล์อัพเดตครับ (http://android.clients.google.com/packages/ota/google_razor/3a3951e8243c82bc01a620ab858f4454c8ebd65c.signed-razor-KRT16O-from-JSS15R.3a3951e8.zip)
ชื่อมันยาวสุดจะทน เปลี่ยนเป็นชื่อสั้นๆว่า update.zip ครับเพื่อง่ายต่อการหา
เอาล่ะ ถ้าท่านเตรียมตัวเตรียมใจพร้อมแล้ว ก็เริ่มพิธีกันเถอะ!
1. เข้าไปที่ Development menu และ เปิด USB Debugging ในเครื่องของท่าน เนื่องจาก android version 4.2 เป็นต้นมาจะซ่อน Development menu ไว้ วิธีเรียกกลับมาคือ แตะที่ แถว Build number ใน About tablet จำนวน 7 ครั้ง
2. นำไฟล์ update.zip ไปวางในโฟล์เดอร์เดียวกับ platform-tools ซึ่งอยู่ในโฟล์เดอร์ชื่อ sdk
3. ปิดเครื่อง nexus 7 จากนั้นกดปุ่มเปิดเครื่องและปุ่มลดเสียง พร้อมๆกัน ย้ำว่า พร้อมๆกัน สักครู่เดียวเราจะเข้าสู่ fastboot mode มีหุ่นเขียวนอนหลายพร้อมกับพุงเปิดอยู่ และเมนูต่างๆ ณ จุดๆนี้ หน้าจอจะไม่รับรู้การสัมผัสแล้ว แล้วจะใช้ปุ่มเปิดปิดและปุ่มปรับเสียงในพิธีของเราจากนี้ไป
4. กดปุ่มลดเสียงสองครั้ง ท่านจะได้เจอคำว่า Recovery mode กดปุ่มเปิดปิดเครื่องเพื่อเข้าสู่ Recovery mode
ท่านจะเจอหุ่นหงายท้องพร้อมด้วยเครื่องหมายตกใจบนสามเหลี่ยมสีแดง แน่นอนท่านจะตกใจครับ ผมก็ตกใจ จากนั้น กดปุ่มเปิดเครื่องพร้อมกับปุ่มเพิ่มเสียงพร้อมกัน กดแล้วปล่อยไม่ต้องค้างนาน ท่านจะเจอเมนูต่างๆขึ้นมาให้อุ่นใจ ผมกดหลายรอบกว่าจะสำเร็จ ไม่รู้เป็นอะไร
5. ต่อเครื่องคอมพิวเตอร์ของท่านเข้ากับ nexus 7 ด้วยสายยูเอสบี ตรงนี้ไม่แน่ใจว่าต้องลง driver อะไรเพิ่มไหม เพราะผมปล่อยให้เครื่องคอนพิวเตอร์หาเอาเอง
6. ใช้ปุ่มเพิ่มหรือลดเสียง เพื่อเลือกเมนู apply update from ADB แล้วเลือกโดยใช้ปุ่มเปิดปิด
7. เปิดหน้าต่างสีดำแห่งวันวานคือ cmd โดยค้นหาว่า cmd ใน search ของ Windows เปลี่ยนไดเรกทอรี่ไปยัง platform-tools
8. เมื่อเรามายังไดเรกทอรี่ที่ถูกต้องแล้ว พิมพ์ adb sideload update.zip เครื่องท่านจะส่งไฟล์ไปให้ nexus 7 และทำที่เหลือเอง
9. ปล่อยให้ nexus 7 อัพเดตตัวเอง มี progress bar ให้ลุ้นเล็กๆ แต่ถึงจุดนี้ ไม่มีปัญหาให้ลุ้นแล้วล่ะครับ
10. รีสตาร์ทเครื่องโดยเลิก reboot system now เป็นอันเสร็จพิธี
มีข้อสงสัยตรงไหนก็ถามไว้นะครับ ผมและเพื่อนๆจะได้ช่วยท่านนำ Kitkat มาสู่เครื่องด้วยความภาคภูมิใจของท่านเอง
ผิดพลาดจุดไหน ช่วยกันบอกนะครับ ขอให้สนุกทุกท่านครับ
Tuesday, September 10, 2013
Monday, July 29, 2013
Kate: comment and uncomment
To toggle a block comment
--
Clt+d
--
and to remove a block comment
--
Clt+Shift+d.
That's it.
--
Clt+d
--
and to remove a block comment
--
Clt+Shift+d.
That's it.
Monday, July 22, 2013
From "list" in python to "vector" in C++
We can do this easily in Python but we need some new things to do this in C++.
An example of randomly generating heterogeneous numbers is shown below.
std::vector<int> groupI;
int k;
do {
k = 0 + (std::rand() % (int)(41 - 0 + 1));
}
while (std::find(groupI.begin(), groupI.end(), k) != groupI.end());
groupI.push_back (k);
And we got it. :)
An example of randomly generating heterogeneous numbers is shown below.
std::vector<int> groupI;
int k;
do {
k = 0 + (std::rand() % (int)(41 - 0 + 1));
}
while (std::find(groupI.begin(), groupI.end(), k) != groupI.end());
groupI.push_back (k);
And we got it. :)
Subscribe to:
Posts (Atom)

