This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Bluebird from 'bluebird'; | |
// assume express, promise-ready ORM (Sequelize, Bookshelf, Mongoose) | |
function wrap(genFn) { | |
var cr = Bluebird.coroutine(genFn); | |
return function (req, res, next) { | |
cr(req, res, next).catch(next); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
universe: everything that isn't this software | |
can only interface with software through the shell | |
- user | |
- monitor | |
- browser | |
- database | |
- file system | |
- external API | |
- API on the same machine but different piece of software | |
- sensors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function privateHandlePut(req, res) { | |
// do things | |
} | |
function publicHandleGet(req, res) { | |
// do things | |
} | |
export.controller = { | |
publicHandleGet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UPDATE page, (SELECT pageorder as oldorder FROM page WHERE id = :pgid) as t2 SET page.pageorder = CASE | |
WHEN id = :pgid THEN :neworder | |
WHEN page.pageorder <= :neworder AND page.pageorder > t2.oldorder THEN page.pageorder-1 | |
WHEN page.pageorder >= :neworder AND page.pageorder < t2.oldorder THEN page.pageorder+1 | |
ELSE page.pageorder | |
END | |
WHERE page.pageorder >= LEAST(:neworder, t2.oldorder) AND page.pageorder <= GREATEST(:neworder, t2.oldorder); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; removal | |
UPDATE page | |
, (SELECT category_id as oldcategory, page_order as oldorder FROM page WHERE id = :pgid) as t2 | |
SET page.page_order = CASE | |
WHEN id = :pgid THEN -1 | |
WHEN page.category_id = t2.oldcategory | |
AND page.page_order > t2.oldorder | |
THEN page.page_order-1 | |
ELSE page.page_order | |
END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// trivial division | |
h,i=2;g(j){return j*j>i||i%j++&&g(j);}main(){scanf("%i",&h);for(;h;i++)g(2)&&printf("%i ",i,--h);} | |
// Wilson's Theory | |
h,i;m(n){return n?n*m(n-1)%i:1;}main(){scanf("%i",&h);for(;h;)m(i++)+1-i||printf("%i ",i,--h);} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
how dynamic paths work | |
while this design sounds good, may wish to consider allowing something like | |
{param|/regex/} | |
would require the existance of "DynNode" to store the regex validator | |
but also, the parent Node would need to store an array of DynNodes | |
don't need to store the param names though, since it can be stored in the dynnodes themselves | |
when adding, must verify the names match up |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
var TrieRouter = require('./experimental-router'); | |
TrieRouter.add(['get'], '/', function(req, res) { | |
//console.log('index'); | |
}, {}); | |
TrieRouter.add(['get'], '/aboutus', function(req, res) { | |
console.log('aboutus'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Methods could be any of the CRUD actions | |
// they may return data like newest info, result data, or just a status | |
// they could set flash vars (universally) using Flash.post('error', 'something went wrong') | |
// POST->redirect flow without JS | |
// the result is probably ok to ignore when you think about the workflow. | |
// the redirect-to should load a page that loads data anyway. | |
// we expose Flash system on both sides anyway, so call that in here. | |
// would just need a way to know where to redirect following a non-XHR |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// types/todo.js | |
export default Type({ | |
owner: User, // user is assumed defined for this example | |
message: { | |
type: String, | |
validators: /\\w+/ // maybe a function, maybe an array, maybe an object with a custom error message | |
} | |
}); | |
// db/todo.js |
OlderNewer