Showing posts with label python. Show all posts
Showing posts with label python. Show all posts

Wednesday, May 11, 2011

I've Just Learned About Bloom Filter

Although the algorithm was invented at about the same time that I was born, I've just understood how Bloom filter works today :-)

From Wikipedia page, the Bloom filter "is a space-efficient probabilistic data structure that is used to test whether an element is a member of a set. False positives are possible, but false negatives are not. Elements can be added to the set, but not removed (though this can be addressed with a counting filter). The more elements that are added to the set, the larger the probability of false positives."

Here's a discussion about a 22-line Python implementation of the filter.

Friday, January 21, 2011

A Few Webpages For Math Teachers And Learners

If you are teaching math to kids or if you find math interesting, here are a few websites that you might enjoy.

The Virtual Math Tutor site contains solved math problems for high school and college levels.

Math Magic contains a bunch of mathematical puzzles that you might enjoy. The archive goes back to 1998.

Project Euler contains puzzles for math and programming. The intended audience would "...include students for whom the basic curriculum is not feeding their hunger to learn, adults whose background was not primarily mathematics but had an interest in things mathematical, and professionals who want to keep their problem solving and mathematics on the edge."



Monday, August 24, 2009

Useful Unicode Information For Thai Language


I needed to convert a bunch of files saved in a few Unicode encodings and I found the Unicode table for you, Unicode HOWTO (for Python), and Ascii Table MS-DOS Codepage 874 (Thai) pages very useful. I'm writing this down in case someone needs to do similar things for Thai files.

Saturday, July 11, 2009

Wednesday, December 17, 2008

If Programming Languages Were Religions...

I stumbled upon an amusing essay called "If programming languages were religions..."

It's doubly amusing that my programming language of choice (Python) and my life philosophy (Humanism) match in the comparison.

Historically I went through Satanism (Basic) to Judaism (C) to Islam (C++) to Voodoo (Perl) to Humanism (Python.)  I'm also curious about Zen Buddhism (Lisp), Taoism (Haskell), and Hinduism (Erlang) but haven't learned much about them.

Saturday, January 19, 2008

Applied Probability: How To Write A Spelling Corrector In 21 Lines Of Python

Once again Bayes' Theorem comes in handy. This time, Peter Norvig shows us how to make a not-so-bad spelling corrector. It was done in 21 lines of easy-to-understand Python! I actually could understand it in one pass of reading. (It usually takes me many reading passes to understand any algorithm--I'm dense that way.)

If you have children, they should have some basic math and probability skills. Rational thoughts need those skills. Otherwise, they won't be able to make quantitative comparisons.

Sunday, December 16, 2007

Solving Sudoku Puzzles

I was thinking about writing a program to solve Sudoku puzzles for fun. Before I started writing, I did a quick Google search to see what programs are available. The search turned up many results, the most impressive of which is this essay by Peter Norvig (who co-wrote a famous AI book and is currently the Director of Research at Google)

The full Python source is only about 100 lines and it solves hard Sudoku puzzles very quickly. Therefore, my plan to write the ultimate Sudoku solver is derailed by Dr. Norvig's brilliance

:-D

By the way, Dr. Norvig has a lot of interesting essays that anyone working with computers should take a look. My favorites are Gettysburg Powerpoint Presentation (hilarious), Einstein '05 Performance Review (even more hilarious!), Teach Yourself Programming in Ten Years (no, not a joke, but wise), and The Python IAQ: Infrequently Answered Questions.
--- - ---- - ----- ---------

P.S. I also found this extremely hilarious link about how NOT to solve Sudoku. (You need to click on Ron Jeffries' attempts for hilarity.)

Tuesday, December 11, 2007

Python: Programming Is Fun Again!

A comic from xkcd.com:


My thought exactly.

Any programmer can learn it in an afternoon and be productive in a day. As a bonus, the code is naturally easier to read, so after half a year, I can pick up my own old code again in 10 seconds. And I'm just an average amateur programmer. (Amateur = doing it for love; Professional = doing it for money. Look at the etymology here and here.)

All CS students should at least know about it. I don't understand why introductory programming classes in Thailand are being taught with C, C++, C#, or Java while half the class would copy the other half's homework. No learning happens in half of the brains!

My posts about Python in the past are here.

Thursday, February 22, 2007

My Wife Discovered Flickr and Tabblo



Click here to go to our pictures at Flickr.
Click here to go to our pictures at Tabblo.



I personally like Tabblo better because it is very easy for us to arrange pictures on the pages.  It is also made with my favorite programming language, Python.  (Well, Python and a lot of Javascript, I suppose.)

Wednesday, November 29, 2006

Web Browsing Automation

If you need to keep going to a web page that requires you to log in, then click a series of links, you might be able to automate this process and save a lot of time. Tools like PAMIE and IEUnit let you write simple scripts that will make Internet Explorer visit the site without your intervention.

For example, I use PAMIE which is a library for Python like this:

import cPAMIE
ie = cPAMIE.PAMIE('www.website-to-visit.com')

ie.imageClick('intro.jpg')
ie.textBoxSet('loginName','my_username')
ie.textBoxSet('password', 'my_password')
ie.imageClick('login.jpg')
ie.linkClick('Reports for Today')
ie.linkClick('My Report')

I saved the above commands into a file called 'myreport.py' and whenever I needs to see the report, I just doublick the file and see Internet Explorer do the logging in and clicking for me.

The password is stored in plain text, so this is not very secure if you are sharing your computer with untrusted people. However, if you are not serious about this, it can save you time, especially when your Internet is not fast and you have to wait if you visit the site manually. This way, all the waiting is done by the script, freeing you to do other better things.

Monday, August 21, 2006

If You Need To Teach Programming To Physics Students In Two Days, ...

... you can try Python! See the handbook developed at Oxford here.

Python is my favorite programming language now.* A programmer should be able to learn (and start to be productive in) Python in an afternoon using the tutorial that comes with the installation. For a more detailed introduction, Dive Into Python by Mark Pilgrim is very hard to beat. I bought his book even though he lets us see all the contents on the web, just to show my appreciation.

If you use Linux/Unix or Mac, you should already have Python installed. If you use Windows, you can download the Python installer at www.python.org or use ActiveState's package (which I use.)

There are useful collections of Python recipes at Python Cookbook and Python Grimoire. You can see and learn from example programs there.

If you are hungry for even more tutorials, you can come to this page where you will find 300+ tutorials about using Python in all kinds of things.

As for the editor and development environment, you can use the included IDLE or PythonWin editor, but I prefer SPE and PyScripter. PyScripter runs only on Windows but SPE runs everywhere that Python runs.

--- - ---- - ----- ---------
*My preferred programming languages in the decreasing order are: Python, Mathematica, C++ (which I use like C with STL), C, Perl, Delphi, and VBA. I only read Java, but do not write programs in it. I hope to learn about Haskell, Erlang, and Lisp in the coming years.

Wednesday, March 22, 2006

"สูตรสู่ความสำเร็จ"

ผมได้รับเมล์ลูกโซ่มาครับ กรุณาอ่านถึงข้างล่างนะครับ


หวัดดีคับ ....
มีข้อความดีๆ มาฝาก .... เรื่องอะไรลองอ่านเอาเองนะ
...
สูตรสู่ความสำเร็จ
ถ้า A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
มีค่าเท่ากับ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
แล้วจะพบว่า......
1) H+A+R+D+W+O+R+K = 8+1+18+4+23+15+18+11 = 98%
HARD WORK หรือ ทำงานหนัก มีค่าเท่ากับ 98 %
2) K+N+O+W+L+E+D+G+E = 11+14+15+23+12+5+4+7+5 = 96%
KNOWLEDGE หรือ ความรู้ มีค่าเท่ากับ 96 %
3) L+O+V+E=12+15+22+5 = 54%
LOVE หรือ ความรัก มีค่าเท่ากับ 54 %
4) L+U+C+K = 12+21+3+11 = 47%
LUCK หรือ โชค มีค่าเท่ากับ 47 %

ไม่มีสิ่งใดที่มีค่า 100 % เลยหรือ !!!
แล้วสิ่งใดที่มีค่าเท่ากับ 100 %

- ใช่เงินหรือเปล่า ?……… .... .....ไม่ใช่ !!!!!
(M+O+N+E+Y = 13+15+14+5+25 = 72)

- ความเป็นผู้นำหรือเปล่า ?………ไม่ใช่ !!!!!
(L+E+A+D+E+R+S+H+I+P = 12+5+1+4+5+18+19+8+9+16 = 97)

แล้วอะไรล่ะ ?


A+T+T+I+T+U+D+E = 1+20+20+9+20+21+4+5 = 100%

ATTITUDE หรือ ทัศนคติ นั่นเอง ที่มีค่าเท่ากับ 100 %
ท่านคิดเช่นนั้นหรือไม่ ทุกปัญหามีทางออก . .
บางทีแค่เพียงแต่เราเปลี่ยน "ทัศนคติ "

ของเราเสียใหม่เท่านั้นเอง มีเพียงแต่ “ทัศนคติ” ของเราเท่านั้น
ที่จะเป็นตัวนำทาง ไปสู่ความสำเร็จในชีวิต และงานที่ทำ

ความคิด & ทัศนคติ
สุดท้าย .... ลงมือทำ


ผมเลยหาคำอื่นๆที่มีค่า 100% อีก ปรากฏว่า คำว่า APOPLECTIC, DUMBFOUND, EMASCULATE, FLUORINE, HEMOGLOBIN, HOSPITAL, IMPOTENCE, INEFFICIENT, LEADERLESS, MUMMIFY, NIHILIST, PUSSY, SALACIOUS, SAVORY, SHIBBOLETH, SHRIEKING, SIMULATE, SLEEPYHEAD, SOCIALISM, SODOMITE, STARFISH, SUFFOCATED, TELEPHONE, TELESCOPE, THIRTY, WHENEVER, WHOLESALE, และWHORISH ก็มีค่า 100% เหมือนกัน (คุณสามารถดูคำอื่นๆอีกหลายร้อยคำโดยดาวน์โหลดไฟล์นี้)

อย่าซีเรียสครับ อย่าซีเรียส :-)

(I found these words by using the list of words from here and wrote a small Python program to process the words. Everything (the word list, the program, and the output) can be downloaded from here.)

Sunday, May 08, 2005

Python & Java Programming Links

If you want to use Unicode in Python, I recommend End to End Unicode Web Applications in Python by Martin Doudoroff. It's simple, short, and informative.

Another excellent article about using Unicode is "The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)" by Joel Spolsky.

If you want to develop Java applications that support the Thai language, IBM has a useful article here.

I'm checking out CherryPy which claims to be "a pythonic, object-oriented web development framework." It seems simple enough for me to work with. We'll see.