Skip to content

Instantly share code, notes, and snippets.

View askdesigners's full-sized avatar
🚮

Ryan Cole askdesigners

🚮
  • Tell Me Something Nice
  • Prague
View GitHub Profile
@JedWatson
JedWatson / API-Auth-With-KeystoneJS.md
Last active April 16, 2023 02:11
API Auth with KeystoneJS

To implement API authentication in KeystoneJS, you need the following:

For key based authentication

  • Middleware that validates the key in the request body or a header

For session based authentication

  • An endpoint that handles signin
  • An endpoint that handles signout
@JedWatson
JedWatson / KeystoneApiExample.md
Last active July 26, 2021 11:29
Example of how to scaffold API endpoints for Posts in a Keystone project (based on the yo keystone example).

This is an example of how to scaffold API endpoints to list / get / create / update / delete Posts in a Keystone website.

It's a modification of the default project created with the yo keystone generator (see https://github.com/JedWatson/generator-keystone)

Gists don't let you specify full paths, so in the project structure the files would be:

routes-index.js        -->    /routes/index.js         // modified to add the api endpoints
routes-api-posts.js    -->    /routes/api/posts.js     // new file containing the Post API route controllers
@bycoffe
bycoffe / smooth.js
Created September 9, 2011 20:09
Gaussian smoothing function in JavaScript
// Adapted from http://www.swharden.com/blog/2008-11-17-linear-data-smoothing-in-python/
var smooth = function (list, degree) {
var win = degree*2-1;
weight = _.range(0, win).map(function (x) { return 1.0; });
weightGauss = [];
for (i in _.range(0, win)) {
i = i-degree+1;
frac = i/win;
gauss = 1 / Math.exp((4*(frac))*(4*(frac)));
weightGauss.push(gauss);