Next Spaceship

Driving into future…

How to Downgrade Your Smart Phone to a Non-Smart Phone

| Comments

There are some circumstances that you want your smart phone be a non-smart phone. For example, you may forget to charge your phone last night, and you don’t have a charger in your office, and you suddenly find the battery is less than 20%. Or you are in outdoor travel, and the battery is low, but you don’t want to shutdown your phone because you want to keep in touch with others.

A Python Implementation of Segment Tree

| Comments

Today I need to use a data structure called Segment Tree. A segment tree for a set I of n intervals uses \(O(n \log{n})\) storage and can be built in \(O(n \log{n})\) time. Segment trees support searching for all the intervals that contain a query point in \(O(\log{n} + k)\), k being the number of retrieved intervals or segments.

While I search for a Python implementation of segment tree, there is no good ones. So I write one.

Disable Third-Party Cookies

| Comments

More and more websites and abusing web cookies to track users and get private information which they shouldn’t get. Though we can trust some websites, like Google, to coollect user info for analytics and providing better service, we can not trust all websites, especially some in bad reputation. Some company even sell user info. So we have to protect ourselves.

To disable 3-party cookies if one of the most effective way to protect your privacy when surfing the web. How to do it? Follow me and I will guide you.

GitHub Workflow for Submitting Pull Requests

| Comments

The original source of this document is from OpenShift.

This document describes the recommended workflow to maintain a fork of a GitHub repository and how to submit pull requests for new features or bug fixes. The examples used on this page can be used for any GitHub repository.

How to Set Up an OpenGL Project With XCode

| Comments

If you search this topic, you find few people are talking about this. Why? because it’s too easy to set up an OpenGL project for Mac. But I still write this article, because maybe someone are finding something like a quick start.

Unlike other platforms, in Mac, you don’t need to install OpenGL independently. To use OpenGL in Mac, you need to install XCode first.

The Formula of Annual Leave Days

| Comments

Company D recently changed the policy of annual leave days, which confused many people. So I make up these mathematical formulas to make it more clear.

Assume Amy’s entry date is year \(x_0\), month \(y_0\), day \(z_0\), then \(F(x)\), the annual leave days for year \(x\) is

\( F(x) = \dfrac{\left\lfloor{2\left(f(x)+\dfrac{1}{4}\right)}\right\rfloor}{2} \)

\( f(x) = \begin{cases} \dfrac{(x - x_0 + 9)(y_0 - 1) + (x - x_0 + 10)(12 - y_0 + 1)}{12}, &\text{if $x > x_0$;}\\ \dfrac{10(13 - y_0)}{12}, &\text{if $x = x_0 , z_0 <= 15$;}\\ \dfrac{10(12 - y_0)}{12}, &\text{if $x = x_0, z_0 > 15$;}\\ \end{cases} \)

Django + uWSGI + Nginx

| Comments

This is a brief introduction of production environment configuration for Django, uWSGI and Nginx. If you haven’t installed virtualenv, do it first.

Orion’s Belt

| Comments

I suddenly realize new year is coming. It’s another year. I want to look at the Orion’s belt to make sure it is coming and learn how far is it, because when the three stars of Orion’s belt are in a line, it’s the start a new year. But when I raise my head and look up at the sky, I find nothing except polluted air.

Three Days in California

| Comments

I couldn’t believe it was true when I recieved Dave’s email that told me I was a winner of the Udacity CS101 Contest and awarded an expenses-paid to Palo Alto, California. But it was true. Thanks to Udacity.

On Saturday 07 July, I arrived at San Francisco International Airport transiting via Vancouver BC, Canada. That was my first time to take a flight. It was fabulous.

Always Set the Default Charset for DB Table

| Comments

Today, I spent a long time to find a bug. I read code, but finally I found the cause is that the character set of table is not correct.

Record this to avoid making the same mistake. Character set should always be set while a table is created. For MySQL, the syntax is:

How to Write Blog via Vim

| Comments

Today, I find a vim plugin called vimrepress. So I install it and write this blog here.

Note: this blog is expired for it was for Wordpress. However currently this blog is built with Octopress instead of Wordpress.

Checklist Before Launching a Website

| Comments

Just record these steps for possible uses in the future.

  • Check the favicon of the website

  • Check the title and meta data: add description and keywords

  • Performance test, get the maximum concurrent access the website can bear

  • Database security check

  • Database backup configuration

  • Web server backup

  • Cache images, java script and css files.

  • Use gzip to compress web pages.

  • Use a dedicate domain name and server for images and other static files.

  • Customize your 404 not found page

  • Write the robots.txt file

  • Write the sitemap.xml file

  • Use optipng to compress png and gif files

  • Use jpegoptim to compress jpeg files

  • Use Google’s Chrome and PageSpeed plugin to optimize website’s speed

  • Use Google’s Webmaster Tools to find dead links and other errors in your pages.

How to Translate Apache’s “RewriteRule” Into Nginx’s “Rewrite”

| Comments

There are many cases you need to use friendly url. If you are using Apache, tipcially you can activate the URL rewriting module and write some rewriting rules with .htaccess file; While if you are using Nginx, you can also write some rewriting rules. Both of them support regular expression, so it’s easy to translate from one to the other.

To translate from the Apache’s rewriting rule to the Nginx’s, simply do the following substitutions:

Adaptive Color Selector

| Comments

This is an adaptive color selector. It can dynamically choose which color of checkmark to use. When a light color is chosen, a black checkmark display; while when dark color is chosen, a white checkmark display.

Here is a screenshot.