Skip to content

Instantly share code, notes, and snippets.

View pmahmud's full-sized avatar

Pallab Mahmud pmahmud

View GitHub Profile
@pmahmud
pmahmud / flatten.js
Last active August 2, 2019 18:06
ES6 - flatten an array using stack - non recursive
const nestedArray = [
1, 2, 3, 2,
[23, 4, 5, 2, [2, 4, 5, 6, 5, 123, 3, [-2, 4, -4]]]
];
const flatten = (nestedArray) => {
const stack = [...nestedArray];
const result = [];
while(stack.length) {
const nextElement = stack.pop();
@pmahmud
pmahmud / regex.md
Created March 7, 2018 02:28
Common Regex

multiline comment: /\\*.*?\\*/

@pmahmud
pmahmud / mongo-commands.md
Last active April 8, 2016 19:52
MongoDB Commands

###Useful MongoDB commands

> mongo
  • show all the available databases
> show dbs
@pmahmud
pmahmud / js-design-patterns.md
Last active August 29, 2015 14:24
JavaScript design patterns

##Creating object with literals

var car = {};

car.color = 'blue';
car['model'] = 'bmw';

car['build year'] = 2000;

Object.defineProperty(car, 'registrationNumber',{
@pmahmud
pmahmud / git-commands.md
Last active January 25, 2018 02:07
Useful git commands

Useful git commands for github

Official Cheat Sheets from GitHub Gihub Cheatsheets

Add your user name and email

> git config --global user.name "Pallab Mahmud"
> git config --global user.email "pmahmud@uoregon.edu"
@pmahmud
pmahmud / handle-error-in-node.md
Last active August 29, 2015 14:24
Handle errors in Node

Handling errors in node

#####Safely "throwing" errors

Ideally we'd like to avoid uncaught errors as much as possible, as such, instead of literally throwing the error, we can instead safely "throw" the error using one of the following methods depending on our code architecture:

For synchronous code, if an error happens, return the error:

@pmahmud
pmahmud / thirdParty.factory.js
Created July 7, 2015 18:15
Use third party JS package in angular
/*
This gist is a work-around of the dependency injection issue of third party packages in an Angular project.
*/
'use strict';
angular.module('yourAppName')
.factory('thirdPartyPackageName',function( $window ) {
/* Get the package from $window */
var thirdPartyPackageName = $window.thirdPartyPackageName;
delete( $window.thirdPartyPackageName );