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 / 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 / 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 / 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 / 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 / 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