Skip to content

Instantly share code, notes, and snippets.

Jed Watson JedWatson

Block or report user

Report or block JedWatson

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@JedWatson
JedWatson / localfile.js
Created Apr 11, 2016
LocalFile Contents Scratch
View localfile.js
{ fieldname: 'file',
originalname: 'Advanced example.md',
name: '1458848e82f2de780e5ad963d93606aa.md',
encoding: '7bit',
mimetype: 'text/markdown',
path: '/var/folders/ck/y02pffhs31xd_k4xc9xmn3hw0000gn/T/1458848e82f2de780e5ad963d93606aa.md',
extension: 'md',
size: 7703,
truncated: false,
buffer: null } }
@JedWatson
JedWatson / files.js
Created Apr 8, 2016
File Field Scratchpad
View files.js
keystone.init({
...options
});
var S3Storage = require('keystone-storage-s3');
keystone.addStorage('s3bucket1', S3Storage, {
key: 'my key',
bucket: 'keystone-stuff',
secret: 'abracadabra',
@JedWatson
JedWatson / styles.jsx
Created Apr 5, 2016
A simple thought experiment demonstrating concepts I'm thinking about for styling react components in javascript
View styles.jsx
import React, { Component, PropTypes } from 'react';
import { Link } from 'react-router';
import useSheet from 'react-jss';
import CloudinaryImage from './CloudinaryImage';
const Author = ({image, name}, {theme}) => {
const classes = useSheet(stylesheet, theme);
const { authorKey, bio, id, image, name, summary, urlPath } = this.props;
@JedWatson
JedWatson / Flick.js
Created Jul 12, 2015
Declarative Interaction Component
View Flick.js
<Flick settings={...}>
{velocityDelta =>
<Spring
currentVelocity={currentVelocity => velocityDelta === 0 ? currentVelocity :
increase(currentVelocity, velocityDelta)
}
endValue={...}>
{currentValues => <div />}
</Spring>
}
@JedWatson
JedWatson / renderComponentToStringAndCSS.js
Last active Aug 29, 2015
React.renderComponentToStringAndCSS
View renderComponentToStringAndCSS.js
var MyComponent = React.createComponent({
render () {
return <div style={{ color: 'blue' }}>Hello World</div>;
});
var page = React.renderComponentToStringAndCSS(MyComponent);
// value of page:
page = {
html: '<div className="__a" data-reactid=".abc" data-react-checksum="123" data-react-classname="__a">Hello World</div>',
@JedWatson
JedWatson / UserStore.js
Created Mar 26, 2015
Simple store-prototype example for a User Store + View
View UserStore.js
var Store = require('store-prototype');
var UserStore = new Store();
var users = {};
var loaded = false;
UserStore.extend({
loadUsers: function() {
loadUsersSomehow(function(err, results) {
users = results;
@JedWatson
JedWatson / API-Auth-With-KeystoneJS.md
Last active Jul 28, 2019
API Auth with KeystoneJS
View API-Auth-With-KeystoneJS.md

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
View keybase.md

Keybase proof

I hereby claim:

  • I am JedWatson on github.
  • I am jedwatson (https://keybase.io/jedwatson) on keybase.
  • I have a public key whose fingerprint is 75DB 2419 8E41 BF37 4E39 88F9 5D4F 4D18 EF37 8B10

To claim this, I am signing this object:

@JedWatson
JedWatson / Countries.js
Last active Jul 24, 2019
Example of how to use the filters option for Relationship fields
View Countries.js
// A global file to provide the countries and cities
exports.countries = [{
name: 'Australia',
cities: ['Melbourne', 'Sydney', 'Canberra']
}, {
name: 'España',
cities: ['Madrid', 'Barcelona', 'Sevilla']
}, {
name: 'Italia',
@JedWatson
JedWatson / createItems.md
Last active May 31, 2018
Examples of how to use Keystone's createItems functionality
View createItems.md

Populating Data in KeystoneJS

Keystone's createItems function is a simple but powerful way to populate your database with data.

It can be used to create test fixtures or initialise your database with default content / users / etc.

There's also a shorthand syntax that can be used within update files; if you are using the auto updates feature, any file that exports a create object will automatically be wrapped and the data will be created.

createItems takes two passes at the data it is passed, first creating the items and retaining references by key (if provided) that can be used to populate relationships in the second pass. This makes it easy to create related data without asynchronous nesting (which for data creation sometimes ends up in knots).

You can’t perform that action at this time.