Skip to content

Instantly share code, notes, and snippets.

@Toxicable
Toxicable / file-upload.component.ts
Created October 23, 2016 07:18
How to upload files in angular 2
/**
* Created by Fabian on 19/10/2016.
*/
import { Component, ElementRef, Input } from '@angular/core';
import { Http } from '@angular/http';
@Component({
selector: 'file-upload',
template: '<input type="file" [attr.multiple]="multiple ? true : null" (change)="upload()" >'
})
export class FileUploadComponent {
//usage
const MY_STORE_TOKEN = new InjectionToken('MY_STORE_TOKEN');
@NgModule({
providers: [
//on the ServerModule you want to provide
//ServerStateTransferModule
BrowserStateTransferModule,
//helper function which will provide the store accosiated with this token
import { Component, PLATFORM_ID , Inject} from '@angular/core';
import { isPlatformServer } from '@angular/common'
import { TransferState , makeStateKey} from '@angular/platform-browser';
import { HttpClient } from '@angular/common/http'
interface CounterState {
count: number;
}
const COUNTER_KEY = makeStateKey<CounterState>('my-counter');
export function validate(module: any, bootstrapComponent: any, selector = 'app-root', timeout = 5000) {
@NgModule({
imports: [
BrowserModule.withServerTransition({ appId: selector }),
module
],
declarations: [bootstrapComponent],
bootstrap: [bootstrapComponent],
})
class AppModule { }
let [root] = getAllAngularRootElements();
let appRoot = ng.probe(root);
let [rootComponent] = appRoot.injector.get(ng.coreTokens.ApplicationRef).components;
let ChangeDetectorRef = rootComponent.changeDetectorRef.constructor.prototype;
ChangeDetectorRef.constructor.prototype.detectChanges = (function () {
let oldDC = ChangeDetectorRef.constructor.prototype.detectChanges;
let map = new WeakMap();
return function () {
Zone.root.run(() => showChangeDetection(this));
return oldDC.apply(this, arguments);
import { ChildProcess, spawn } from 'child_process';
import * as execa from 'execa';
const nodeCleanup = require('node-cleanup');
const terminate = require('terminate');
process.env.NODE_ENV = 'e2e';
let childProcesses: ChildProcess[] = [];
function start(cmd: string) {
const proc = execa.shell(cmd);
@Toxicable
Toxicable / cloudSettings
Last active August 9, 2018 03:53
Visual Studio Code Settings Sync Gist
{"lastUpload":"2018-08-09T03:53:20.393Z","extensionVersion":"v3.0.0"}
const fs = require('fs');
const path = require('path');
const JasmineRunner = require('jasmine/lib/jasmine');
const {createInterface} = require('readline');
const UTF8 = {
encoding: 'utf-8'
};
// These exit codes are handled specially by Bazel:
import 'zone.js/dist/zone-node';
import 'reflect-metadata';
import * as http from 'http';
import * as fs from 'fs';
import * as util from 'util';
import * as path from 'path';
import * as url from 'url';
import * as mime from 'mime-types';
import * as os from 'os';
import { ɵCommonEngine as CommonEngine } from '@nguniversal/common/engine';
import * as querystring from 'querystring';
function isObject(arg: any) {
return typeof(arg) === 'object' && arg !== null;
}
const slashedProtocol = {
http: true,
https: true,
ftp: true,