Skip to content

Instantly share code, notes, and snippets.


Thuan Duong thuandt

  • Ho Chi Minh, Vietnam
View GitHub Profile
thuandt / userChrome.css
Last active Aug 29, 2015
View userChrome.css
/* Disable "List all Tabs" Button */
.tabs-alltabs-button {
display: none !important;
/* Disable Container box for "List all Tabs" Button */
.tabs-alltabs-box {
display: none !important;
thuandt /
Created Oct 30, 2013
Create XenServer USB Install

Installing XenServer 6.2.0 from a USB Stick

  • Download the XenServer 6.2.0 ISO image

  • Format a USB stick using FAT32.

  • Use unetbootin to install the ISO to the USB stick. Use the “DiskImage” option instead of the “Distribution” one, and point it right to the ISO file.

  • Now we need to fix up some boot stuff (All paths are relative to the root of the USB drive)

thuandt /
Last active Jun 4, 2017
Instructions for switching to RAID 1 for XenServer 6.2 with GPT

Instructions for switching to RAID 1 for XenServer 6.2 with GPT

  • Create new partition for Local Storage
# gdisk /dev/sda
  • Check /dev/sda partition table
thuandt / bash_shortcuts
Created May 1, 2013
Keyboard Shortcuts for Bash
View bash_shortcuts
Ctrl + A Go to the beginning of the line you are currently typing on
Ctrl + E Go to the end of the line you are currently typing on
Ctrl + L Clears the Screen, similar to the clear command
Ctrl + U Clears the line before the cursor position. If you are at the end of the line, clears the entire line.
Ctrl + H Same as backspace
Ctrl + R Let’s you search through previously used commands
Ctrl + C Kill whatever you are running
Ctrl + D Exit the current shell
Ctrl + Z Puts whatever you are running into a suspended background process. fg restores it.
Ctrl + W Delete the word before the cursor
thuandt / umask
Created May 1, 2013
UNIX/Linux umask
View umask
Umask Created Files Created Directories
000 666 (rw-rw-rw-) 777 (rwxrwxrwx)
002 664 (rw-rw-r--) 775 (rwxrwxr-x)
022 644 (rw-r--r--) 755 (rwxr-xr-x)
027 640 (rw-r-----) 750 (rwxr-x---)
077 600 (rw-------) 700 (rwx------)
277 400 (r--------) 500 (r-x------)
View star_animation.cpp
#include <GL/gl.h>
#include <GL/glut.h>
#include <cmath>
static GLfloat spin = 0.0;
void init(void)
glClearColor(0.0, 0.0, 0.0, 0.0);
View raster_font.cpp
#include <GL/gl.h>
#include <GL/glut.h>
GLubyte rasters[24] = { 0x00, 0x00,
0x06, 0x00,
0x06, 0x00,
0x06, 0x00,
0x06, 0x00,
0x06, 0x00,
0x06, 0x00,
import sys
def gcd(a, b):
t = b
b = a % b
if b == 0:
return t
return gcd(t, b)
View latency.markdown

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs
Read 1 MB sequentially from memory ..... 250,000 ns  = 250 µs
thuandt /
Created Jan 11, 2013
Select a random item from a list/tuple/data stucture in Python

One of the most common tasks that requires random action is selecting one item from a group, be it a character from a string, unicode, or buffer, a byte from a bytearray, or an item from a list, tuple, or xrange. It’s also common to want a sample of more than one item.

Don’t do this when randomly selecting an element

A naive approach to these tasks involves something like the following; to select a single item, you would use randrange (or randint) from the random module, which generates a pseudo-random integer from the range indicated by its arguments:

import random
items = ['here', 'are', 'some', 'strings', 'of',