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
var koa = require('koa'); | |
var session = require('koa-session'); | |
var app = module.exports = koa(); | |
app.keys = ['some secret hurr']; | |
app.use(session({ domain: '.app.localhost' }, app)); // THIS WORKS IN BROWSER BUT FAILS IN SUPERTEST | |
//app.use(session(app)); // THIS WORKS EITHER WAY | |
app.use(function*() { |
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
var koa = require('koa'); | |
var session = require('koa-session'); | |
var flash = require('koa-flash'); | |
var router = require('koa-router'); | |
var handlebars = require("koa-handlebars"); | |
var app = koa(); | |
app.keys = ['foo']; | |
app.use(session({ domain: '.localhost' }, app)); // THIS FAILS |
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
/** | |
* Returns camel-cased equivalent of (lower-case) hyphenated string. | |
* | |
* To enable round-tripping, hyphens not followed by a-z are left intact | |
* (can be checked for and/or removed manually if required). | |
* | |
* Only transforms ASCII capitals (lack of JavaScript Unicode regexp). | |
*/ | |
function hyphenToCamel(str) { | |
// for Unicode transforms, replace [a-z] with \p{Ll} if available |
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
/** | |
* Returns specified argument from query string. | |
* | |
* @params {string} key - Argument to be returned. | |
* @returns {string} Value of key ('' for ?arg=, null for ?arg, undefined if not present). | |
*/ | |
function getQueryArg(key) { | |
var srch = location.search.substring(1); // lose the initial '?' | |
var args = srch.split(/[&;]/); // list of field=value pairs | |
for (var i=0; i<args.length; i++) { // for each arg |
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
/** | |
* Returns specified argument from query string. | |
* | |
* @params {string} key - Argument to be returned. | |
* @returns {string} Value of key ('' for ?arg=, null for ?arg, undefined if not present). | |
*/ | |
function getQueryArg(key) { | |
// look for key prefixed by ?/&/;, (optionally) suffixed | |
// by =val (using lazy match), followed by &/;/# or EOS | |
var re = new RegExp('[?&;]'+key+'(=(.*?))?([&;#]|$)'); |
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
<?php | |
/** | |
* Returns how long ago something happened in the past, showing it as | |
* 'n' seconds / minutes / hours / days / weeks / months / years ago. | |
* | |
* For periods over a day, it rolls over at midnight (so doesn't depend on | |
* current time of day), and it correctly accounts for month-lengths and | |
* leap-years (months and years rollover on current day of month). | |
* |
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
<?php | |
/** | |
* Truncates text to given length with suffixed ellipsis. | |
* | |
* @param string $text Original text string. | |
* @param int $length Length to truncate to. | |
* @param bool [$wholeWords=true] Whether to truncate back to whole words. | |
* @return string Truncated string. | |
*/ |
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
<?php | |
/** | |
* Encrypts object to be stored secure from prying eyes (uses AES-256 ECB). | |
* | |
* @param object $sourceObj Object to be encrypted. | |
* @param string $key Key to use for encryption. | |
* @return string Encrypted object. | |
*/ | |
function objEncrypt($sourceObj, $key) |
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
<?php | |
/** | |
* Cleans up posted data - trims texts & converts empty fields to null. | |
* | |
* @param mixed[] $post POST data to be cleaned. | |
* @return mixed[] Cleaned-up POST data. | |
*/ | |
function clean($post) | |
{ |