Skip to content

Instantly share code, notes, and snippets.

@jameshwc
jameshwc / LZW.py
Last active January 1, 2020 13:38
LZW implementation via python
def Compress(s):
dictionary = {chr(i):i for i in range(0,255)} # create dictionary according to ascii code
last = 256 # the size of dictionary
p = ""
result = []
for c in s:
pc = p+c
if pc in dictionary:
p = pc # if pc in dictionary then try to append next character until pc is not in dictionary
else:
@jameshwc
jameshwc / draw.py
Last active January 3, 2020 09:53
SP HW4 helper
import matplotlib.pyplot as plt
import os
def read_thread_time():
with open('thread_time', 'r') as file:
s = file.read()
s = s.split(',')[:-1]
s = [round(float(i),3) for i in s]
return s
@jameshwc
jameshwc / hw2-q3.py
Created October 24, 2020 11:57
IoIV HW2 Q3.py
from math import ceil
from random import randint, random
from math import e, pow
from copy import deepcopy
from time import time
def swap(transmission: list, period: list, i=None, j=None) -> tuple:
if i is None:
i, j = randint(0, n-1), randint(0, n-1)
transmission_time[i], transmission_time[j] = transmission_time[j],transmission_time[i]
@jameshwc
jameshwc / main.py
Last active March 22, 2021 07:06
nasa lab4 docker
from flask import Flask
import psutil
import time
import datetime
app = Flask(__name__)
start_time = time.time()
def in_docker():
""" Returns: True if running in a Docker container, else False """
@jameshwc
jameshwc / main.go
Created April 5, 2021 06:07
nasa midterm
package main
import (
"fmt"
"log"
"net/http"
)
func main() {
m := http.NewServeMux()