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
############################################################################################################
### % [ 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

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?"

{
"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": [

Project organization

Here is how I prefer to organize projects:

┌─ _dist/
├─ assets/
├─ content/
├─ data/
@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.

@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 / tutorial-create-permalinks-using-stringsjs.md
Last active August 29, 2015 14:01
Creating permalinks with Strings.js
@jonschlinkert
jonschlinkert / .assemblerc.yml
Last active August 29, 2015 14:01
Create a theme with Assemble
# I'm only using a few fields here to demonstrate how this works
# Site theme
theme: slides
# Assets
# The assets path is based on the theme,
# the other paths can build on the assets path
assets: assets/<%= site.theme %>
images: <%= site.assets %>/images
@jonschlinkert
jonschlinkert / task-vs-target.md
Created May 23, 2014 12:49
What is a "task" and a "target" in Grunt configuration?

What's a target?

Demystifying tasks and targets

Here, we have the basics of any Gruntfile.

module.exports = function(grunt) {
  grunt.initConfig({
 // tasks will go here. A "task" is run by a grunt "plugin"
@jonschlinkert
jonschlinkert / this.md
Last active February 3, 2018 05:52
How `this` works in JavaScript

this

In JavaScript, this is a reference to the calling object of the function. For example:

var letters = {  // <= `this` (letters) is the calling object
  letter: 'A',
  getLetter: function () {
    // here, `this.letter` = `letters.letter`
    console.log(this.letter);