Crayon Kingdom A tech, develop and reading blog.

Summary and thinking on Bulb Switcher problem

Bulb Switcher Problem: There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every second bulb. On the third round, you toggle every third bulb (turning on if it's off or turning off if it's on). For the ith ... Read more
Posted at 2016-08-16 05:20:55 by Ares Ou

Compile & install 32 bit Python 2.7 on 64 bit CentOS 6.5

You might want to compile a version of Python other than shipped one on your CentOS system. For example, running a Python script using a library that only has a 32bit build. Here are the steps on how to compile & install Python 2.7.12 from source code ... Read more
Posted at 2016-06-27 04:52:56 by Ares Ou

How to check version of Python (both command-line and programmatically)

Sometimes you might want to confirm if your program will run / is running under Python 2.x or 3.x. We have a very simple way to do the stuff. Command Line Method It is really easy to confirm a Python version using the option --version of the ... Read more
Posted at 2016-04-09 18:07:59 by Ares Ou

How to directly run a Python script in a *nix environment

Under Mac or Linux environment, add a comment line at the beginning of the file: #!/usr/bin/env python3 print('hello, world') Make the .py file executable: $ chmod a+x Then, run it by typing: $ ./ You are all set! Read more
Posted at 2016-02-16 07:43:42 by Ares Ou

Difference between "is" keyword and "==" (double equal) in Python

Introduction In Python, you may know there are two basic ways to compare if two variables are the same. The first one is is keyword, the second one is == operator. So what's the difference when we use them to compare something? Let's see the code ... Read more
Posted at 2016-02-16 07:43:42 by Ares Ou

HTML&CSS Notes (Last updated on 3/5/2016)

A "Note" series that record the knowledge I gathered from my daily work and development. This is the HTML part. Disabled input field in <form> Disabled input fields in a form will not be sent when the form is submitted. Try to check the element to see ... Read more
Posted at 2016-02-16 07:43:42 by Ares Ou

JavaScript (jQuery / AngularJS) Notes (Last updated on 3/5/2016)

Better way to compare two floats When you compare two floats, you'd better not directly compare them. Because in the calculation handled by computer, some minor difference will be introduced into infinities. Try to compare floats if they are equal ... Read more
Posted at 2016-02-07 21:16:37 by Ares Ou