Skip to content

Instantly share code, notes, and snippets.

View mahulst's full-sized avatar

Michel van der Hulst mahulst

  • Amsterdam
  • 03:03 (UTC +02:00)
View GitHub Profile
import { Directive, HostListener, Input } from '@angular/core';
import { AnalyticsService } from './analytics.service';
/**
* @description
* This directive adds a click listener on an element
* and send events to google analytics.
*
* Usage:
* Add myGA as an attribute to the clickable element.
* Provide a string with an category, label and action
import { TestBed, ComponentFixture } from '@angular/core/testing';
import { Component } from '@angular/core';
import { AnalyticsService } from '../services/analytics.service';
import {
AnalyticsEventDirective
} from './analytics-events.directive';
// create a component using the directive we want to test
// eventString is a variable we can change to test behaviour
import { Component, OnInit } from '@angular/core';
import { Http } from '@angular/http';
import { Observable } from 'rxjs';
export interface Todo {
name: string;
completed: boolean;
}
@Component({
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { TodoListComponent } from './todolist';
import { Http } from '@angular/http';
import { Observable } from 'rxjs';
import { By } from '@angular/platform-browser';
describe('TodoListComponent', () => {
// Reference to components we can use in our tests
let stub: any = {},
componentFixture: ComponentFixture<TodoListComponent>,
import { Injectable } from '@angular/core';
import { Observable, ReplaySubject } from 'rxjs/Rx';
// Dummy class to show mocking without angular2 dependency injection
export class AnalyticsService {
trackDevices(device) {
console.log(device);
return device;
}
}
import { DeviceTypeService, AnalyticsService } from './device-type.service';
import { Observable } from 'rxjs';
import { fakeAsync, tick } from '@angular/core/testing';
describe('DeviceTypeService', () => {
let stub: any = {}, service: DeviceTypeService;
beforeEach(() => {
// Create a stub for the analytics service
stub.AnalyticsService = jasmine.createSpyObj('AnalyticsService', [ 'trackDevices' ]);
@mahulst
mahulst / LoginMsg.elm
Created June 7, 2017 08:26 — forked from ryan-senn/LoginMsg.elm
Update nesting
module Modules.Auth.Login.Msg exposing (..)
import Http exposing (Error)
import Types exposing (User)
type LoginMsg
= LoginUpdateEmail String
| LoginUpdatePassword String
@mahulst
mahulst / GetClickPosition.elm
Created September 16, 2017 10:02
getClickPosition
getClickPosition : Model -> Mouse.Position -> Vec3
getClickPosition model pos =
let
x =
toFloat pos.x
y =
toFloat pos.y
@mahulst
mahulst / RayTriangleIntersect.elm
Last active September 16, 2017 10:02
rayTriangleIntersect
rayTriangleIntersect : Vec3 -> Vec3 -> ( Vec3, Vec3, Vec3 ) -> Maybe Vec3
rayTriangleIntersect rayOrigin rayDirection ( triangle0, triangle1, triangle2 ) =
let
epsilon =
0.000001
edge1 =
Vec3.sub triangle1 triangle0
edge2 =
@mahulst
mahulst / RayTriangleIntersect.elm
Created September 16, 2017 10:02
rayTriangleIntersect
rayTriangleIntersect : Vec3 -> Vec3 -> ( Vec3, Vec3, Vec3 ) -> Maybe Vec3
rayTriangleIntersect rayOrigin rayDirection ( triangle0, triangle1, triangle2 ) =
let
epsilon =
0.000001
edge1 =
Vec3.sub triangle1 triangle0
edge2 =