Giới thiệu Virtual Environment trong Python

x-post from kipalog.com Virtual Environments là gì và dùng để làm gì? Virtual Environment dịch nôm na là môi trường ảo :D Cũng giống như máy ảo (Virtual Machine), Virtual Environment thiết lập một môi trường ảo, cho phép bạn nghịch ngợm lung tung với các packages của Python mà không làm ảnh hưởng đến những packages đã được cài đặt sẵn trên Python. Ví dụ bạn muốn thử nghiệm với Django 1.8 trong khi trên hệ thống đang cài đặt Django 1.4 LTS. Cũng giống như việc bạn dùng Virtual Machine để thử nghiệm phiên bản Chrome beta mới

WordPress Permalink Settings on Windows Hosting

My 2 cents: You should not host WordPress (or any script other than ASP, .NET) on Windows hosting. Try Linux. You will not be disappointed. In case you still want to use Windows hosting for your WordPress, here is a piece of code that will save you lots of time trying to figure out how to update Permalink Settings on WordPress. You will probably got this message: You should update your web.config now. Open FTP and put the following into web.config file (create a new one if you can’t see it) <?xml version=”1.0″ encoding=”UTF-8″?> <configuration> <system.webServer> <rewrite> <rules> <rule name=”wordpress”

New API: Expand URL

Today, the Internet is flooded with shortened URL. All links shared on Twitter are shortened (start with t.co). There is nothing wrong with it. I just don’t feel comfortable clicking a shortened URL without knowing where it will bring me to. How paranoid I am! There are several reason I don’t trust shortened URL: They might contain tracking or referral code. SlickDeals heavily uses it (to make money, of course). Again, there is nothing wrong with it. They provide you a service and they deserve to get some money out of it. They might hide malicious URL, like XSS I

Free course: The Complete iOS 7 Course – Learn by Building 14 Apps (was $499)

I always want to learn how use build an iOS app, and I have some idea in mind. However, I’m just lazy and procrastinating to do so. Today I found a free course (via Slickdeal) to build an iOS app, and already registered (and you should). It’s free (was $499). Link: http://bitfountain.io/course/the-complete-ios-7-course-learn-by-building-14-apps/?couponCode=COUPON111677

Markdown is available for self-hosted WordPress through Jetpack

Jay! I’ve just noticed that. It’s funny when searching for Markdown on WordPress return this article: Write (More) Effortlessly With Markdown Basically, they mentioned that Markdown is only available for WordPress.com blog, by a simple switch in configuration. I am skeptical, so I always try to use “official” version of plugins. Yes, there are many Markdown plugins out there http://wordpress.org/plugins/tags/markdown When I check my Jetpack version, it’s already there! So if you want to write in Markdown style (like Github and StackOverflow), just enable it (why not?).

Today I Leaned (the hard way): The difference between dict and list and Python

Lookup time for dict() is O(1) and for list() is O(n) no matter what the number of elements is. Given a list of elements in a file, this piece of code: from itertools import izip lists = map(str.strip, open(‘dict.txt’).readlines()) i = iter(lists) j = range(len(lists)) dicts = dict(izip(i, j)) index = dicts[w] is n time faster than this piece of code: dicts = map(str.strip, open(‘dict.txt’).readlines()) index = dicts.index(w) I learned that the hard way. My dict has 5,000,000 elements, which mean my code will run 5 millions time slower than it should be. As such, I ran my code on

Thử một bài viết có rất nhiều tiếng Việt

Bài viết này lẽ ra đã không được publish. Mục đích của mình chỉ là kiểm tra xem WordPress 3.4 xử lý tiếng Việt trong Permalink như thế nào. Trước 3.4, WordPress xử lý việc này không tốt, cụ thể là với tiêu đề như trên, WordPress sẽ xử lý thành “thử-một-bai-viết-co-rất-nhiều-tiếng-việt”. WordPress 3.4 đã xử lý việc này rất tốt, URL trở thành “thu-mot-bai-viet-co-rat-nhieu-tieng-viet”. Dưới đây là đoạn code được mình viết và đặt trong file wp-includes/formatting.php để xử lý tiếng Việt trong Permalink. WordPress 3.4 cũng có một đoạn xử lý tương tự nhưng đã tối ưu và

How to disable comment box from Facebook like widget

It have been a long time since the last time I used Facebook like widget on my blog. At that time, I feel that Facebook scripts take a lot of time to load, hence slowdown my site and affect its performance. Today, I changed my mind and add it back. With just 2 pieces of code (one load all.js at bottom and one load the like button), Facebook like button appears again on my site. Sweet and simple! But wait. When I test by click on Like button, an ugly comment box appear: As this is unexpected, I want to

How to format bytes to kilobytes, megabytes, gigabytes in PHP

This is the best function I found on StackOverflow: function formatBytes($bytes, $precision = 2) { $units = array(‘B’, ‘KB’, ‘MB’, ‘GB’, ‘TB’); $bytes = max($bytes, 0); $pow = floor(($bytes ? log($bytes) : 0) / log(1024)); $pow = min($pow, count($units) – 1); // Uncomment one of the following alternatives // If 1 kilobytes = 1024 bytes // $bytes /= pow(1024, $pow); // If 1 kilobytes = 1000 bytes // $bytes /= (1 < < (10 * $pow)); return round($bytes, $precision) . ' ' . $units[$pow]; }

CSS: How to add width and height attributes to anchor tag

You might face this problem sometimes: You want to add width and height to an anchor instead of giving these attributes to its container. Surprisingly, width and height attribute are not works. For example, consider the following codes: a.ansok { width:86px; height:41px; line-height:41px; background-image: url(../images/layout/button.png); } And here is what you will get (instead of beautiful buttons): So, what is the reason and how to fix it? Well, anchor tags are not block level HTML elements but rather inline elements. So what is the difference between the two? Here is the definition of the two items: Inline Element definition: Inline