Skip to content

Instantly share code, notes, and snippets.

View singhmohancs's full-sized avatar
👨‍💻
Building with JavaScript, React, Angular, NodeJs, MongoDb and AWS Serverless

Mohan Singh singhmohancs

👨‍💻
Building with JavaScript, React, Angular, NodeJs, MongoDb and AWS Serverless
View GitHub Profile
@singhmohancs
singhmohancs / git-reset-remote.sh
Last active August 7, 2023 08:03 — forked from CaroManel/git-reset-remote.sh
delete all commits, empty repository
rm -r .git
git init
(create files)
git add -A
git commit -m 'Initial commit'
git remote add origin <url>
git push --force --set-upstream origin master
@singhmohancs
singhmohancs / confirm-unsaved-changes.directive.js
Created May 22, 2017 05:39
Detect Unsaved changes and show confirm modal + angularjs
/**
* @ngdoc Directive
* @name app.confirmOnExit
*
* @description
* Prompts user while he navigating away from the current route (or, as long as this directive
* is not destroyed) if any unsaved form changes present.
*
* @element Attribute
* @scope
@singhmohancs
singhmohancs / dateFormat.js
Created May 19, 2017 07:56
Date format + Javascript
/**
* Format datetime
* Usage:
* new Date().format('yyyy/MM/dd'), new Date().format('hh:mm:ss')
* @param {String} format
* @return {String}
*/
Date.prototype.format = function(format) {
var self = this;
@singhmohancs
singhmohancs / README.md
Created April 13, 2020 04:30 — forked from pbojinov/README.md
Two way iframe communication- Check out working example here: http://pbojinov.github.io/iframe-communication/

Two way iframe communication

The main difference between the two pages is the method of sending messages. Recieving messages is the same in both.

Parent

Send messages to iframe using iframeEl.contentWindow.postMessage Recieve messages using window.addEventListener('message')

iframe

@singhmohancs
singhmohancs / javascript-object-to-querystring.js
Created June 16, 2019 04:32 — forked from tjmehta/javascript-object-to-querystring.js
Object to Querystring - JavaScript, JS, JSON
function objectToQuerystring (obj) {
return Object.keys.reduce(function (str, key, i) {
var delimiter, val;
delimiter = (i === 0) ? '?' : '&';
key = encodeURIComponent(key);
val = encodeURIComponent(obj[key]);
return [str, delimiter, key, '=', val].join('');
}, '');
}
@singhmohancs
singhmohancs / form-Auto-fill-Fix.directive.js
Created January 19, 2018 08:24
Fix autocomplete (autofill) form in Angular
angular.module('A').directive('formAutofillFix', function ($timeout) {
return function (scope, element, attrs) {
element.prop('method', 'post');
if (attrs.ngSubmit) {
$timeout(function () {
element
.unbind('submit')
.bind('submit', function (event) {
event.preventDefault();
element

##Change default Mac OS X PHP to XAMPP's PHP Installation and Install Composer

Find out what version of PHP is running

which php

This will output the path to the default PHP install which comes preinstalled by Mac OS X, by default

/**
* @ngDoc Directive
* @name app.Directive.onKeyEnter
* @module app
*
* @description
* this directive triggers callback function when enter key is pressed
*
* @author Mohan Singh <mslogicmaster@gmail.com>
*
@singhmohancs
singhmohancs / country-list.json
Created December 9, 2018 06:55
country list with dial code and iso2
[{
"name": "Afghanistan (‫افغانستان‬‎)",
"iso2": "af",
"dialCode": "93"
}, {
"name": "Albania (Shqipëri)",
"iso2": "al",
"dialCode": "355"
}, {
"name": "Algeria (‫الجزائر‬‎)",
@singhmohancs
singhmohancs / matchers.js
Created December 20, 2017 13:04 — forked from tomyam1/matchers.js
Custom matchers for Protractor and Jasmine 2
"use strict";
var _ = require('lodash');
/**
* Custom matchers for protractor and jasmine 2
*
* expect(el).toBePresent();
* expect(el).toBeDisplayed();
* expect(el).toContainText('text to contain');