Skip to content

Instantly share code, notes, and snippets.

@0scarB
0scarB / main.c
Last active September 5, 2024 18:58
Simple testing framework in C. Easily extensible; easily translated to other languages.
/*
* (c) 2024. This work is openly licensed via CC BY 4.0.
* Give credit by linking to the original Gist or https://github.com/0scarB/dev-ref/blob/main/ref-impls/c_test_framework/main.c.
*/
#define _POSIX_C_SOURCE 1
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
@0scarB
0scarB / stringConcatBench.js
Last active June 25, 2024 19:42
JavaScript large string concat benchmark (v8 + NodeJS)
#!/usr/bin/env node
const { Buffer } = require('node:buffer');
function main() {
console.log(`NodeJS version = ${process.versions.node}`);
console.log(`V8 version = ${process.versions.v8}`);
console.log("---------------------------------------------------")
measureStringConcat();
}
@0scarB
0scarB / find_image_urls_in_markdown.py
Last active September 12, 2023 13:58
Quick and dirty function to extract image URLs from markdown.
from collections.abc import Iterable
import urllib
def find_image_urls_in_markdown(s: str) -> Iterable[str]:
context = ""
alt_text_chars = []
url_chars = []
for char in s:
if context == "":
@0scarB
0scarB / dfs.py
Created August 25, 2022 15:18
DFS returning path
def dfs(graph, start, goal, path=None, visited=None):
path = path or []
visited = visited or set()
path.append(start)
visited.add(start)
if start == goal:
return path
@0scarB
0scarB / bfs.py
Last active August 24, 2022 17:35
BFS returning path
from collections import deque
def bfs(graph, start, goal):
# initialize state
queue = deque()
explored_vertex_to_path = {}
# utility functions
def mark_as_explored(vertex, parent=None):
@0scarB
0scarB / watch_files.py
Created June 25, 2022 19:41
Simple file watcher
#!/usr/bin/env python3
from functools import lru_cache
import sys
import os.path
import time
WATCH_INTERVAL = 1
SCHEDULER_POLL_INTERVAL = 0.1
PURGE_OLD_UIDS_INTERVAL = 100 * WATCH_INTERVAL
@0scarB
0scarB / paper_js_trees1.js
Created December 28, 2018 13:30
paper.js sketch that generates trees with branches of varying length.
var width = view.size.width;
var height = view.size.height;
var averageLengthFac = 0.7;
var angleInc = Math.PI/4;
var iterations = 12;
function drawLine(x1, y1, x2, y2, color) {
var line = new Path(new Point(x1, y1));
line.strokeColor = color;
@0scarB
0scarB / fractal_decorator.py
Last active June 4, 2018 22:54
decorator for generating fractals
from functools import wraps
def _run(iter_n, func, initial_args, initial_kwargs):
current_iter_params = [(initial_args, initial_kwargs)]
for _ in range(iter_n):
next_iter_params = []
for args, kwargs in current_iter_params:
next_iter_params.extend(
next_iter_func_params for next_iter_func_params in func(*args, **kwargs))
@0scarB
0scarB / AttrDict
Last active May 29, 2018 11:37
Python data structure for working with a dict via attributes or keys
We couldn’t find that file to show.