Posted onWord count in article: 279Reading time ≈1 mins.
Approach 1: Linear Search
Our first solution is using dictionary. This has a O(1) complexity for setting and O(n) for getting, as we have to perform linear search. There are two tricks:
Extending the defaultdict class.
Chaining the .get(key, {}).items() expressions to make code looks more elegant.
defget(self, key: str, timestamp: int) -> str: max_time = 0 res = "" for time, val insuper().get(key, {}).items(): if max_time < time <= timestamp: max_time = time res = val return res
However, the runtime exceeded limit when testing on LeetCode.
Posted onEdited onWord count in article: 529Reading time ≈2 mins.
This post tests the color scheme of note tags in modern style. I have created a dark mode color scheme for the them and is waiting for the pull request to be merged.
Posted onEdited onWord count in article: 665Reading time ≈2 mins.
This post proposes a Pythonic implementation of Trie data structure, with insert, search, and starts_with methods. With careful design, the Pythonic improvements reduced the lines of code from 27 lines to 8 lines.
Posted onEdited onWord count in article: 239Reading time ≈1 mins.
This solution beats 98.90% solutions on LeetCode by runtime and 98.03% by memory usage. My notes for this problem can be found at here.
1 2 3 4 5 6 7 8 9
substr = "" for c in s: index = substr.rfind(c) if index == -1: substr += c else: substr = substr[index + 1 :] + c max_len = len(substr) iflen(substr) > max_len else max_len return max_len
Posted onEdited onWord count in article: 523Reading time ≈2 mins.
When migrating older posts to new website system, the images stored in my Gitee repo were not loading. Interestingly, these images were accessible directly through the browser. My first thought was that the loading process was timing out since Gitee’s servers are in China. However, this didn’t make sense as the images loaded in a reasonable amount of time in browser.
After an unsuccessful search in English, I switched to searching in Chinese. This instantly led to the solution. There’s a large Hexo community in China and a specific Chinese term for this type of image storage, “figure bed” (图床), which helped me find the solution efficiently
Posted onEdited onWord count in article: 571Reading time ≈2 mins.
Background
I have two domains registered:
sghuang.com, with my initials for English and Chinese first names and last name.
guanchao.pro, with my first name in Chinese.
Since my portfolio is oriented towards English speakers (for now,) I want to point the secondary domain to the primary one while ensuring URLs with paths can still be accessed. The primary domain is used for this website hosted on GitHub Pages.
Cloudflare is used as the nameserver and provides simple proxy features.
Posted onEdited onWord count in article: 562Reading time ≈2 mins.
What a longstanding issue in the history of web! Traditionally, when rendering HTML, a soft line break would be treated as a space. This makes sense for European languages consist of words, but not for CJK languages – there are no spaces in CJK languages!
Solution
Here are three links that lead to the solution to this issue in Hexo:
Posted onEdited onWord count in article: 99Reading time ≈1 mins.
This is the project for course CSE 60467 Data Science. In this project, I led a team of three students to conduct analysis on the sentiments of comments related to climate change on Reddit. I was responsible for clustering analysis and project management. The dataset we used can be found on SocialGrep For more details, view our project report.
Here are some of the interesting insights we found from the dataset.
The longer the comment, the stronger the sentiment.
Sentiment vs Comment Length
There are more discussions on climate change in summers and winters.
Posted onEdited onWord count in article: 90Reading time ≈1 mins.
This project is for course CSE 40373 Embedded System Development in 2024 Spring semester.
In this project, I created a system that employs a motion sensor to detect nearby movements, triggering a camera to capture an image when motion is detected. This image is then processed using the YOLOv8 model for object recognition. If the object is an animal of interest, users receive a push notification on their iPhone via the Bark API, and the image is uploaded to Google Drive.
Posted onEdited onWord count in article: 32Reading time ≈1 mins.
Project for course SME306 Advanced Digital CMOS IC Design in Spring 2023 semester. We designed and simulated a 180nm process 4x4 bit array multiplier using Cadence. The layout is displayed below.
This summer research stint was packed with collaboration and hands-on experience, especially with Git and GitHub. Our Senior Software Engineer initially helped us tidy up our Git history, setting a solid foundation for the work ahead. I also dove into the book Pro Git to deepen my understanding. By summer’s end, I was the go-to person for resolving Git issues among my peers!
Visit here to view a all my pull requests. The two major contributions I made are described in the following sections.
Transaction Log Visualization
I developed a Python tool to designed to visualize the transaction logs generated by work_queue in order to identify performance bottlenecks in the distributed computing system. Recognizing that matplotlib alone was inadequate for this task, I conducted research on alternatives and decided to utilize the Bokeh library.
The source code of this tool, note that it has likely been enhanced since I initially developed it.
The following are examples of generated visualization.
Viz-1Viz-2
It’s incredibly rewarding to see my work make a lasting impact! After my first stint at CCL, I was thrilled to learn that:
This visualizer is actively used in research, the graphs it created were featured in the research papers.
CCL is in the process of developing a new online dashboard, which continues to use Bokeh for interactive visualizations. It’s great to see that my choice of technology has been well-received and adopted for ongoing projects!
I’m not sure if this is even a sensible request, but it would be really nice if you could “drain” a work queue factory–in other words, tell a factory that it should reduce the number of connected workers, but only by removing workers after they complete their current tasks.
6 years after this feature request is proposed, I claimed this issue and implemented a mechanism to reduce the number of distributed workers without compromising task progress.
For more details see the Pull Request #2912. I quote from it the way I design this system:
Work Queue Factory includes FACTORY_NAME to indicate where the workers come from.
A command line argument for work_queue_factory to specify factory_name.
A command line argument --from-factory <factory_name> for work_queue_worker.
In read_config_file, work_queue_factory launches the workers with --from-factory=.. argument.
Factory reports this workers_max to the catalog server.
Manager reads the info and take actions.
Manager reads workers_max from the catalog server.
Manager maintains a dictionary of factory structs.
Manager sends shutdown signal to excessive workers in the factory that are not running any tasks.
Do not dispatch tasks to workers until currently connected workers is less then workers_max.
Whenever the last task on the worker is returned, shut down that worker.
Posted onEdited onWord count in article: 97Reading time ≈1 mins.
This post describes my project for course CSE 40932 Exotic Computing in Spring 2022. In this project, I developed a UTM with text interface using Python. It supports several command line options, takes input and rules from files, and display the steps as the emulator runs.
As a side-note, during the course, I helped Prof. Kogge fix many typos and errors from the book he was writing, The Zen of Exotic Computing and was included in the acknowledgement section.
Posted onEdited onWord count in article: 106Reading time ≈1 mins.
This post details my project for SME309 Microprocessor Design in Fall 2021 semester. In this project, I wrote a microprocessor that implements basic instructions of AMRv3 along with a multi-cycle multiplier. As a side-note, I achieved a score of 98/100 for this course, and ranked the first in the final exam.
Posted onEdited onWord count in article: 127Reading time ≈1 mins.
This course project for Digital Image Processing integrates LSB steganography in images with Hamming Code error correction. I chose this topic because I was fascinated by the video made by 3Blue1Brown explaining Hamming Code, and I have a strong interest in bit operations.
You can learn more about this project by reading the comprehensive project report.
Challenges Encountered
accuracy
Hamming Code cannot recover from excessive bit errors caused by significant damage to the image file.
I wasn’t familiar with Git at the time, the commit history was unclear.
Successes Achieved
Several elegant code snippets were developed, which I’m proud of.
The code is fairly Pythonic, many builtin features are utilized.
path = 'labels/' withopen(path + 'label_train.txt', 'w') as fw: for i inrange(1, 201): file_name = path + str(i).rjust(7, '0') + '.txt' withopen(file_name, 'r') as fr: for line in fr.readlines(): fw.write(line.strip() + ' ') fw.write('\n')
Posted onEdited onWord count in article: 167Reading time ≈1 mins.
This post details my project for the CSE203B course, Design and Analysis of Algorithms B1, in which I led a team of four students. Our main task was to implement Strassen algorithm, a classic example of recursion. To fully embrace this challenge, we opted to develop our own matrix library rather than relying on NumPy. This project was my first taste of Python OOP and magic methods – and it was enjoyable!
Posted onEdited onWord count in article: 2.9kReading time ≈10 mins.
This document is intended for the reviewing of the course Fundamentals of Electric Circuits.
Preface
Current
Current is the rate of charge flow past a given point in a given direction.
$$
i = \frac{\mathop{dq}}{\mathop{dt}}
$$
Voltage
Voltage is the energy required to move 1 C of charge through an element.
$$
v = \frac{dw}{dq}
$$
Power
Power is the energy supplied or absorbed per unit time.
$$
p = \frac{dw}{dt} = vi
$$
Passive Sign Convention
Passive sign convention is satisfied if the direction of current is selected such that current enters through the terminal that is more positively biased.
Law of Energy Conservation
∑p = 0
Sources
An ideal voltage source has zero internal resistance and is capable of producing any amount of current.
An ideal current source has infinite resistance. It is able to generate any voltage to establish the desired current through it.