Skip to content

Instantly share code, notes, and snippets.

View RayLuxembourg's full-sized avatar

Ray Luxembourg RayLuxembourg

View GitHub Profile
@RayLuxembourg
RayLuxembourg / product.component.ts
Created August 19, 2018 14:50
Component using resolver
export class ProductComponent implements OnInit {
product: Product;
constructor(private route: ActivatedRoute) {}
ngOnInit() {
this.product = this.route.snapshot.data['product'];
}
}
@RayLuxembourg
RayLuxembourg / example.repeatable-code.ts
Created August 19, 2018 14:55
example.repeatable-code.ts
interface BaseProduct {
name: string;
id: number;
price: number;
}
interface ProductsList {
top: BaseProduct[];
bottom: BaseProduct[];
@RayLuxembourg
RayLuxembourg / dry-example.ts
Created August 19, 2018 14:58
dry-example.ts
interface BaseProduct {
name: string;
id: number;
price: number;
}
interface ProductsList {
top: BaseProduct[];
bottom: BaseProduct[];
@RayLuxembourg
RayLuxembourg / counter.spec.ts
Created September 10, 2018 09:55
Simple counter test
describe('CounterComponent', () => {
let component: CounterComponent;
let fixture: ComponentFixture<CounterComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [CounterComponent]
}).compileComponents();
}));
@RayLuxembourg
RayLuxembourg / bag.spec.ts
Last active September 10, 2018 10:16
more detailed test
//testing both success and fail status
it('should handle Add to bag Message', () => {
const msg: BagResponse = {
actionType: 'add',
category: 'bag',
product: { colorId: '01', productId: '23423', sizeId: 'SM003' },
status: 'success'
};
component.chooseMessageHandler(msg);
expect(component.bag[0]).toBe(component.buildIdentifier(msg.product));
@RayLuxembourg
RayLuxembourg / DragEvent.ts
Last active November 14, 2018 08:59
Rxjs Universal drag event
export const DragEvent = (selector:string):Observable<boolean> => {
//element where the drag event should be recorded (make sure element is in the dom)
const elem = document.querySelector(selector);
// touch events to handle mobile devices
const touchStart$ = fromEvent<TouchEvent>(elem, 'touchstart');
const touchEnd$ = fromEvent<TouchEvent>(elem, 'touchend');
const romanNumerics = {
I: 1,
V: 5,
X: 10,
L: 50,
C: 100,
D: 500,
M: 1000
};
@RayLuxembourg
RayLuxembourg / FibAlgo.ts
Created April 28, 2019 15:11
Fib Algorithm practice
const fibForLoop = (position: number) => {
const result = [0, 1]
for (let i = 2; i <= position; i++) {
const a = result[i - 1] // first iteration will return 0 , next 1 , 2 , 3
const b = result[i - 2] // first iteration will return 1 , next 2 , 3 , 5}
result.push(a + b)
}
return result[position]
}
@RayLuxembourg
RayLuxembourg / GenericList.tsx
Created May 2, 2019 10:38
React typescript generic list
import * as React from 'react';
export interface GenericListProps<T> {
items: T[];
itemRenderer: (item: T) => JSX.Element;
}
export class GenericList<T> extends React.Component<GenericListProps<T>, {}> {
render() {
const { items, itemRenderer } = this.props;
@RayLuxembourg
RayLuxembourg / RenderProps.tsx
Created May 2, 2019 10:51
Render Props typescript
import * as React from 'react';
interface NameProviderProps {
children: (state: NameProviderState) => React.ReactNode;
}
interface NameProviderState {
readonly name: string;
}