Skip to content

Instantly share code, notes, and snippets.

@nicolevanderhoeven
nicolevanderhoeven / getCampaignList.js
Created August 9, 2024 14:02
Writes Dataview query results to a Markdown note in Obsidian
function getNumOfGames(campaign) {
let numOfGames = app.plugins.plugins.dataview.api
.pages(`"ttrpgs/${campaign}"`)
.where(page => {
if (page.type === 'session') {
if (page.campaign === campaign) {
return true;
}
}
}).length
@nicolevanderhoeven
nicolevanderhoeven / updateDate.js
Created May 8, 2023 15:42
Gist for automatically adding a link to today's daily note to an Dataview inline field in an Obsidian note. For use with the QuickAdd Obsidian plugin.
module.exports = async function updateDate(params) {
/*
This function does the following things:
1. Gets the current date.
2. Reads the contents of the current file.
3. When a line that contains `date::` is found, adds the current date as a note to the end of the line.
*/
let currDate = moment().format('YYYY-MM-DD');
const currentFile = params.app.workspace.getActiveFile();
const fileContents = await params.app.vault.read(currentFile);
@nicolevanderhoeven
nicolevanderhoeven / random-npcs.js
Created March 22, 2023 23:15
Randomly return 10 NPCs from an Obsidian vault using the Dataview plugin.
```dataviewjs
function randomElements(arr, n) {
var result = new Array(n);
var len = arr.length;
if (n > len) throw new RangeError("randomElements: more elements taken than available");
for (var i = len - 1; i >= len - n; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = arr[i];
result[len - i - 1] = arr[j];
arr[i] = arr[j];
@nicolevanderhoeven
nicolevanderhoeven / daily.md
Last active November 9, 2022 14:18
Obsidian Daily Note template with a DataviewJS snippet for returning tasks due on a certain date

{{title}}

Tasks due today

dv.taskList(dv.pages().file.tasks 
  .where(t => !t.completed)
  .where(t => t.text.includes("{{date:YYYY-MM-DD}}")))
@nicolevanderhoeven
nicolevanderhoeven / returnStudyOptions.js
Created January 14, 2022 11:16
Script for use with the Obsidian Dataview and Templater plugins to return activity options given an amount of time available
/*
This script returns a list of activity options you could do (each defined by a Markdown file),
depending on how much time you have available.
REQUIRES:
- Obsidian: https://obsidian.md
- Obsidian Dataview plugin: https://blacksmithgu.github.io/obsidian-dataview/
- Obsidian Templater plugin: https://silentvoid13.github.io/Templater/
- this folder structure:
@nicolevanderhoeven
nicolevanderhoeven / downloadfirebase.py
Last active September 17, 2024 12:38
Download Roam images locally for use with Obsidian vault
# Opens files in directory, outputs firebase URLs to a file, downloads them, and replaces the links with a link to the new files.
# To use, replace PATH in the variable vaultDir with your vault's root directory.
# This automatically puts filenames in /assets - change the newFilePath variable if you want to change this
import re
import glob
import os
import requests
import calendar
import time
@nicolevanderhoeven
nicolevanderhoeven / home-login.js
Last active October 1, 2021 08:18
k6 sample load testing script with variable think time, multiple scenarios, thresholds, test data, and correlation of dynamic values.
import http from 'k6/http';
import { sleep, check } from 'k6';
import { parseHTML } from "k6/html";
import papaparse from 'https://jslib.k6.io/papaparse/5.1.1/index.js';
import { SharedArray } from "k6/data";
const domain = 'https://test.k6.io'; // Parameterize the domain to make it easier to change environments.
let token = 'NOT FOUND'; // Initialize the csrftoken variable.
/*

+++ title = "Load Tests as Code" outputs = ["Reveal"] [reveal_hugo] custom_theme = "reveal-hugo/themes/robot-lung.css" margin = 0.2 highlight_theme = "color-brewer" transition = "slide" transition_speed = "fast" +++

@nicolevanderhoeven
nicolevanderhoeven / deroamify.py
Created December 18, 2020 22:16
Reformats Roam Markdown output for publishing via Hugo or similar
# Takes exported Roam input and turns it into a better format for publishing.
# Output is still Markdown, but it's one that doesn't support backlinks.
# Good for traditional blogs.
# Run from a directory with a source .md file.
# Pipe output to a new file, i.e., output.md
import re
import glob
try:
filename = glob.glob('*.md')
@nicolevanderhoeven
nicolevanderhoeven / yinotetoroam.py
Created December 15, 2020 20:59
Reformat exported Markdown file from YiNote for importing into Roam Research
# Parses a .md generated by [YiNote](https://yinote.co/) and reformats it for export into [Roam Research](https://roamresearch.com).
# Prereq: Input .md file in the same folder
# Run this and pipe the output to a file you specify, i.e. `python3 yinotetoroam.py > output.md`
# Import `output.md` to Roam.
import re
import datetime
import glob
try:
filename = glob.glob('*.md')