Skip to content

Instantly share code, notes, and snippets.

🌴
On vacation

Parth Agarwal Parth-Agarwal

🌴
On vacation
  • India
Block or report user

Report or block Parth-Agarwal

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@Parth-Agarwal
Parth-Agarwal / main.js
Created Sep 28, 2019
Quick start js for serving pre-made front end on localhost.
View main.js
// Imports
const express = require('express')
const path = require('path')
// Initializations
const app = express()
const router = express.Router()
// Static Files Directory
app.use(express.static(__dirname + '/public'))
@Parth-Agarwal
Parth-Agarwal / Character Picture Grid.py
Created Aug 8, 2019
Character Picture Grid Plotter. Column Wise.
View Character Picture Grid.py
grid = [
[".", ".", ".", ".", ".", "."],
[".", "0", "0", ".", ".", "."],
["0", "0", "0", "0", ".", "."],
["0", "0", "0", "0", "0", "."],
[".", "0", "0", "0", "0", "0"],
["0", "0", "0", "0", "0", "."],
["0", "0", "0", "0", ".", "."],
[".", "0", "0", ".", ".", "."],
[".", ".", ".", ".", ".", "."],
@Parth-Agarwal
Parth-Agarwal / beautifulList.py
Created Aug 8, 2019
Convert a list into a grammatically readable string.
View beautifulList.py
items = ["Cheese", "Tomato", "Potato", "Cucumber", "Salt", "Pepper"]
def beautifulList(array):
string = ""
for index, item in enumerate(array, start=1):
string += "and " + item if index == len(items) else item + ", "
return string
print(beautifulList(items))
@Parth-Agarwal
Parth-Agarwal / Collatz.py
Created Aug 6, 2019
Collatz Sequence Using Python
View Collatz.py
# Collatz Operation
def collatz(number):
if number % 2 == 0: # Check for Even
operation = number // 2
print(operation)
return operation
else:
operation = 3 * number + 1
print(operation)
return operation
@Parth-Agarwal
Parth-Agarwal / Angular CLI New Project
Last active Aug 5, 2019
Custom new clean project starter for Angular CLI
View Angular CLI New Project
ng new client --routing=true --skipTests=true --style=scss
Then delete e2e folder.
Under .vscode folder and settings.json file:
{
"files.exclude": {
"**/.git": true,
"**/.svn": true,
View Firestore Retrieve Collection
import {AngularFirestore,AngularFirestoreCollection,AngularFirestoreDocument} from '@angular/fire/firestore'
this.usersCollection = this.afs.collection('users')
this.users = this.usersCollection.valueChanges()
this.usersCollection.valueChanges().subscribe(data => data.forEach(element => {
console.log(element)
}))
@Parth-Agarwal
Parth-Agarwal / Extracting Data From Array
Created Jun 14, 2019
Extracting Data from an Array or Array of Objects in Typescript using higher order functions.
View Extracting Data From Array
// Get List of Items only
this.categories = Array.from(new Set(this.items.map((item: any) => item.category)))
// Filter and Get List of Items (Chaining Higher Order Functions)
this.subcategories = Array.from(new Set(this.items.filter((item: any) => item.category == this.addForm.get('category').value).map((item: any) => item.subcategory)))
@Parth-Agarwal
Parth-Agarwal / Strict Mongoose Schema
Created Jun 12, 2019
Mongoose Extended Strict Schema Definition.
View Strict Mongoose Schema
const mongoose = require('mongoose');
var itemSchema = new mongoose.Schema({
category: {
type: String,
unique: false,
required: true,
dropDups: false,
},
subcategory: {
@Parth-Agarwal
Parth-Agarwal / Mongoose Create Document
Last active Jun 12, 2019
Mongoose Create Document with Proper Error Handling.
View Mongoose Create Document
Item.create(motor, function (error, doc) {
if (error && error.name === 'MongoError' && error.code === 11000) {
console.log({
"error": error.errmsg
})
} else if (error) {
console.log(error)
}
})
@Parth-Agarwal
Parth-Agarwal / Intersect.py
Created Apr 19, 2019
Python Challenge 5: Find intersection in two sets.
View Intersect.py
a = [2,3,4,5,5,6,7,8,8,9,10]
b = [2,3,4,5,5,6,7,8,8,9,10,11,12,13,14,15]
c = []
print([e for e in b if e in a and e not in c])
You can’t perform that action at this time.