Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Ezeokafor GoodnessEzeokafor

🏠
Working from home
View GitHub Profile
@GoodnessEzeokafor
GoodnessEzeokafor / self.decorator.ts
Created July 3, 2022 12:30 — forked from DimosthenisK/self.decorator.ts
NestJS Guard + Decorator that allows user access limit to his own resources
View self.decorator.ts
import { SetMetadata } from '@nestjs/common';
export interface SelfDecoratorParams {
userIDParam: string;
allowAdmins?: boolean;
}
export const Self = (params: SelfDecoratorParams | string) =>
SetMetadata(
'selfParams',
@GoodnessEzeokafor
GoodnessEzeokafor / crypto-rate.ts
Created March 21, 2022 11:22
crypto rate from coingecko
View crypto-rate.ts
import axios from "axios"
const COINGGECKO_BASE_URL:string = 'https://api.coingecko.com/api/v3'
const VS_CURRENCY: string = "usd"
const CURRENCY_IDS:string = "bitcoin,ethereum,ripple,stellar,celo"
const ORDER:string = "market_cap_desc"
const PERPAGE:number = 100
const PAGE = 1
const SPARKLINE:boolean = false
@GoodnessEzeokafor
GoodnessEzeokafor / axios.ts
Created March 11, 2022 08:27
Native Axios Implementation in Nest js
View axios.ts
import { Injectable, Logger } from "@nestjs/common";
import axios from "axios";
import { IHttpServices } from "src/core/abstracts/http-services.abstract";
@Injectable()
export class AxiosService implements IHttpServices {
async get(url: string, config: Record<string, any>) {
try {
const response = await axios.get(url, config)
View eventEmitter.ts
/********
* This module will help us decouple alot of functionality like
* * sending emails
* * sending sms
* * sending notification
* * tracking users activities
*
*/
import * as events from "events"
@GoodnessEzeokafor
GoodnessEzeokafor / firebaseFineOne.ts
Created February 17, 2022 09:47
Firebase find query
View firebaseFineOne.ts
type FilterQuery<T> = {
[K in keyof T]?: T[K]
};
static async findOne(field: FilterQuery<ITranslation>): Promise<any> {
try {
const results = await this.builder().where(Object.keys(field)[0], "==", Object.values(field)[0]).get();
if (results.length) {
return results[0];
}
@GoodnessEzeokafor
GoodnessEzeokafor / IRepository.ts
Created January 24, 2022 10:58 — forked from Orbis25/IRepository.ts
Simple Repository Pattern in TypeScript with axios
View IRepository.ts
import { AxiosResponse } from "axios";
import { AxiosConfig } from "../../api";
export interface IRead<T> {
getAll(route: string, params?: string): Promise<AxiosResponse<T[]>>;
getById(route: string, id: string): Promise<AxiosResponse<T>>;
getPaginatedList(route: string, params?: string): Promise<AxiosResponse<T[]>>;
}
export interface IWrite<T> {
@GoodnessEzeokafor
GoodnessEzeokafor / hash.cfml
Created December 8, 2021 12:12
Cold fusion examples
View hash.cfml
<cfoutput>
#hash("Password1!", "SHA-512", "UTF-8")#
</cfoutput>
# output - ECB3548B49FEFA9C984EC134FA362B3316EC8CC4C044B3A71444EED538ECC39461FE5D4DD1D71287FCD2B1C3354CC36873956B3E15229B5ACBDACDA276BABED1
@GoodnessEzeokafor
GoodnessEzeokafor / encrypt.ts
Last active December 8, 2021 10:38
Obj Encryption
View encrypt.ts
const osbEncryption = (str: string | Record<string, any>) => {
console.log("STRING",str)
const reverseString = str.split("").reverse().join("")
console.log("REVERSE STRING", reverseString)
let hmac = crypto.createHash("sha512");
hmac.update(typeof reverseString === 'string' ? reverseString : JSON.stringify(reverseString));
return Buffer.from(hmac.digest()).toString('hex')
}
@GoodnessEzeokafor
GoodnessEzeokafor / transactions.js
Created November 29, 2021 12:20
Mongo-Db-Transactions
View transactions.js
/**
* Rules for MONGODB Multi Document Transactions
* All data modeling rules still applies
* Transactions should be the most common operation
* Pass in the session to all statements
* Implement retry logic , transactions can always abort
* Plan for DDL operations
*/
import db, { ClientSession } from 'mongoose';
/**
View calculator.py
import math
from functools import reduce
class Calculator:
def __init__(self):
pass
def __str__(self):
return "Basic calculator"