Skip to content

Instantly share code, notes, and snippets.

View cgatian's full-sized avatar
🏠
Working from home

Chaz Gatian cgatian

🏠
Working from home
View GitHub Profile
public class Base
{
public long _id;
public Base(long id)
{
this._id = id;
}
}
public class A : Base
public class Singleton
{
private static readonly Lazy<Singleton> _lazy = new Lazy<Singleton>(
() => new Singleton(), isThreadSafe: true);
public static Singleton Instance
{
get
{
return Singleton._lazy.Value;
@cgatian
cgatian / js-guarantee new
Created August 9, 2013 13:45
Guarantee the object is created using the constructor and not placing itself into the global namespace.
function Class()
{
if(!(this instanceof Class))
{
return new Class();
}
}
var _obj = Class();
@cgatian
cgatian / arrayForeach - (from Knockout Source)
Last active December 28, 2015 07:49
Reusable function for scoping issues when invoking functions in JavaScript.
var arrayForEach = function (array, action)
{
for (var i = 0, j = array.length; i < j; i++)
{
action(array[i]);
}
};
//Usage
@cgatian
cgatian / server.js
Created October 18, 2016 15:09
Simple Express Server with gzip
'use strict';
let path = require('path');
let express = require('express');
let compression = require('compression');
// Constants
let PORT = 8080;
// App
@cgatian
cgatian / hmr.ts
Created April 18, 2017 19:24
Angular Module HMR Bootstrap
import { NgModuleRef, ApplicationRef, Type } from '@angular/core';
import { createNewHosts, createInputTransfer, removeNgStyles } from '@angularclass/hmr';
/**
* Adds HMR to an existing Angular Module
*
* Credits & References:
* https://webpack.github.io/docs/hot-module-replacement.html
* https://github.com/AngularClass/angular2-hmr
* https://medium.com/@beeman/tutorial-enable-hrm-in-angular-cli-apps-1b0d13b80130
@cgatian
cgatian / image-carousel.component.ts
Created April 27, 2017 12:44
Image Carousel Component
@cgatian
cgatian / app.component.ts
Last active April 2, 2018 11:01
Dynamically creating a component in DOM location
@Component({
selector: 'app-root',
template: ``
})
export class AppComponent implements OnInit {
private componentRef;
constructor(
private componentFactoryResolver: ComponentFactoryResolver,
private injector: Injector
@cgatian
cgatian / header.component.ts
Last active October 24, 2017 00:25
sample header component
@Component({
selector: 'my-header',
template: `<h1>{{ title }}</h1>`
})
export class HeaderComponent {
title = 'Hello World';
constructor() {
setTimeout(_ => {
this.title = 'Updated!';
@cgatian
cgatian / app.component.ts
Last active October 24, 2017 01:13
app component using portals
import { DomPortalHost, Portal, ComponentPortal } from '@angular/cdk/portal';
@Component({
selector: 'my-app',
template: '',
})
export class AppComponent implements OnInit {
private portalHost: DomPortalHost;
private portal: ComponentPortal<HeaderComponent>;