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 / cleandb.sh
Created July 29, 2019 14:56
Mariadb drop database and free the disk space
#!/bin/sh
# mysqldump -u[root] -p[root_password] [database_name] > [dbdump].sql
mysqladmin -u[root] -p[root_password] drop [database_name]
sudo systemctl stop mariadb
sudo rm /var/lib/mysql/ibdata1
sudo rm /var/lib/mysql/ib_logfile*
sudo systemctl start mariadb
# mysqladmin -u[root] -p[root_password] create [database_name]
# mysqladmin -u[root] -p[root_password] [database_name] < [dbdump].sql
@xuhang57
xuhang57 / loadbalancer.sh
Last active July 9, 2019 18:28
Octavia (Load Balancer project in OpenStack) tests
# Create a load balancer
openstack loadbalancer create --name lb1 --vip-subnet-id <SubnetName("public")>
# Create a listener
openstack loadbalancer listener create lb1 --protocol HTTP --protocol-port 80 --name listener1
# Create a pool
openstack loadbalancer pool create --lb-algorithm ROUND_ROBIN --listener listener1 --protocol HTTP --name pool1
# Create a health monitor
@xuhang57
xuhang57 / launch.sh
Last active August 5, 2019 13:27
OpenStack Launch an VM via the OpenStack CLI
# create a flavor which would be used by the instance
openstack flavor create --id 0 --vcpus 1 --ram 2048 --disk 20 m1.small
#openstack flavor create --id 1 --vcpus 4 --ram 8192 --disk 80 m1.large
#openstack flavor create --id 2 --vcpus 8 --ram 16384 --disk 160 m1.xlarge
# create a network
openstack extension list -c Alias -c Name --network # list extensions within the system
openstack network create net1
#openstack network create net2 --provider-network-type vxlan
openstack subnet create subnet1 --network net1 --subnet-range 192.0.2.0/24
@xuhang57
xuhang57 / memory.java
Last active April 24, 2019 16:53
Stack Memory and Heap Space in Java
/* https://www.baeldung.com/java-stack-heap */
class Person {
int pid;
String name;
// constructor, setter/getters
}
public class Driver {
/**
* 1. Upon entering the main() method, a space in stack memory would be created to store primitives
@xuhang57
xuhang57 / concurrency.java
Last active March 27, 2019 18:36
Code Snippet on Java Concurrency
/*
Using the synchronized keyword to protect blocks of code within a method.
This block is guarded by a key, which can be either a string or an object
This key is called the lock
*/
public synchronized void critial() {
// some thread critical stuff
}
@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
@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 / 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 / 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 / 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