Skip to content

Instantly share code, notes, and snippets.

View DaveMBush's full-sized avatar

Dave Bush DaveMBush

  • Cheshire, CT
View GitHub Profile
@DaveMBush
DaveMBush / buttonClick.js
Last active August 5, 2017 15:59
Explaining Observables
Observable.fromEvent(this.myButton,'click').subscribe((event) =>
   /* do something in response to the click here */
);
@DaveMBush
DaveMBush / package.json
Last active August 1, 2017 12:54
Functional TypeScript
{
...
"scripts": {
"lint": "ng lint --type-check",
...
},
"pre-commit": [
"lint"
],
...
@DaveMBush
DaveMBush / app-routes1.module.ts
Last active July 15, 2017 19:16
Angular Routing
export const routes: Routes = [];
@NgModule({})
export class AppRoutesModule {}
@DaveMBush
DaveMBush / b64ToFile.ts
Last active July 1, 2017 16:29
Image Blog Post
b64toFile(dataURI): File {
// convert the data URL to a byte string
const byteString = atob(dataURI.split(',')[1]);
// pull out the mime type from the data URL
const mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0]
// Convert to byte array
const ab = new ArrayBuffer(byteString.length);
const ia = new Uint8Array(ab);
@DaveMBush
DaveMBush / create-observable.ts
Last active June 10, 2017 18:24
RxJS Marble Testing
const testScheduler = new TestScheduler();
const hotObservable = testScheduler.createHotObservable(hotMarbleString);
const coldObservable = testScheduler.createColdObservable(coldMarbleString);
@DaveMBush
DaveMBush / directory-structure.txt
Last active July 14, 2017 15:22
NgRX-With-SubReducers
app/
+-store/
+-route1/
+-sub-reducer1/
--sub-reducer1.actions.ts
--sub-reducer1.effects.ts
--sub-reducer1.model.ts
--sub-reducer1.reducer.ts
+-sub-reducer2/
--route1.actions.ts
@DaveMBush
DaveMBush / app.module1.ts
Last active May 20, 2017 15:47
NgRX Sample Code
// standard imports omitted for clarity
import {AppStores} from './app.stores';
import { AppComponent } from './app.component';
@NgModule({
declarations: [
AppComponent
],
imports: [
@DaveMBush
DaveMBush / app.component.html
Last active December 21, 2017 17:29
DynamicComponent
<ng-template #dynamicInsert></ng-template>
@DaveMBush
DaveMBush / model-form-patch.ts
Last active April 15, 2017 20:55
Angular(2+) Model Driven Forms Are Superior
this.form.patchValue({
name: contact.name,
sex:contact.sex,
dob:contact.dob.toLocaleDateString()
});
Object.defineProperty(XMLHttpRequest.prototype, 'onreadystatechange', {
enumerable: true,
configurable: true,
get: function() {
return this.orsc;
},
set: function(f) {
this.orsc = f;
}
});