Skip to content

Instantly share code, notes, and snippets.

View jymchng's full-sized avatar
🎯
Focusing

Jim Chng jymchng

🎯
Focusing
  • Singapore
  • 23:24 (UTC +08:00)
View GitHub Profile
@jymchng
jymchng / create-c-project-template.sh
Created July 5, 2024 09:21
create-c-project-template.sh
#!/bin/bash
# Function to create directories
create_directories() {
mkdir -p $PROJECT_NAME/{source,include,tests,build,docs,cmake}
}
# Function to create a README file
create_readme() {
cat << EOF > $PROJECT_NAME/README.md
@jymchng
jymchng / secret.test.ts
Created August 20, 2023 04:28
Typescript Secret/SyncSecret
import { describe, expect, test } from '@jest/globals';
import { Secret } from './secret';
describe('Secret<T> Class', () => {
// Test Case 1: Creating a Secret with an initial secret value
it('should create a Secret with an initial secret value', () => {
const secret = new Secret<string>('mySecret');
expect(secret.toString()).toBe('Secret<string>');
expect(secret.exposeSecret()).toBe('mySecret');
});
@jymchng
jymchng / consts.py
Created July 24, 2023 16:17
Python consts
import ast
from ast import NodeVisitor
import inspect
import textwrap
from types import MethodType
from typing_extensions import Annotated
from abc import ABCMeta
from pydantic.main import ModelMetaclass
@jymchng
jymchng / median.cpp
Last active July 29, 2023 03:36
Calculating median at compile time and writing a C++ function that returns different types.
#include <algorithm>
#include <array>
#include <iostream>
#include <cassert>
#include <cstddef>
#include <typeinfo>
template <std::size_t N>
struct IsSizeEven : std::integral_constant<bool, (N % 2) == 0>
{
@jymchng
jymchng / add_text_to_right_of_logo
Last active September 17, 2022 15:01
add_text_to_right_of_logo
@jymchng
jymchng / _partial.py
Created August 20, 2022 13:39
Make partial out from a function.
def _partial(func, *args, **keywords):
@wraps(func) # functools.wraps doesn't wrap func, so add it here
def newfunc(*fargs, **fkeywords):
newkeywords = {**keywords, **fkeywords}
return func(*args, *fargs, **newkeywords)
newfunc.func = func
newfunc.args = args
newfunc.keywords = keywords
return newfunc
@jymchng
jymchng / _parse_xlxs_merged_cells
Last active June 15, 2022 16:11
Given a Excel (.xlsx) file with merged cells, returns a pandas DataFrame with its unmerged cells' values appropriately filled.
from openpyxl.workbook import Workbook
from openpyxl import load_workbook
from openpyxl.utils.cell import range_boundaries
import pandas as pd
import numpy as np
def _parse_xlxs_merged_cells(filepath, how='top-left'):
"""
Takes in a Path-like object specifying the .xlsx file and returns a pandas DataFrame with unmerged cells' values
appropriately filled.