Skip to content

Instantly share code, notes, and snippets.

/*
* Time for a little data structure and algorithm exercise.
*
* Websites commonly make use of a "search suggestion" feature.
* As you type, options are suggested to you based on what others
* have searched for in the past. For example, if I type 'Le',
* I will be presented with other things for which people have searched--
* other terms that begin with 'Le', such as "Levi", "Lego", and "Level".
* One way to accomplish this is by using a tree structure, breaking each previous
* search term into characters and then storing them in a tree, like so:
@Nijhazer
Nijhazer / bawts-20.js
Last active January 14, 2016 17:16
Building Applications with TypeScript - Snippet 20
/*
* Import the libaries that we're using.
* This is a test of API code, so any libraries
* specified in package.json should be available
* for import here.
*/
import chai = require('chai');
import chaiAsPromised = require("chai-as-promised");
import sinon = require('sinon');
@Nijhazer
Nijhazer / bawts-19.js
Created December 2, 2015 03:38
Building Applications with TypeScript - Snippet 19
var KarmaServer = KarmaServer = require('karma').Server;
gulp.task('test:www', ['compile:www'], function (done) {
new KarmaServer({
configFile: __dirname + '/karma.conf.js',
singleRun: true
}, done).start();
});
@Nijhazer
Nijhazer / bawts-18.js
Created December 2, 2015 03:37
Building Applications with TypeScript - Snippet 18
var baseUrl = '/base';
var config = {
baseUrl: baseUrl,
baseUILib: baseUrl + '/src/www/js/lib',
baseAPILib: baseUrl + '/node_modules',
fileInclusionTest: /spec\..+\.js$/i
};
var allTestFiles = [];
@Nijhazer
Nijhazer / bawts-17.js
Created December 2, 2015 03:36
Building Applications with TypeScript - Snippet 17
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['mocha', 'requirejs', 'chai-sinon'],
// Here, we specify which files Karma should load into the test harness.
files: [
// First, load an additional test runner that the karma-requirejs plugin will need.
'src/test/karma-test-runner.js',
@Nijhazer
Nijhazer / bawts-16.js
Created December 2, 2015 03:35
Building Applications with TypeScript - Snippet 16
var mocha = require('gulp-mocha');
gulp.task('test:api', ['compile:api'], function() {
return gulp.src('api/unit/test/location/**/*.js', {
read: false
}).pipe(mocha({
reporter: 'spec'
}));
});
@Nijhazer
Nijhazer / bawts-15.sh
Created December 2, 2015 03:35
Building Applications with TypeScript - Snippet 15
tsc --module amd task.ts
@Nijhazer
Nijhazer / bawts-14.sh
Created December 2, 2015 03:34
Building Applications with TypeScript - Snippet 14
tsc --target es6 task.ts
@Nijhazer
Nijhazer / bawts-13.js
Created December 2, 2015 03:31
Building Applications with TypeScript - Snippet 13
var router = Express.Router();
var taskManager = new DataManager(
new MongoDataDriver(EnvDataConfig.getInstance()),
Task
);
var taskController = new ExpressController();
taskController.manager = taskManager;
@Nijhazer
Nijhazer / bawts-12.js
Created December 2, 2015 03:30
Building Applications with TypeScript - Snippet 12
export class MongoDataDriver implements IDataDriver {
getConnection() : Promise {
return new Promise((resolve, reject) => {
Mongo.MongoClient.connect(this.config.connectionURL, (err, connection) => {
if (err) {
reject(err);
}
resolve(connection);
});
});