Skip to content

Instantly share code, notes, and snippets.

@arnoson
arnoson / cleanupEmptyFolders.js
Created November 15, 2022 11:47
nodejs: remove empty directories recursively
View cleanupEmptyFolders.js
import { readdirSync, rmdirSync, statSync } from 'node:fs'
import { join } from 'node:path'
export const cleanupEmptyFolders = (folder) => {
if (!statSync(folder).isDirectory()) return
let files = readdirSync(folder)
if (files.length > 0) {
files.forEach((file) => cleanupEmptyFolders(join(folder, file)))
// Re-evaluate files; after deleting subfolders we may have an empty parent
@arnoson
arnoson / dash-array-holes.js
Created November 4, 2021 14:32
Create a dash array with holes in it
View dash-array-holes.js
const path = new Path.Circle({
radius: 200,
strokeColor: 'blue',
center: view.center,
strokeCap: 'round',
strokeWidth: 3
})
const gap = 50
const offsets = []
@arnoson
arnoson / stretch.js
Last active November 8, 2021 12:49
Stretch a round paper.js path item
View stretch.js
const getBottomSegment = (segments) =>
segments.reduce((prev, curr) => (curr.point.y > prev.point.y ? curr : prev))
const getTopSegment = (segments) =>
segments.reduce((prev, curr) => (curr.point.y < prev.point.y ? curr : prev))
const wrapSegmentIndex = (path, index) =>
(index =
index < 0 ? path.segments.length + index : index % path.segments.length)
@arnoson
arnoson / class.lua
Created April 8, 2021 23:22
Lua class helper
View class.lua
-- Inspired by: lua-users.org/wiki/SimpleLuaClasses
function class(base)
local c = {}
-- Inherit base by making a shallow copy.
if type(base) == 'table' then
for key,value in pairs(base) do c[key] = value end
c._base = base
end