Skip to content

Instantly share code, notes, and snippets.

For creating a local static library and driver (e.g. test) program

Assuming the following files in the directory:

  • my_mem.h/my_mem.c - header and source files for library component #1
  • my_malloc.h/my_malloc.c - header and source files for library component #2
  • libmy_c.a - local static library to be created based on the above components
  • test_driver.c - source file for driver program, which includes any/all of above header files, and links to the local static library

For multi-source-file-applications

Assuming the following files in the directory (noting that the local "library" is really just an object file in this case):

  • my_library.h - header file for local library function declarations
  • my_library.c - source file for local library function definitions (i.e. implementations)
  • driver.c - source file for driver program, which has #include "my_library.h", defines main(), and calls functions defined in my_library.c

Use the following Makefile:

For single-source-file applications

# the compiler: gcc for C program, define as g++ for C++
CC = gcc

# compiler flags
#  -g    adds debugging information to the executable file
#  -Wall turns on most, but not all, compiler warnings
CFLAGS = -g3

Sample launch.json file

{
    "version": "0.2.0",
    "configurations": [
        
        {
            "name": "(gdb) dsh",
 "type": "cppdbg",
@crashka
crashka / rankdata.py
Last active March 8, 2022 01:29
Standalone implementation of scipy.stats.rankdata, adapted from https://stackoverflow.com/a/3071441
from collections.abc import Sequence
from numbers import Number
def rankdata(a: Sequence[Number], method: str = 'average', reverse: bool = True) -> list[Number]:
"""Standalone implementation of scipy.stats.rankdata, adapted from
https://stackoverflow.com/a/3071441, with the following added:
- `method` arg, with support for 'average' (default) and 'min'
- `reverse` flag, with `True` (default) signifying descending sort order
(i.e. the highest value in `a` has a rank of 1, as opposed to `len(a)`)
@crashka
crashka / config.py
Created December 27, 2021 17:23
Manage application configurations through YAML files, with default profiles and overrides, and incremental file loading
from collections.abc import Iterable
from typing import Union, Optional
import os.path
import yaml
DEFAULT_PROFILE = 'default'
class Config:
"""Manages YAML config information, features include:
@crashka
crashka / parse_argv.py
Last active March 8, 2022 01:29
Parse args/kwargs-style command line arguments, returning separate args and kwargs with typecast values
from typing import Union
from numbers import Number
def parse_argv(argv: list[str]) -> tuple[list, dict]:
"""Takes a list of arguments (typically a slice of sys.argv), which may be a
combination of bare agruments or kwargs-style constructions (e.g. "key=value")
and returns a tuple of `args` and `kwargs`. For both `args` and `kwargs`, we
attempt to cast the value to the proper type (e.g. int, float, bool, or None).
"""
def typecast(val: str) -> Union[str, Number, bool, None]:
@crashka
crashka / write_like_crash_says_and_not_like_he_does.md
Last active March 8, 2022 01:29
Follow this and you can dump Crash as a copy editor

In formal writing, be aware of conjunctions or descriptors that sound too colloquial. For example, consider the following alternatives:

  • as -> since, when, because
  • like -> such as, for instance
  • a lot -> many, much

Try not to repeat words and/or phrases within a short span, other than by design (e.g. for reinforcement or parallel construction). "Short span" here means a sentence or two.

Installing WSL2 on Windows 10

Enabling core Windows features

  1. Go to Control Panel > Programs

    Click on "Turn Windows Features On Or Off"

    Enable "Virtual Machine Platform" and "Windows Subsystem for Lunix"