Skip to content

Instantly share code, notes, and snippets.

View tariknz's full-sized avatar

Tarik Alani tariknz

  • New Zealand
  • 22:15 (UTC +13:00)
  • LinkedIn in/tariknz
View GitHub Profile
@tariknz
tariknz / sublimefolder.reg
Created November 11, 2013 05:38
Open folder with Sublime Text 3 (or 2) via Windows contextual right-click menu.
Windows Registry Editor Version 5.00
; This will make it appear when you right click ON a folder
; The "Icon" line can be removed if you don't want the icon to appear
[HKEY_CLASSES_ROOT\Directory\shell\sublime]
@="Open Folder as &Sublime Project"
"Icon"="\"C:\\Program Files\\Sublime Text 3\\sublime_text.exe\",0"
[HKEY_CLASSES_ROOT\Directory\shell\sublime\command]
import { MdDialogRef } from '@angular/material';
import { Component } from '@angular/core';
@Component({
selector: 'confirm-dialog',
template: `
<p>{{ title }}</p>
<p>{{ message }}</p>
<button type="button" md-raised-button
(click)="dialogRef.close(true)">OK</button>
import { MdDialogRef } from '@angular/material';
import { Component } from '@angular/core';
@Component({
selector: 'confirm-dialog',
template: `
<p>{{ title }}</p>
<p>{{ message }}</p>
<button type="button" md-raised-button
(click)="dialogRef.close(true)">OK</button>
import { Observable } from 'rxjs/Rx';
import { ConfirmDialog } from './confirm-dialog.component';
import { MdDialogRef, MdDialog, MdDialogConfig } from '@angular/material';
import { Injectable } from '@angular/core';
@Injectable()
export class DialogsService {
constructor(private dialog: MdDialog) { }
import { DialogsService } from './dialogs.service';
import { MdDialogModule, MdButtonModule } from '@angular/material';
import { NgModule } from '@angular/core';
import { ConfirmDialog } from './confirm-dialog.component';
@NgModule({
imports: [
MdDialogModule,
MdButtonModule,
import {Component} from '@angular/core';
import {DialogsService} from './dialogs.service';
@Component({
selector: 'material-app',
template: `
<div>
<button md-raised-button (click)="openDialog()">Open Dialog</button>
<p>Result from dialog: {{ result }}</p>
</div>
import {
Component, Input, ElementRef, AfterViewInit, ViewChild
} from '@angular/core';
@Component({
selector: 'app-canvas',
template: '<canvas #canvas></canvas>',
styles: ['canvas { border: 1px solid #000; }']
})
export class CanvasComponent implements AfterViewInit {
@tariknz
tariknz / draw-2.ts
Last active November 24, 2018 00:04
private captureEvents(canvasEl: HTMLCanvasElement) {
// this will capture all mousedown events from the canvas element
fromEvent(canvasEl, 'mousedown')
.pipe(
switchMap((e) => {
// after a mouse down, we'll record all mouse moves
return fromEvent(canvasEl, 'mousemove')
.pipe(
// we'll stop (and unsubscribe) once the user releases the mouse
// this will trigger a 'mouseup' event
private drawOnCanvas(
prevPos: { x: number, y: number },
currentPos: { x: number, y: number }
) {
// incase the context is not set
if (!this.cx) { return; }
// start our drawing path
this.cx.beginPath();
private captureEvents(canvasEl: HTMLCanvasElement) {
Observable
.fromEvent(canvasEl, 'mousedown')
.switchMap((e) => {
return Observable
.fromEvent(canvasEl, 'mousemove')
.takeUntil(Observable.fromEvent(canvasEl, 'mouseup'))
.pairwise()
})
.subscribe((res: [MouseEvent, MouseEvent]) => {