Skip to content

Instantly share code, notes, and snippets.

View johanfriis's full-sized avatar

Johan Friis johanfriis

View GitHub Profile
@johanfriis
johanfriis / rmdirRecurseSync.js
Created April 8, 2013 16:02
node recursive rmdir #snippet
var rmdirRecurseSync = function(dir) {
var list = fs.readdirSync(dir);
for(var i = 0; i < list.length; i++) {
var filename = path.join(dir, list[i]);
var stat = fs.statSync(filename);
if(stat.isDirectory()) {
// rmdir recursively
rmdirRecurseSync(filename);
} else {
@johanfriis
johanfriis / titleize.js
Created May 18, 2013 20:10
Convert a string to a human readable title string #snippet
/*
* Convert a string into a human readable title
*
* This function borrows heavily from sugar.js
* http://sugarjs.com/
*
* titleize("man from the boondocks") -> Man from the Boondocks
* titleize("x-men: the last stand") -> X Men: The Last Stand
* titleize("TheManWithoutAPast") -> The Man Without a Past
* titleize("raiders_of_the_lost_ark") -> Raiders of the Lost Ark
@johanfriis
johanfriis / stripTags.js
Created May 18, 2013 20:59
Stip html tags #snippet
stripTags = function (str) {
if (str === null && str === undefined) return '';
return String(str).replace(/<\/?[^>]+>/ig, '');
};
@johanfriis
johanfriis / php.sh
Created May 19, 2013 13:42
Command Line Servers #snippet
# requires php v5.4
php -Slocalhost:3000
@font-face {
font-family: "Fura Code";
font-weight: 200;
src: url("https://github.com/ryanoasis/nerd-fonts/blob/master/patched-fonts/FiraCode/Light/complete/Fura%20Code%20Light%20Nerd%20Font%20Complete.otf?raw=true") format('opentype');
}
@font-face {
font-family: "Fura Code";
font-weight: 400;
src: url("https://github.com/ryanoasis/nerd-fonts/blob/master/patched-fonts/FiraCode/Regular/complete/Fura%20Code%20Regular%20Nerd%20Font%20Complete.otf?raw=true") format('opentype');
}
@johanfriis
johanfriis / view.js
Last active December 26, 2023 21:19
A DataView View that implements almost the same rendering for lists that we have for tasks, and adds pagination. This version has tasks removed from output to drastically simplify the view.
if (!input?.query) {
dv.paragraph("You must pass a `query` to the view");
return;
}
const pagesWithLists = await dv.tryQuery(input.query);
const HEADER_SIZE = input?.headerSize ?? 2;
/**