Skip to content

Instantly share code, notes, and snippets.

View sgress454's full-sized avatar

Scott Gress sgress454

View GitHub Profile
@sgress454
sgress454 / pre-commit
Created June 20, 2017 20:20
Pre-commit hook to block commits that change models without adding a migration script
#!/Users/scottmac/.nvm/v6.3.0/bin/node
/**
* Pre-commit hook to prevent commits that change models unless they
* also include a migration file.
*
* To skip, use the `--no-verify` option when committing.
* (useful if you just added a comment to a model)
*/
@sgress454
sgress454 / custom-blueprint.md
Last active March 5, 2022 06:05
Adding a custom blueprint action to all models

Reference: https://gitter.im/balderdashy/sails?at=58be4b1af1a33b62758d57ea

Is there anyway that I can add a method to all routes?

The issue

Given a Sails app with two models User and Pet, how do we create a single controller action foo and have it automatically run on requests for both /user/foo and /pet/foo?

The solution

@sgress454
sgress454 / saving-binary-data-using-waterline.md
Last active February 23, 2017 22:05
Saving binary data in a model using Waterline

Given the appropriate columnType, MySQL and PostgreSQL will handle storing buffers for you.

Model

module.exports = {
  attributes: {
    name: {
      type: 'string',
 },
@sgress454
sgress454 / sails-1.0-removed-deps.md
Created December 2, 2016 00:28
Dependencies removed in Sails 1.0

Dependencies removed in Sails v1.0

Dependency Version
anchor ~0.10.5
connect-flash 0.1.1
ejs-locals 1.0.2
express-handlebars 3.0.0
grunt 1.0.1
grunt-cli 1.2.0
@sgress454
sgress454 / algorithm-for-orderiner g-routes.md
Last active October 20, 2016 16:39
Algorithm for ordering routes

An algorithm for ordering routes

Definition of a "route"

For the purposes of this algorithm, a route is a string containing:

  • An optional HTTP verb (or ALL) prefix, followed by a space, followed by:
  • 1 or more path components, where each path component is:
    • A forward slash /, followed by:
  • A colon : followed by any combination of letters and numbers (a "param"), OR
@sgress454
sgress454 / waterline_issue_repo_instructions.md
Created March 2, 2016 18:27
How to make a repo for reproducing a Waterline issue

The instructions below will work with the regular Git command-line tool or the hub CLI tool (makes things a bit faster).

# Make a new Sails app with a descriptive title
sails new waterline-issue-cant-create-records
cd waterline-issue-cant-create-records

# Install the minimum node modules needed to reproduce the issue, making careful note of versions
# and remembering to use --save
npm install sails-mysql --save
@sgress454
sgress454 / sails_issue_repo_instructions.md
Last active February 24, 2016 11:58
How to make a repo for reproducing a Sails issue

The instructions below will work with the regular Git command-line tool or the hub CLI tool (makes things a bit faster).

# Make a new Sails app with a descriptive title
sails new sails-issue-cant-use-handlebars-layout
cd sails-issue-cant-use-handlebars-layout

# Install the minimum node modules needed to reproduce the issue, making careful note of versions
# and remembering to use --save and --save-exact
npm install handlebars@4.0.5 --save --save-exact
├── bcrypt@0.8.5 extraneous
├── bcryptjs@2.3.0
├─┬ connect-redis@1.4.5
│ ├─┬ debug@2.2.0
│ │ └── ms@0.7.1
│ └── redis@0.7.3
├── ejs@0.8.8 -> /home/ubuntu/.nvm/versions/node/v4.2.1/lib/node_modules/sails/node_modules/ejs
├── forever@0.15.1 extraneous
├─┬ grunt@0.4.2 -> /home/ubuntu/.nvm/versions/node/v4.2.1/lib/node_modules/sails/node_modules/grunt
npm ls --depth=1
rest-api@0.2.0 /www/5m/rest-api
├── bluebird@3.1.5
├─┬ chai@3.5.0
│ ├── assertion-error@1.0.1
│ ├── deep-eql@0.1.3
│ └── type-detect@1.0.0
├─┬ debug@2.2.0
│ └── ms@0.7.1
@sgress454
sgress454 / sails_rc5_dependencies.txt
Created December 28, 2015 17:13
Notes on upgrades from v0.11.3 dependencies to now
Following is the list of top-level non-development dependencies with their versions in v0.11.x and notes detailing the version they are upgraded to in v0.12.x (if any) and why. New dependencies (like `consolidate`) have notes explaining the choice of current version.
├── anchor@~0.10.5 (ours)
├── async@0.9.2 -> 0.10.5 (has changelog, lots of bug fixes and good stuff)
├── captains-log@~0.11.11 (ours)
├── colors@0.6.2 -> 1.1.2 (no changelog, but seems to be just bugfixes and it's only used for logs)
├── commander@2.1.0 -> 2.9.0 (has changelog, bugfixes et al)
├── connect@2.25.0 -> 2.29.1 (required by our express version)
├── connect-flash@0.1.1 (latest)
├── consolidate@0.12.1 (latest is just react/promises stuff)