Skip to content

Instantly share code, notes, and snippets.

View jescalan's full-sized avatar

Jeff Escalante jescalan

View GitHub Profile
new SpikeDatoCMS({
addDataTo: locals,
token: 'xxx',
templates: [
{
collection: (dato) => dato.blogPosts,
path: 'templates/post.html',
output: (post) => { return `posts/${post.slug}.html` }
}
]
@jescalan
jescalan / post.sgr
Created December 1, 2016 15:54
Almost pure markdown, but infinitely more flexible
extend(src='layout.sgr')
block(name='content')
.post(md).
# A markdown post
Here you can write **pure markdown** without issue.
You can treat this entire block like it's a normal markdown file and it will be compiled as such. Pretty cool! Everything works -- headlines, links, etc.
.footnote What's nice is that if you need to inject some extra html, javascript, add another block to change the title, etc. this is very simple to do since you have the capability to write full html with a reshape file as opposed to markdown.
---
title: 'wow'
---
hello, this is **markdown**!
@jescalan
jescalan / fooLoader.js
Created February 9, 2017 20:16
The issue with passing functions to loaders in webpack2
module.exports = function (source) {
console.log(this.query) // { foo: [null] } -- this is because when it's json serialized, it nulls out functions
const realOptions = this.options.module.rules.reduce((m, r) => {
const fooLoaderUse = r.use.find((u) => u.loader === 'foo-loader')
return fooLoaderUse ? fooLoaderUse.options : m
}, null)
console.log(realOptions) // foo: [() => 'bar'] -- it works, but is v. ugly
}
@jescalan
jescalan / fn.js
Last active December 22, 2016 14:33
lazy-loading require in node
/**
* Requires a library, but only loads it when it's actually used.
*
* lazy_require('fs');
* fs.readFileSync('example.js');
*
* var wow = lazy_require('fs');
* wow.readFileSync('example.js');
*
* @param {String} lib - name of the lib you want to load
@jescalan
jescalan / index.js
Last active December 11, 2016 21:02 — forked from tkraak/index.js
Gist from mistakes.io
/**
* @param {number} n - integer (n >= 0)
* @param {number} d - digit (0 <= d <= 9)
* square all numbers k between 0 and n (0 <= k <= n)
* count the number of digits d used in the k*k's
* example
*
* n = 10
* d = 1
@jescalan
jescalan / .profile
Created December 23, 2011 18:36
.dotfiles
# Config Notes
# Dependencies: rbenv, ruby 1.9.3-p0, pow, powder, git, git_completion, grc
#
# path:
PS1='\[\e[0;31m\]⚡\[\e[m\] \[\e[0;30m\]${PWD##*/}\[\e[39m\] \[\e[0;33m\]$(__git_ps1 "(%s) ")\[\e[m\]'
# pretty colors (brew install grc)
source "`brew --prefix grc`/etc/grc.bashrc"
@jescalan
jescalan / index.md
Last active August 29, 2016 15:37
Some helpful tools for working with open source node projects

Helpful Node Tools

  • greenkeeper
    when one of your projects' dependencies releases a new version, creates a pull request to update it
    install: npm i greenkeeper -g, run: gk enable
  • npm-check
    command line tool which checks your projects dependencies, tells you when there are any out of date, upgrades them
    install: npm i npm-check -g, run: npm-check -u
  • fixpack
    checks your package.json file to make sure it has important fields, organizes fields consistently
@jescalan
jescalan / index.md
Last active August 16, 2016 20:27
Differences between jade and the spike-standards stack

Spike v0.11.0 Migration Guide

In this release of spike, we switch posthtml for reshape. Reshape is a complete rewrite of posthtml by the static-dev team with several significant differences:

  • It returns a function by default, so that its results can be used as client-side templates
  • It has a much more clear and robust error reporting system, reporting errors that include the line/col in the original source, and exposing a code snippet to show where it came from
  • It has more clearly written documentation, more thorough tests, consistent code style, and 100% coverage on all core modules

However, as a consequence of this move, the jade plugin is no longer available. The jade plugin was always a hack, and had several crippling caveats. In addition, jade does not fit well with reshape's philosophy of breaking functionality down into small modules. As such, we have replaced ja

@jescalan
jescalan / serializeVerbatim.js
Created August 11, 2016 22:08
serialize an object, with functions, ready to be required
function serializeVerbatim (obj) {
let i = 0
const fns = []
let res = JSON.stringify(obj, (k, v) => {
if (typeof v === 'function') {
fns.push(v.toString())
return `__REPLACE${i++}`
} else {
return v
}