Skip to content

Instantly share code, notes, and snippets.

Avatar

Dave Bush DaveMBush

  • Cheshire, CT
View GitHub Profile
@DaveMBush
DaveMBush / buttonClick.js
Last active Aug 5, 2017
Explaining Observables
View buttonClick.js
Observable.fromEvent(this.myButton,'click').subscribe((event) =>
   /* do something in response to the click here */
);
@DaveMBush
DaveMBush / package.json
Last active Aug 1, 2017
Functional TypeScript
View package.json
{
...
"scripts": {
"lint": "ng lint --type-check",
...
},
"pre-commit": [
"lint"
],
...
View app-routes1.module.ts
export const routes: Routes = [];
@NgModule({})
export class AppRoutesModule {}
@DaveMBush
DaveMBush / b64ToFile.ts
Last active Jul 1, 2017
Image Blog Post
View b64ToFile.ts
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 Jun 10, 2017
RxJS Marble Testing
View create-observable.ts
const testScheduler = new TestScheduler();
const hotObservable = testScheduler.createHotObservable(hotMarbleString);
const coldObservable = testScheduler.createColdObservable(coldMarbleString);
@DaveMBush
DaveMBush / directory-structure.txt
Last active Jul 14, 2017
NgRX-With-SubReducers
View directory-structure.txt
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
NgRX Sample Code
View app.module1.ts
// standard imports omitted for clarity
import {AppStores} from './app.stores';
import { AppComponent } from './app.component';
@NgModule({
declarations: [
AppComponent
],
imports: [
View app.component.html
<ng-template #dynamicInsert></ng-template>
@DaveMBush
DaveMBush / model-form-patch.ts
Last active Apr 15, 2017
Angular(2+) Model Driven Forms Are Superior
View model-form-patch.ts
this.form.patchValue({
name: contact.name,
sex:contact.sex,
dob:contact.dob.toLocaleDateString()
});
View fix-one-a.ts
Object.defineProperty(XMLHttpRequest.prototype, 'onreadystatechange', {
enumerable: true,
configurable: true,
get: function() {
return this.orsc;
},
set: function(f) {
this.orsc = f;
}
});