Skip to content

Instantly share code, notes, and snippets.

View osamaishtiaq's full-sized avatar
🤘
Feeling Innovative

Oisee (Osama Ishtiaq) osamaishtiaq

🤘
Feeling Innovative
View GitHub Profile
@osamaishtiaq
osamaishtiaq / gist:481f09c982cabcfbfc1ed1b9ccceb51d
Created January 15, 2024 14:08
Removes a function call foo'(' along with its closing bracket ')' from a text
function buildFunctionRemoverFunction(functionName) {
return function (text) {
let replacedTxt = text.replaceAll(functionName+"(", "").split("");
let isBracketClosed = true;
for (let i = 0; i < replacedTxt.length-1; i+=1) {
if (replacedTxt[i] === "(") {
isBracketClosed = false;
} else if (replacedTxt[i] === ")" && isBracketClosed === false) {
@osamaishtiaq
osamaishtiaq / cleanAndSortGraphQLType.js
Created August 24, 2023 09:46
Given a graphql type, it will clean out all the comments and sort the fields alphabetically. Saves time when for example you have to compare two types.
function cleanAndSortGraphQLType(typeString) {
const lines = typeString.split('\n');
const indent = lines[1].match(/^\s*/)[0]; // Get the leading indentation
const cleanLines = lines
.map(line => line.replace(/\/\/.*/g, '').trim()) // Remove comments
.filter(line => line.length > 0); // Remove empty lines
const fields = cleanLines
.filter(line => line.includes(':'))
/**
*
* @param pageName - Page name you want to check
* @returns Object { followers, followings, accountsNotFollowBack }
*/
async function getListOfPeopleWhoNotFollow(pageName) {
let username = pageName; // your page name, mine is oisee_gallery
try {
console.log("Fetching data....");
let res = await fetch(`https://www.instagram.com/${username}/?__a=1`)
@osamaishtiaq
osamaishtiaq / example-request-retry.js
Created April 15, 2022 00:14
Example of using request retry
// without request retry
async fetchHttpMediaBufferArray(imageUrl) {
try {
// your request code
const bufferResp = await firstValueFrom(
this.httpService.get(imageUrl, { responseType: 'arraybuffer' }),
);
const contentType = bufferResp.headers['content-type'];
const buffer = Buffer.from(bufferResp.data);
@osamaishtiaq
osamaishtiaq / request-retry.js
Created April 15, 2022 00:00
Request retry mechanism in JavaScript
export async function requestWithRetry(requestFunc, errFunc, retryCount = 3) {
try {
return await requestFunc();
} catch (err) {
if (retryCount <= 0) {
errFunc(err);
}
console.log('Request failed, retrying...');
retryCount -= 1;
@osamaishtiaq
osamaishtiaq / PostgresCountDatatypeFromString.sql
Last active April 6, 2019 18:13
Check Possible Data Type of a string using pattern matching in PostgreSQL and Return Count.
SELECT COUNT(1) AS COUNT, 'Decimal' as DataType
FROM @TableName
WHERE @ColumnName ~ '^\d+\.\d+$'
UNION ALL
SELECT COUNT(1) AS COUNT, 'Integer' as DataType
FROM @TableName
WHERE @ColumnName ~ '^\+?(0|[1-9]\d*)$'
UNION ALL