Showing posts from February, 2015

New "car"

I just bought a new bicycle and started riding to work every day for a week. I will have to ride more than 20 km a day. It's pretty awesome huh? Gonna loose some weight! \m/

Auto create and populate UserProfile in Django 1.7 with django-auth-ldap

To map some extra information of the Active Directory user into my Django's StudentProfile (UserProfile) model (Django 1.7 and django-auth-ldap 1.2.5), I have to call a post_save signal: In my from django.db import models from django.contrib.auth.models import User from django.db.models.signals import post_save from django_auth_ldap.backend import LDAPBackend class StudentProfile (models.Model): user = models.OneToOneField(User, related_name="student_profile", related_query_name="profile") student_number = models.CharField(max_length=255) # Office class_of = models.CharField(max_length=255) # Description def create_student_profile (sender, instance, created, **kwargs): if created: new_profile = StudentProfile.objects.create(user=instance) user = LDAPBackend().populate_user(instance.username) if user: desc = user.ldap_user.attrs.get("description", [])[0] office = user.ldap_user.attrs.get("physicalDel

Toggle Find-and-Replace panel in Atom editor

To be able to toggle Find-and-Replace panel in Atom (v0.182.0), add this following lines to your keymap.cson: '.platform-win32, .platform-linux':   'ctrl-f': 'find-and-replace:toggle'   'ctrl-shift-f': 'project-find:toggle'

To make Atom remember your last session

To enable Atom to remember your last session whenever you re-open it, install this plugin Github repo: >> Edit >> Preferences >> Install >> search for "save-session", install. Close Atom, and reopen it to see the magic.

Hide TreeView in Atom by default

To stop Atom keeps showing TreeView whenever you open the editor: >> Edit >> Open Your Init Script >> Old way: atom.workspaceView.trigger 'tree-view:toggle' New way (Atom v0.181.0): atom.commands.dispatch atom.views.getView(atom.workspace), 'tree-view:toggle' Save!

Show invisible characters in Atom editor except EOL and CR

In Atom editor to show invisible characters (tab, space) except the EOL and CR: >> Edit >> Open Your Config add the following: "*":   editor:     invisibles:         'cr': ''         'eol': ''         'space': '·'         'tab': '⇥'     showIndentGuide: true     showInvisibles: true ... Save and enjoy!

Enable long line words wrap in Sublime Text 3

Add this line to Preferences >> Settings-User : "word_wrap": "true",

Could not run rails console in gitlab due to missing readline

Yesterday, I was trying to open the rails console of my gitlab server (gitlab v6.9.2, Ubuntu 12.04) to reset the admin password by the following command: $ cd /home/git/gitlab $ sudo -u git -H bundle exec rails console production But it raised this error: ... `require': no such file to load -- readline (LoadError) ... After a while, I fixed it by ( DO NOT MODIFY THE GEMFILE ): 1. Install readline dev packages: $ sudo apt-get install libreadline-dev 2. Recompile or upgrade ruby to v2.1: Note: The use of Ruby version managers such as RVM, rbenv or chruby with GitLab in production frequently leads to hard to diagnose problems. For example, GitLab Shell is called from OpenSSH and having a version manager can prevent pushing and pulling over SSH. Version managers are not supported and we strongly advise everyone to follow the instructions below to use a system Ruby. Install the required packages to compile ruby: $ sudo apt-get install -y build-essential zlib1g-de

How to fix apt-get upgrade/install fail error related to linux-headers-server unmet dependencies

I was trying to upgrade my Ubuntu server and got this error this morning: You might want to run 'apt-get -f install' to correct these. The following packages have unmet dependencies:  linux-server : Depends: linux-image-server (= but is installed                 Depends: linux-headers-server (= but is installed E: Unmet dependencies. Try using -f. I ran the apt-get -f install  command over and over but It kept failing. Then I found the solution: $ sudo aptitude install linux-headers-server aptitude is smarter at dependency solutions than apt-get. It fixed the issue and the server is fine now. Reference:

Clean up boot partition in Ubuntu server

Sometimes you forget to clean up the old kernels and your boot partition full. That may cause you trouble when upgrading new kernel. Here is how you can clean up the boot partition when apt-get keeps telling you to "-f install" (that command keeps failing): 1. Check your current installed kernels: The running one: $ uname -r All kernels instlled: $ sudo dpkg --list 'linux-image*' Note the two newest versions in the list and the one in use (for example 68, 69, 70). 2. Remove the unused kernels (remember to exclude the current and two newest kernel images), for example: $ sudo rm -rf /boot/*-3.2.0-{23,45,49,51,52,53,54,55}-* 3. Run ' sudo apt-get -f install '   to fix the partial install 4. Finally, run ' sudo apt-get autoremove ' to clear out the old kernel image packages. Note: to see available space on the boot partition: $ sudo df -h Reference:

Tet holiday in the office

It's pretty quiet.

Introduction to Linux course by The Linux Foundation on edX

I just finished (passed the final exam with 100% :D) the Introduction to Linux course by the Linux Foundation on edX (in about 1 day): Even though I've been using Linux for almost 3 years, the course reminded me a lot of things that I rarely use. That's a really good chance to review my Linux skill. If you wanna have some new experience and advance your career, you should check this out.

MUST WATCH of the day - Elon Musk at KhanAcademy


2015 Gates Annual Letter, a MUST READ for starting 2015

If you haven't read through this letter of the Gates, do it now:

Quote of the day

"Everybody wants a good life, but not everybody willing to read to get it." ~Tai Lopez.

Bill Gates about Online Education

Bill Gates and The Verge just made a great article (video) about how online education will improve education: Video by Bill Gates : Article by  Adi Robertson :

Speaking lesson from Paul Graham

Like many other essays of Paul Graham, this one is a pretty good one, even though it's only his idea about speaking and writing: If you have ever listened any of Paul's talk you will see the essay explained a lot about that. It's because he's using his pre-written scripts when talking. But after all they are really good ones. It's really hard to be a good speaker. It is a trade-off. You have to be a bullshitter just like Paul said. Indeed, sometime you have to talk about things that you don't even care to get the attention of the audience. I don't like that. After a while, I figured out that it doesn't matter that people will like your talk, the idea that you're trying give is matter.  So, I quited being a good speaker and trying to be a good thinker and writer. I'm practicing my talk (whenever I have a chance) by writing it down somewhere, repeated it many time. I know it will not be a good show but at

Listening to radio in command line (Ubuntu 14.04) with mplayer

You heard that. It's pretty cool idea huh? Actually it's not something new. In Ubuntu (mine is 14.04), you can streaming radio using mplayer: 1. Install mplayer: $ sudo apt-get install mplayer 2. Enjoy: $ mplayer <address of the channel, ip address is recommended> for example $ mplayer For more radio channel addresses, please look up in this website:

A pretty cool command line style radio streaming website

Jesus Christ, this is so cool!!! Check it out: Getting started: 1. Type help for available commands 2. Type genres for channels 3. Type play <channel name> to play (e.g. play piano) This website is based on the jQuery Terminal plugin . Enjoy!

Find duplicated elements in a python list

This is a pretty neat python snippet to find duplicated elements in a list: def find_duplicates(my_list):   my_set = set()   tmp = seen.add   duplicates = set( x for x in my_list if x in my_set or tmp(x) )   return list( duplicates ) Try it: my_list = [1234, 456, 1234, 678, 'abc', 'abc', 'abc'] find_duplicates(my_list) # should be [1234, 'abc']

How to deploy Web-CAT automatic grading system on Ubuntu 14.04

A teacher in my school where I'm working asked me about an automatic grading software because he will teach a programming course (python) next year. After searching around Google, I found Web-CAT . The following is an excerpt from Web-CAT's website: Web-CAT is an advanced automated grading system that can grade students on how well they test their own code. It is free, open-source software. It is highly customizable and extensible, and supports virtually any model of program grading, assessment, and feedback generation. Web-CAT is implemented a web application with a plug-in-style architecture so that it also can serve as a platform for providing additional student support services to help students learn programming or software testing. Some of its key features: Customizable and extensible Plug-in-style architecture Supports student-written tests, measurement of test coverage, and grading on test thoroughness Supports static analysis tools to assess documentation an

How to enable the Disk Clean Up tool on Windows Server 2008 (R2) without installing Desktop Experience

The Disk Clean Up tool is disabled by default in Windows Server 2008 (R2). Officially, to enable the tool we have to install the Desktop Experience which will also install a whole bunch of other tools and requires us to restart the server. There is another way to do that which is way more convenient: 1. Copy Cleanmgr.exe to %systemroot%\System32 . 2. Copy Cleanmgr.exe.mui to %systemroot%\System32\en-US . Find out the location of Cleanmgr.exe and Cleanmgr.exe.mui from the table below based on your OS version: Operating System Architecture File Location Windows Server 2008 R2 64-bit C:\Windows\winsxs\amd64_microsoft-windows-cleanmgr_31bf3856ad364e35_6.1.7600.16385_none_c9392808773cd7da\cleanmgr.exe Windows Server 2008 R2 64-bit C:\Windows\winsxs\amd64_microsoft-windows-cleanmgr.resources_31bf3856ad364e35_6.1.7600.16385_en-us_b9cb6194b257cc63\cleanmgr.exe.mui Windows Server 2008 64-bit

Zhuang Zhou, the Butterfly Philosopher

This is the most famous story of a Chinese philosopher, Zhuang Zhou: English translated (source: wikipedia) : "Once upon a time, Zhuang Zhou dreamed he was a butterfly, a butterfly flitting about happily enjoying himself. He did not know that he was Zhou. Suddenly he awoke, and was palpably Zhou. He did not know whether he was Zhou, who had dreamed of being a butterfly, or a butterfly dreaming that he was Zhou. Now, there must be a difference between Zhou and the butterfly. This is called the transformation of things." ~Zhuang Zhou, "Zhuangzi" chapter 2, "On the Equality of Things". (Image source: ) Chinese: "昔者庄周梦为蝴蝶,栩栩然蝴蝶也,自喻适志与,不知周也。俄然觉,则戚戚然周也。不知周之梦为蝴蝶与,蝴蝶之梦为周与?周与蝴蝶则必有分矣。此之谓物化。" Chinese-Vietnamese translated ( source: Trang Tử Nam Hoa Kinh, Nguyễn Duy Cần ): "Tích giả Trang Châu mộng vi hồ điệp, hủ hủ nhiên hồ điệp dã, tự dụ thích chí dữ bất tri Châu dã. N

E-commerce my ass!

Last year, I had a Skype meeting with a CEO of one of the biggest e-commerce companies in Vietnam about his new venture. I was not really sure what he was excited about. They were just some crappy idea about outsourcing for the Scandinavia zone. NOT INTERESTED! And again, at the beginning of this year, I have another meeting, this time it's in person, with a guy from Singapore. He's trying to setup a team for his new project(s). He asked me about my ability to make an e-commerce website. Yes, that's it, an e-commerce website. Done. BYE. To be honest, ain't you guys tired of doing the same thing over and over again? I meant outsourcing, e-commerce... New market? My ass! Look at this . What I'm trying to say is that if it's not about Education , or about building something that will change the world, or completely new things, forget about it. Sorry, I'm not into it. Please find someone else.

Little Trinh

The typography in this photo is designed for me by designer Thanh Nguyen . It's precious. I love it! by Thanh

Setup GEM_HOME for your ruby gems installation in Ubuntu

I found this setup is pretty helpful when working with Rails projects in Ubuntu (it's 14.04 in this case): Add these lines at the end of ~/.bashrc : export GEM_HOME=$HOME/ruby/gems export GEM_PATH=$GEM_HOME:/lib/ruby/gems/1.9.3 export GEM_CACHE=$GEM_HOME/cache export PATH=$PATH:$HOME/ruby/gems/bin To get affected right away: $ source ~/.bashrc

Fix "Error: EACCES" error when running npm install

When I was trying to run npm install some packages (via bundle) yesterday, I got this error: ... npm ERR! Error: EACCES, open '/home/dangtrinhnt/.npm/-/all/.cache.json' npm ERR!  { [Error: EACCES, open '/home/dangtrinhnt/.npm/-/all/.cache.json'] npm ERR!   errno: 3, npm ERR!   code: 'EACCES', npm ERR!   path: '/home/dangtrinhnt/.npm/-/all/.cache.json' } npm ERR!  npm ERR! Please try running this command again as root/Administrator. ... It's a permission issue. So, to fix this: change the owner to myself sudo chown -R $(whoami) ~/.npm

A cool WordPress plugin to insert widget into a page using shortcode

So, you want to display a WordPress widget (which is usually in sidebar or homepage) in a page but don't know how and don't want to do any coding? This is what you need: amr shortcode any widget Plugin: All you have to do are: 1. In Appearance > Widget: drag and drop the widget you want to display in any page to the " Widgets for shortcode " section (for example: widget Tyler Points of Interest). You may want to set the title and other configuration of that widget. Then click save. 2. In any page you want to display the widget add the following shortcode: [do_widget "Tyler Points of Interest"] 3. Go to the page to see the result: