Skip to content

Instantly share code, notes, and snippets.

View thuandt's full-sized avatar
💀
This.isDevOps(powah_code=36)

Thuan Duong thuandt

💀
This.isDevOps(powah_code=36)
View GitHub Profile
@thuandt
thuandt / no_accent_vietnamese.py
Created August 22, 2012 03:07
Chuyển đổi từ Tiếng Việt có dấu sang Tiếng Việt không dấu
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Chương trình chuyển đổi từ Tiếng Việt có dấu sang Tiếng Việt không dấu
Chỉnh sửa từ mã nguồn của anh NamNT
http://www.vithon.org/2009/06/14/x%E1%BB%AD-ly-ti%E1%BA%BFng-vi%E1%BB%87t-trong-python
"""
import re
INTAB = "ạảãàáâậầấẩẫăắằặẳẵóòọõỏôộổỗồốơờớợởỡéèẻẹẽêếềệểễúùụủũưựữửừứíìịỉĩýỳỷỵỹđẠẢÃÀÁÂẬẦẤẨẪĂẮẰẶẲẴÓÒỌÕỎÔỘỔỖỒỐƠỜỚỢỞỠÉÈẺẸẼÊẾỀỆỂỄÚÙỤỦŨƯỰỮỬỪỨÍÌỊỈĨÝỲỶỴỸĐ"
@thuandt
thuandt / unique_digit_prime.py
Created December 8, 2012 23:53 — forked from lewtds/unique_digit_prime.py
Tìm số nguyên tố lớn nhất có 9 chữ số và các chữ số khác nhau từng đôi một
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Filename: prime.py
#
# Description: Tìm số nguyên tố lớn nhất có 9 chữ số khác nhau
#
# Created: 12/09/2012 06:32:33 AM
# Last Modified: 12/09/2012 06:40:49 AM
@thuandt
thuandt / python_random_item.md
Created January 11, 2013 13:21
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',

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

import sys
def gcd(a, b):
t = b
b = a % b
if b == 0:
return t
else:
return gcd(t, b)
#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,
@thuandt
thuandt / star_animation.cpp
Created March 12, 2013 06:31
Star Animation
#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);
glShadeModel(GL_FLAT);
@thuandt
thuandt / umask
Created May 1, 2013 06:37
UNIX/Linux 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------)
@thuandt
thuandt / bash_shortcuts
Created May 1, 2013 21:39
Keyboard Shortcuts for Bash
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
thuandt / XenServer-software-RAID1.md
Last active June 4, 2017 08:26
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