This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type AnyResolvers = { | |
[prop in PropertyKey]: (params: any) => any | |
} | |
type Resolved<R extends AnyResolvers> = { | |
[prop in keyof R]: Awaited<ReturnType<R[prop]>> | |
} | |
type UnionToIntersection<U> = (U extends any ? (a: U) => any : never) extends ((b: infer A) => any) ? A : never; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const startsWith = (letter: string) => | |
(word: string) => | |
word[0] === letter; | |
const isAny = () => | |
true; | |
const lastLetterOf = (word: string): string => | |
word[word.length - 1]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const isThenable = value => typeof value?.then === "function"; | |
const wrapHandler = (handler, resolve, reject) => resultOrError => { | |
try { | |
const handledResult = handler(resultOrError); | |
if (isThenable(handledResult)) { | |
handledResult.then(resolve, reject); | |
} else { | |
resolve(handledResult); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class CodingService { | |
abstract Developer createDeveloper(); | |
public void writeCode() { | |
Developer dev = createDeveloper(); | |
String code = dev.writeCode(); | |
System.out.println(code); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { CallHandler, ExecutionContext, Injectable, NestInterceptor } from '@nestjs/common'; | |
import { Observable } from 'rxjs'; | |
import { flatMap } from 'rxjs/operators'; | |
import { fromFunctionCall } from '../common/utils'; | |
@Injectable() | |
export class LoginInterceptor implements NestInterceptor { | |
intercept(context: ExecutionContext, next: CallHandler): Observable<any> { | |
const req = context.switchToHttp().getRequest(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { CallHandler, ExecutionContext, Injectable, NestInterceptor } from '@nestjs/common'; | |
import { Observable, Observer } from 'rxjs'; | |
import { flatMap } from 'rxjs/operators'; | |
const nextAndComplete = <T>(observer: Observer<T>, value?: T): void => { | |
observer.next(result); | |
observer.complete(); | |
}; | |
@Injectable() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createParamDecorator, ExecutionContext, SetMetadata } from '@nestjs/common'; | |
export const Passport = createParamDecorator((data: unknown, ctx: ExecutionContext) => { | |
const req = ctx.switchToHttp().getRequest(); | |
const logIn = <U>(user: U): Promise<U> => new Promise( | |
(resolve, reject) => req.logIn(user, err => err ? reject(err) : resolve(user)) | |
); | |
return { logIn }; | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const message = | |
i % 3 === 0 && i % 5 === 0 ? ( | |
"fizzbuzz" | |
) : i % 3 === 0 ? ( | |
"fizz" | |
) : i % 5 === 0 ? ( | |
"buzz" | |
) : i % 7 === 0 ? ( | |
"foo" | |
) : ( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface IServices { | |
logger: ILogger, | |
dataAccessService: IDataAccessService, | |
ecommerceService: IECommerceService, | |
} | |
class ServiceLocator implements IServices { | |
private _logger: ILogger | null = null; | |
private _dataAccessService: IDataAccessService | null = null; | |
private _ecommerceService: IECommerceService | null = null; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { compose } from "...somewhere..."; | |
export const diContext = React.createContext({ | |
container: {}, | |
run: () => {}, | |
)); | |
export const { Consumer } = diContext; |
NewerOlder