Skip to content

Instantly share code, notes, and snippets.

View xuhang57's full-sized avatar
๐Ÿ
Never

Lucas H. Xu xuhang57

๐Ÿ
Never
  • Menlo Park, CA
View GitHub Profile
@xuhang57
xuhang57 / nbd.sh
Created July 31, 2017 14:47
Build Network Block Device Kernel Module On CentOS7
uname -r
sudo su
# useradd builder
# groupadd builder
cd /home/centos
# Get Source Code
wget http://vault.centos.org/7.2.1511/updates/Source/SPackages/kernel-3.10.0-327.28.3.el7.src.rpm
rpm -ivh kernel-3.10.0-327.28.3.el7.src.rpm
# Build Preparation
@xuhang57
xuhang57 / static-vs-class.py
Last active August 21, 2017 15:04
Difference between @classmethod and @staticmethod in python
# https://stackoverflow.com/questions/12179271/meaning-of-classmethod-and-staticmethod-for-beginner/12179325#12179325
# @classmethod means: when this method is called, we pass the class as the first argument instead of
# the instance of that class (as we normally do with methods).
# This means you can use the class and its properties inside that method rather than a particular instance.
# @staticmethod means: when this method is called, we don't pass an instance of the class to it
# (as we normally do with methods).
# This means you can put a function inside a class but you can't access the instance of that class
# (this is useful when your method does not use the instance)
@xuhang57
xuhang57 / how-to-use-super().py
Last active September 27, 2017 18:28
Super() in python
# https://stackoverflow.com/a/33469090/8379419
# Dependency Injection
# Other people can use your code and inject parents into the method resolution:
class SomeBaseClass(object):
def __init__(self):
print('SomeBaseClass.__init__(self) called')
@xuhang57
xuhang57 / keybase.md
Last active March 2, 2018 03:59
claims for keybase

Keybase proof

I hereby claim:

  • I am xuhang57 on github.
  • I am xuhang57 (https://keybase.io/xuhang57) on keybase.
  • I have a public key ASDZtjCtXp-eu8ix7SewdhQHIQRiVfstD3xYhWV015a8xAo

To claim this, I am signing this object:

@xuhang57
xuhang57 / mergesort.py
Last active June 19, 2018 08:18
Merge Sort
def merge(left, right):
res = []
i, j = 0, 0
while i < len(left) and j < len(right):
if left[i] <= right[j]:
res.append(left[i])
i+=1
else:
res.append(right[j])
@xuhang57
xuhang57 / insertionsort.py
Created June 19, 2018 08:16
Insertion Sort
def insertion_sort(arr):
for i in range(1, len(arr)):
cur_val = arr[i]
# indexes of the previous values
j = i-1
while j>=0 and cur_val < arr[j]:
arr[j+1] = arr[j]
j -= 1
@xuhang57
xuhang57 / selectionsort.py
Created June 19, 2018 08:30
Selection Sort
def selection_sort(arr):
for i in range(len(arr)):
min_idx = i
for j in range(i+1, len(arr)):
if arr[min_idx] > arr[j]:
min_idx = j
arr[i], arr[min_idx] = arr[min_idx], arr[i]
return arr
@xuhang57
xuhang57 / quicksort.py
Created June 19, 2018 08:34
Quick Sort (v1)
def quick_sort(arr):
smaller, equal, greater = [], [], []
if len(arr) > 1:
pivot = arr[0]
for x in arr:
if x < pivot:
smaller.append(x)
elif x == pivot:
equal.append(x)
@xuhang57
xuhang57 / ds.py
Created January 21, 2019 20:08
Basic Data Structure in Python (Interview)
# String
string = ""
# Tuple
t = tuple() # (), (1,)
# List (Array)
l = []
# Stack, LIFO
@xuhang57
xuhang57 / syntax.s
Created February 28, 2019 19:22 — forked from mishurov/syntax.s
AT&T assembly syntax and IA-32 instructions
# --------
# Hardware
# --------
# Opcode - operational code
# Assebly mnemonic - abbreviation for an operation
# Instruction Code Format (IA-32)
# - Optional instruction prefix
# - Operational code