Skip to content

Instantly share code, notes, and snippets.

View robksawyer's full-sized avatar
🎯
Focusing

Rob Sawyer robksawyer

🎯
Focusing
View GitHub Profile
@wxactly
wxactly / stubQueryMethod.js
Last active August 29, 2015 14:06
Sails.js: Stub Waterline query method with Sinon.js
var util = require('util');
var _ = require('lodash');
var sinon = require('sinon');
/**
* Replaces a query method on the given model object with a stub. The query
* will still operate on a callback, and allow full access to waterline's
* deferred object. However, the query will not cause any I/O and instead
* will immediately resolve to the given result.
*
@nanha
nanha / gist:992575
Created May 26, 2011 04:53
JSONp using closure
var jsonp = {
callbackCounter: 0,
fetch: function(url, callback) {
var fn = 'JSONPCallback_' + this.callbackCounter++;
window[fn] = this.evalJSONP(callback);
url = url.replace('=JSONPCallback', '=' + fn);
var scriptTag = document.createElement('SCRIPT');
scriptTag.src = url;
@josephg
josephg / saver.coffee
Created November 5, 2011 13:56
Script to automatically re-save a sharejs document as its edited.
# This script watches for changes in a document and constantly resaves a file
# with the document's contents.
#
# Usage: coffee saver.coffee -d <DOCNAME> [--url http://somehost:8000/sjs] [-f filename]
client = require('share').client
fs = require('fs')
argv = require('optimist')
.usage('Usage: $0 -d docname [--url URL] [-f filename]')
@akkunchoi
akkunchoi / VisualizeShell.php
Last active December 12, 2015 07:29
CakePHP2.x visualize console task
<?php
/**
* This script is a edited version for CakePHP2.x to work
* original: http://bakery.cakephp.org/articles/AD7six/2008/01/24/visualize-schema-task
*/
/**
*
* Visualize console task
*
@zeffii
zeffii / send_from_python_to_renoise.py
Last active December 27, 2015 03:59
chuck to renoise
..
@johnnncodes
johnnncodes / gist:8436644
Created January 15, 2014 13:54
Using custom validation messages in Sails.js. Credits to: sfb_
/**
* Takes a Sails Model object (e.g. User) and a ValidationError object and translates it into a friendly
* object for sending via JSON to client-side frameworks.
*
* To use add a new object on your model describing what validation errors should be translated:
*
* module.exports = {
* attributes: {
* name: {
* type: 'string',
import express from 'express';
import React from 'react';
import ReactDOMServer from 'react-dom/server';
import App from './components/App';
import {flushServerSideRequires} from 'react-loadable';
let app = express();
let webpackStats = require('./output-webpack-stats.json');
@subtleGradient
subtleGradient / git-transmit
Created April 26, 2010 19:11
git-transmit opens your recently modified files using Panic's Transmit.app DockSend
#!/usr/bin/env bash
# author: Thomas Aylott SubtleGradient.com
echo "Transmitting"
for i in `git log -${1:-1} $2 --name-only|grep -E '^[^ ]+$'|sort|uniq`; do
if [[ -e $i ]]; then
echo " $i"
open -a Transmit $i
fi
done
@JedWatson
JedWatson / createItems.md
Last active September 17, 2019 02:41
Examples of how to use Keystone's createItems functionality

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).

@kof
kof / action-creator-vs-reducer.md
Last active January 18, 2020 09:06
Action creator vs. reducer

When should you use action creator and when reducer?

Action creator

  • you need to have side effects
  • you need to read from store to decide what to do
  • you need to dispatch more than one action
  • action produced by action creator needs to contain all the data reducer can need to shape the components state

Reducer

  • should not have any side effects