Skip to content

Instantly share code, notes, and snippets.

View edward-ji's full-sized avatar

Edward Ji edward-ji

View GitHub Profile
@edward-ji
edward-ji / kepler-108-b-planets-with-transit-method.ipynb
Created August 23, 2024 11:57
Kepler-108 B Planets with Transit Method.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@edward-ji
edward-ji / print_vector.py
Created September 23, 2023 10:08
Print vector
v = [1, 2, 3]
# === str + str ===
print("{ " + str(v[0]) + ", " + str(v[1])
+ ", " + str(v[2]) + " }")
# === str.format ===
# most easy to understand
print("{{ {}, {}, {} }}".format(v[0], v[1], v[2]))
@edward-ji
edward-ji / k_means.py
Created May 17, 2023 03:56
A simple implementation of K-means clustering with NumPy.
import numpy as np
class KMeansClustering:
def __init__(self, k=2, max_epoch=10):
self.k = k
self.max_epoch = max_epoch
self._centroids = None
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@edward-ji
edward-ji / mermaidify.py
Last active March 7, 2023 08:01
Find Notion HTML exports with mermaid code and convert them.
#!/usr/bin/env python
"""
Find HTML files with mermaid code and convert them to mermaid compatible code.
Require Python3 and the `bs4` package.
"""
import os
from bs4 import BeautifulSoup
@edward-ji
edward-ji / pipe.py
Last active October 6, 2022 01:07
Simple Python Pipe
from copy import deepcopy
from typing import Any, Callable, Optional
class Call:
def __init__(self, pipable: "Pipable", *args, **kwargs):
self.pipable = pipable
self.args = args
self.kwargs = kwargs
@edward-ji
edward-ji / README.md
Last active September 12, 2022 05:40
DFA Stylizer

This Gist converts the HTML table from NFA2DFA by @cyberzhg to mathematical style $(Q, \Sigma, \delta, q_0, F)$.

Simply select the table, copy and paste it in a file with CSV extension. The pasted text should be tab separated values. For example, the CSV file should look like table.csv provided below.

Then, run python3 main.py <CSV>, e.g., python3 main.py table.tsv.

@edward-ji
edward-ji / matrix_multi.c
Created May 5, 2022 12:14
Using POSIX threads for matrix multiplication in C
/*
* Example Compilation
*
* gcc matrix_multi.c -lpthread -D USE_THREAD=3 -D NO_DISPLAY -o thread
* time ./thread
* gcc matrix_multi.c -D NO_DISPLAY -o no_thread
* time ./no_thread
*/
#ifdef USE_THREAD
@edward-ji
edward-ji / shape.c
Last active December 9, 2021 15:17
Polymorphism in C
/*
* Refer to Understanding and Using C Pointers by Richard M Reese (the book). Polymorphism
* involves the idea of struct inheritance in C language. This implementation differs from
* the one in the book. In this implementation, methods of an instance refers to a static
* constant virtual table of the constructor to save memory. The reason is that objects of
* the same class (struct) should have the same methods.
*/
#include <stdio.h>
#include <stdlib.h>
@edward-ji
edward-ji / binary_tree.py
Created October 10, 2021 09:27
Leetcode Tree Structures
class TreeNode:
LEAF_REPR = "-"
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def __repr__(self):