Skip to content

Instantly share code, notes, and snippets.

View micaiah-effiong's full-sized avatar
👨‍💻
Focusing

Micah Effiong micaiah-effiong

👨‍💻
Focusing
View GitHub Profile
@micaiah-effiong
micaiah-effiong / addToBuildGradle.ts
Created November 8, 2024 21:30
A function for expo-plugin that adds new lines to build gradle. Can be used to add lines to other files
const addToBuildGradle = (
newLine: string,
anchor: RegExp | string,
offset: number,
buildGradle: string,
) => {
const lines = buildGradle.split('\n');
const lineIndex = lines.findIndex((line) => line.match(anchor));
// add after given line
lines.splice(lineIndex + offset, 0, newLine);
@micaiah-effiong
micaiah-effiong / list-view.md
Created August 13, 2024 13:48
Get the selected element/list-item from gtk4 listview
@micaiah-effiong
micaiah-effiong / array-range.ts
Last active February 23, 2024 01:35
get a fixed range of data from an array. if bounds overflow it shift in the other direction.
function edgeAwareSlice<T>(arr: Array<T>, start: number, win: number) {
if(win > arr.length) { return arr }
const half = Math.floor(win/2)
let front = start - half
let back = start + half;
if (back >= arr.length){
// console.log('gap', {front, back, diff: (back+win%2) - arr.length}, arr.length)
@micaiah-effiong
micaiah-effiong / storage.service.ts
Created August 14, 2023 23:56
google cloud storage service for Nestjs
import { Injectable, InternalServerErrorException } from '@nestjs/common';
import { Storage, Bucket, File } from '@google-cloud/storage';
import StorageKeyFile from 'src/config/storage-service-account.json';
import { ConfigService } from '@nestjs/config';
import { ENV } from 'src/config';
import { BucketDirectories } from './constants';
@Injectable()
export class StorageService {
private gcStorage = new Storage({
import {
CallHandler,
ExecutionContext,
Injectable,
NestInterceptor,
} from '@nestjs/common';
import { Response } from 'express';
import { map, Observable } from 'rxjs';
@Injectable()
@micaiah-effiong
micaiah-effiong / firebase-function-deploy.md
Created April 5, 2023 14:14
APIs and roles needed for deploying firebase functions using service account

APIs and roles needed for deploying firebase functions using service account

Date: 5th April, 2023.

Time: 3:00pm WAT.

Report:

Succesfully deployed a firebase function, using a service account.
This was me trying not to use the ci token as it was flagged unsafe.

This gist contains the roles needed for your service account to deploy properly

@micaiah-effiong
micaiah-effiong / plateNumberNG.ts
Created February 16, 2023 08:59
Regex for validating Nigerian vehicle plate number
const plateNumberRexEx = /^(KWL|ABC|BWR|RSH|JJJ|AAA|LSR|FKJ|FST|APP|AGL|EPE|LND|MUS|KRE|FNN|SGB|LES|EDE|GBN|BAT|CRC|BDW|DDM|BKR|DMS|NGW|JBY|KFY|BRE|DJA|MLF|KTN|DTS|BDJ|GBR|SEY|LUY|AME|MAP|NRK|BJE|KAM|ANA|CAL|KMM|BRA|DUK|GEP|BNS|EFE|GGJ|CKK|TGD|UDU|BKS|GWL|NSR|UGG|KMC|TRN|DTF|DAL|KER|EFY|ADK|EMR|AMK|KLE|TUN|WEN|KEK|AKR|KTP|FFN|REE|SUA|JTA|NND|ABU|AHD|KNM|ABM|NDN|BGM|BNY|DEG|NCH|MHA|KHE|KPR|SKP|BRR|RUM|RGM|GGU|KRK|BER|PBT)-\d{3}[A-Z]{2}$/gi;
function validatePlateNumber(pn: string): boolean{
return plateNumberRexEx.test(pn)
}
@micaiah-effiong
micaiah-effiong / nest-swagger-docs-response-transformer.ts
Last active October 6, 2023 12:54
transforms response entity for swagger docs decorators
import { Type } from '@nestjs/common';
import {
ApiProperty,
ApiPropertyOptions,
ApiResponse,
ApiResponseOptions,
} from '@nestjs/swagger';
export const CustomApiResponseArray = <T>(
entity: Type<T>,
@micaiah-effiong
micaiah-effiong / rust_prompt.rs
Last active August 21, 2022 00:22
Prompt for an input with a custom message. Similar to python input function
fn prompt(msg:&str) -> String {
println!("{msg}");
let mut input:String = String::new();
std::io::stdin().read_line(&mut input).expect("Could not read input");
return input;
}
let guess_value:String = prompt("How many times do you want to try");
@ponelat
ponelat / asyncapi-avro-example.yml
Created May 16, 2022 10:55
AsyncAPI - Avro example
asyncapi: 2.4.0
info:
title: Avro Example
version: 1.0.0
description: |-
An Avro example
channels:
'tweets':
description: This is the firehose of all Tweets