Originally in this blog post, but it's a bit hidden at the bottom, so here's the wrap up:
Available for:
- Debian 7 / stable (wheezy)
- Debian testing (jessie)
- Debian unstable (sid)
- Ubuntu 12.04 LTS (Precise Pangolin)
var Aws = require('aws-sdk'); | |
var sinon = require('sinon'); | |
// Only works for 'createBucket', 'update' and a few others since most API methods are generated dynamically | |
// upon instantiation. Very counterintuitive, thanks Amazon! | |
var createBucket = sinon.stub(Aws.S3.prototype, 'createBucket'); | |
createBucket.yields(null, 'Me create bucket'); | |
// For other methods, we can 'assign' the stubs to the proto, already defined function won't be overridden | |
var listBuckets = Aws.S3.prototype.listBuckets = sinon.stub(); |
require('./.env'); // AWS config is set here via process.env. | |
var Aws = require('aws-sdk'); | |
var uniqid = require('uniqid'); | |
var fs = require('fs'); | |
var s3 = new Aws.S3(); | |
const BUCKET_NAME = 'test-joerx'; | |
const BUCKET_REGION = 'eu-west-1'; |
//based on http://stackoverflow.com/questions/9210542/node-js-require-cache-possible-to-invalidate | |
function clearRequireCache() { | |
Object.keys(require.cache).forEach(function(key) { | |
delete require.cache[key]; | |
}); | |
} | |
var myModule1 = require('./my-module'); | |
console.log(myModule1.counter); // 0 |
<!DOCTYPE html> | |
<html class="no-js" ng-app="myApp"> | |
<head> | |
<meta charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> | |
<title>sp-directives</title> | |
<meta name="description" content=""> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/3.0.2/normalize.min.css"/> |
# Array with expressions | |
dishes=(":hamburger:" ":pizza:" ":poultry_leg:" ":rice:" ":curry:" ":ramen:" ":spaghetti:" ":sushi:") | |
# Seed random generator | |
RANDOM=$$$(date +%s) | |
# Get random expression... | |
selecteddish=${dishes[$RANDOM % ${#dishes[@]} ]} | |
echo $selecteddish |
Originally in this blog post, but it's a bit hidden at the bottom, so here's the wrap up:
Available for:
var EventEmitter = require('events').EventEmitter; | |
var express = require('express'); | |
var httpMocks = require('node-mocks-http'); | |
var res = httpMocks.createResponse({ | |
eventEmitter: EventEmitter // works, but is somewhat counterintuitive | |
// eventEmitter: new EventEmitter() // this is what I would expect to work | |
}); | |
var req = httpMocks.createRequest({ | |
method: 'GET', |
// Occassionally one needs to manually force sails to use the built-in memory adapter as a session store | |
// - for instance when running tests and a mysql-adapter is configured for production, we may need to | |
// override session adapter settings for tests only. Turns out to be pretty simple: | |
Sails.lift({ | |
session: { | |
adapter: 'memory', | |
config: null | |
} | |
}); |