Skip to content

Instantly share code, notes, and snippets.

View jonschlinkert's full-sized avatar
🤔
Trying to stay in the right branch of the wave function.

Jon Schlinkert jonschlinkert

🤔
Trying to stay in the right branch of the wave function.
View GitHub Profile
@jonschlinkert
jonschlinkert / tutorial-create-permalinks-using-stringsjs.md
Last active August 29, 2015 14:01
Creating permalinks with Strings.js
@jonschlinkert
jonschlinkert / create-frame-helper.js
Last active February 3, 2018 05:56
A helper that adds variables from the options hash to the `@` namespace (like `@root`).
Handlebars.registerHelper('foo', function (name, context, options) {
var fn = Handlebars.compile(Handlebars.partials[name]);
var frame = Handlebars.createFrame(context.data);
for (var prop in options.hash) {
frame[prop] = options.hash[prop];
}
var template = fn(context, {data: frame});
return new Handlebars.SafeString(template);
@jonschlinkert
jonschlinkert / sidebar.md
Last active February 3, 2018 05:55
Assemble: how to add a sidebar that conditionally renders on certain pages, allowing each page to use different links

Originally written for http://stackoverflow.com/questions/24705434/assemble-dynamic-or-conditional-partials

Unique IDs

This is just one strategy, but it's simple. If you put a unique identifier in the YAML front-matter of each page it will come in handy later. This is easily done when you add a title property or any other content. slug is a good one to use because it can be used in permalinks or in conditional handlebars expressions etc. A slug should have no spaces, be lowercase, and use dashes not underscores if it might end up in permalinks.

If slug doesn't work for you, use whatever makes sense, but basename probably isn't a good one for this purpose b/c it could be index, which might belong to more than one file, and properties like title might be a sentences.

Project organization

Here is how I prefer to organize projects:

┌─ _dist/
├─ assets/
├─ content/
├─ data/
{
"bold_folder_labels": false,
"close_windows_when_empty": false,
"color_scheme": "Packages/Monokai Extended/Monokai Extended.tmTheme",
"default_line_ending": "unix",
"detect_indentation": false,
"draw_indent_guides": true,
"draw_white_space": "selection",
"ensure_newline_at_eof_on_save": false,
"file_exclude_patterns": [

Unary operators

(and the oddities of number evaluation in JavaScript)

Type conversion, typecasting, and coercion are different ways of, implicitly or explicitly, changing an entity of one data type into another. [--wikipedia][wikipedia]


Unary operators, or "typeof +'foo' === huh?"

############################################################################################################
### % [ title ] ( src ) ###
video_matcher = /^%\[([^\]]*)\]\s*\(([^)]+)\)/
#-----------------------------------------------------------------------------------------------------------
parse_video = ( state, silent ) ->
return false if state.src[ state.pos ] isnt '%'
match = video_matcher.exec state.src[ state[ 'pos' ] .. ]
return false unless match?
unless silent

Regex comparison

In both micromatch and minimatch, globs are converted to regex, which is then used for matching supplied values.

The following example shows one of the implementation differences between micromatch and minimatch, as a way of demonstrating how micromatch manages to have better Bash support while also being 20-120x faster than minimatch.

Pattern

Given this glob pattern:

micromatch vs. minimatch (WIP)

Can micromatch be used as a drop-in replacement for minimatch?

For mainstream features, I tried to keep as much parity as possible between micromatch and minimatch. But there are some differences.

Key differences

  • the main minimatch function, minimatch(), works like micromatch.isMatch()
  • the main micromatch function, micromatch(), works like multimatch, with support for multiple patterns.

Easiest Table of Contents possible

In .verb.md where you want to inject the TOC:

<!-- toc -->

Done!