Skip to content

Instantly share code, notes, and snippets.

@maxandron
maxandron / doc-tracks.js
Created April 30, 2023 23:57
Script to fetch all of the dog friendly tracks in New Zealand from the DOC website
const ProgressBar = require("progress");
const fs = require("fs");
const DOG_ACCESS_FILTER = {
epiFindPropertyName: "DogAccess",
selectedValue: "true",
fieldId: 1153495591,
};
const NZ_REGIONS = [
@maxandron
maxandron / slidev-prettier.js
Created April 23, 2023 04:43
A small wrapper around prettier to format (without breaking) the custom Slidev markdown
const fs = require('fs');
const prettier = require('prettier');
const START_TAG = '\n<!-- prettier-ignore-start -->\n';
const END_TAG = '\n<!-- prettier-ignore-end -->\n';
function addPrettierIgnoreTags(content) {
const pattern = /---(?:\n.+)*\n---/g;
return content.replace(pattern, (match) => {
@maxandron
maxandron / markdowntoc.lua
Created December 9, 2022 07:29
A snippet that defines a `MarkdownTOC` command that creates a table of contents in the current markdown file at the cursor. nothing fancy
vim.api.nvim_create_user_command("MarkdownTOC", function()
if vim.bo.filetype ~= "markdown" then
print("This is not a markdown file")
return
end
-- Extract the hashtags using grep
local hashtags = vim.fn.systemlist("grep -oE '^#+.*' " .. vim.fn.expand("%"))
local toc = ""
@maxandron
maxandron / localstorage.ts
Last active November 29, 2022 02:11
useLocalStorage - an example of a hook the retrieves and stores data in local storage asynchronously
import { useEffect, useState } from "react"
export function useLocalStorage(key: string) {
const [value, setValue] = useState<string | null>(null)
const [isLoading, setIsLoading] = useState(true)
useEffect(function getInitialValue() {
setValue(localStorage.getItem(key))
setIsLoading(false)
}, [])
@maxandron
maxandron / stopword_speed.py
Last active February 13, 2022 16:57
Stop words removal speed test
import re
from collections import Counter
from nltk.corpus import stopwords
# test1 - Common example
stops = stopwords.words("english")
# test2 - Using regex
pattern = re.compile(r"\b(" + r"|".join(stops) + r")\b\s*")
# Tranfer Files
Connect-VIServer -Server 192.168.1.100 -User vsphereusername@domain -Password vspherepassword
Set-Variable -Name "vms" -Value (Get-VM -Name "Group * - Web-IIS")
Copy-VMGuestFile -Source "C:\gene.json" -Destination C:\ -VM $vms -LocalToGuest -GuestUser username -GuestPassword password -Force
@maxandron
maxandron / kindle_clippings_to_md.py
Created April 22, 2020 03:03
Parses kindle "My Clippings.txt" (the book highlights) file to markdown format
#!/usr/local/bin/python3
import argparse
def clippings_to_dict(clip_file):
quotes = open(clip_file, 'r').read().split('==========')
split_quotes = []
for quote in quotes:
# Remove empty lines
# Just put this in your ~/.bashrc, later use it by typing:
# title my title
function title() {
stitle=$@
PROMPT_COMMAND='echo -ne "\033]0;$stitle\007"'
}
@maxandron
maxandron / pre-commit
Last active March 21, 2016 20:56
A git pre-commit hook to disallow committing code with "TODO"
#!/bin/sh
. git-sh-setup # For die
git diff --cached --name-status |
awk '$1 != "R" { print $2 }' |
xargs grep TODO --with-filename --line-number &&
die Blocking commit - TODO detected in patch
exit 0 # Needed because this file must end with success code for git to continue