Skip to content

Instantly share code, notes, and snippets.

@gpoitch
gpoitch / google_analytics_mixin.js
Last active December 16, 2015 16:40
A Google Analytics mixin for an Ember application controller. Sends a page view whenever the currentPath (url) changes. Normalizes the page url for both history and hash location routers.
Ember.GoogleAnalytics = Ember.Mixin.create({
trackPageView: function() {
if(!Ember.isNone(ga)) {
Ember.run.next(function() {
var loc = window.location,
page = loc.hash ? loc.hash.substring(1) : loc.pathname + loc.search;
ga('send', 'pageview', page);
});
}
(function(Ember) {
/**
Transforms a string so that it may be used as part of a 'pretty' / SEO friendly URL.
```javascript
'My favorite items.'.parameterize(); // 'my-favorite-items'
'action_name'.parameterize(); // 'action-name'
'100 ways Ember.js is better than Angular.'.parameterize(); // '100-ways-emberjs-is-better-than-angular'
```
@gpoitch
gpoitch / 1-typecheck.js
Last active April 3, 2020 16:29
Typescript type checking test assertions
const ts = require('typescript')
const DefaultOptions = {
noEmit: true,
target: ts.ScriptTarget.ES2019,
module: ts.ModuleKind.CommonJS
}
function typecheck(filepath, options = DefaultOptions) {
const program = ts.createProgram([filepath], options)
@gpoitch
gpoitch / api-gateway-middleware.ts
Created November 17, 2020 04:24
Node API Gateway Middleware
/**
* Convert a nodejs http request into an AWS API Gateway 'event' object.
* Or apply middleware to automatically convert requests/responses.
* Useful for testing your API Gateway lambda handler locally.
*/
import { IncomingMessage, IncomingHttpHeaders, ServerResponse } from 'http'
import { URL, URLSearchParams } from 'url'
import { APIGatewayProxyHandler, APIGatewayProxyResult } from 'aws-lambda'
const noop = () => {}