Skip to content

Instantly share code, notes, and snippets.

View manavm1990's full-sized avatar
🏠
Working from home

Manav Misra manavm1990

🏠
Working from home
View GitHub Profile
@manavm1990
manavm1990 / github-proxy-client.js
Created March 11, 2022 16:01 — forked from DavidWells/github-proxy-client.js
Full Github REST api in 34 lines of code
/* Ultra lightweight Github REST Client */
const token = 'github-token-here'
const githubClient = generateAPI('https://api.github.com', {
headers: {
'User-Agent': 'xyz',
'Authorization': `bearer ${token}`
}
})
async function getRepo() {
@manavm1990
manavm1990 / reversed.cs
Created February 15, 2022 12:43
Reverse Sentence
string pangram = "The quick brown fox jumps over the lazy dog";
string[] words = pangram.Split(' ');
foreach (string word in words)
{
char[] chars = word.ToCharArray();
Array.Reverse(chars);
string wordReversed = new string(chars);
Console.Write($"{wordReversed} ");
}
@manavm1990
manavm1990 / curry.js
Created December 6, 2021 11:00
Curry 🇮🇳 Fxn
const curry =
(fn) =>
// Rest into an array
(...args) =>
// If we have enough arguments, call the function
args.length >= fn.length
? // Spread array into arguments
fn(...args)
: curry(
/**
@manavm1990
manavm1990 / index.js
Created December 5, 2021 14:34
Fxn. I Wrote To Sort Through 🏦 Transactions Data
const results = JSON.parse(data)
.map(
({
"Transaction date": date,
Description: description,
Amount: amount,
}) => ({
date,
description,
amount,
@manavm1990
manavm1990 / buidPipeline.js
Created November 25, 2021 14:33
As seen in the 📖 Composing Software by Eric Elliott
const buildPipeline =
(...fns) =>
(x) =>
fns.reduce((accV, fxn) => fxn(accV), x);
const { gql } = require('apollo-server');
module.exports = gql`
type Post {
_id: ID!
body: String!
createdAt: String!
username: String!
comments: [Comment]
commentCount: Int!
const converters = {
toCelsius(tempF) {
return ((tempF - 32) * 5) / 9;
},
toFahrenheit(tempC) {
return ((tempC - 32) * 5) / 9;
},
};
function tryConvert(temperature, conversion) {
@manavm1990
manavm1990 / mongodb.js
Last active November 30, 2021 11:19
Create connection to mongodb and keep alive until server shut down.
// Loads a reusable Mongo client for the application.
import { MongoClient } from "mongodb";
// TODO: Check that your path is correct if using a config file (which you should)
import config from "../../config.js";
// TODO: Check that your config file is exporting out an object with properties used in the next line.
const client = new MongoClient(config.db.clientURL);
client
const person = {
name: "Mark",
age: 35
}
if (person.age >= 21) {
console.log(`${person.name} can have a drink of alcohol.`);
} else {
console.log(`${person.name} shsoud have a soda`);
}
// Destructuring
const data = {
first_name: "John",
age: 30,
employer: {
company: "Google",
},
};
// Object destructuring with renaming