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
/**
* Calculates numbers to the mathmatical power (exponent)
*
* @since 1.0.0
*
* @param int $number The number to increase
* @param int $exponent The power to increase the number by
*
* @return int The new number
*/
@singhmohancs
singhmohancs / viewport-units-ios.scss
Created August 10, 2017 16:22 — forked from BenMorel/viewport-units-ios.scss
SCSS mixin to support vh and vw units on all iOS Safari versions. Based on an idea by Patrick Burtchaell's: https://gist.github.com/pburtchaell/e702f441ba9b3f76f587
/**
* Fix for vw, vh, vmin, vmax on iOS 7.
* http://caniuse.com/#feat=viewport-units
*
* This fix works by replacing viewport units with px values on known screen sizes.
*
* iPhone 6 and 6 Plus cannot run iOS 7, so are not targeted by this fix.
* Target devices running iOS 8+ will incidentally execute the media query,
* but this will still produce the expected result; so this is not a problem.
@singhmohancs
singhmohancs / utc-to-local.js
Created July 22, 2017 21:03 — forked from fntneves/utc.js
Moment.JS - Convert UTC to Local Time
$.fn.format = function() {
return this.each(function() {
var $this = $(this);
var time = $this.attr("datetime");
var localTime = moment.utc(time).local().format();
$this.attr("datetime", localTime).timeago();
return this;
});
@singhmohancs
singhmohancs / countries.json
Last active September 28, 2017 09:16 — forked from keeguon/countries.json
A list of countries in JSON
[
{ "name": "Afghanistan", "code": "AF" },
{ "name": "Åland Islands", "code": "AX" },
{ "name": "Albania", "code": "AL" },
{ "name": "Algeria", "code": "DZ" },
{ "name": "American Samoa", "code": "AS" },
{ "name": "Andorra", "code": "AD" },
{ "name": "Angola", "code": "AO" },
{ "name": "Anguilla", "code": "AI" },
{ "name": "Antarctica", "code": "AQ" },
@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 / template.html
Last active September 28, 2017 09:16
AngularJS - UTC to Local + Filter
<span>Local date & time converted from UTC: {{vm.myUtcDate | utcToLocal:'dd.MM.yy - hh.mm a'}}</span>
<!-- Where vm.myUtcLocal = '2016-03-31T00:11:31' (utc) -->
@singhmohancs
singhmohancs / filter.js
Created May 14, 2017 16:02
AngularJS - Slugify Filter
(function () {
'use strict';
angular
.module('app')
.filter('slugify', Filter);
function Filter() {
return function (input) {
if (!input)
@singhmohancs
singhmohancs / angular-focus.js
Created May 7, 2017 05:20
AngularJs Focus Directive
angular.directive('autoFocus', function(){
return function(scope, element){
element[0].focus();
};
});
/*
<div>
<input type="text" auto-focus />
@singhmohancs
singhmohancs / wrap-text.css
Created May 3, 2017 16:31
Wrap long words & Urls
/* These are technically the same, but use both */
overflow-wrap: break-word;
word-wrap: break-word;
-ms-word-break: break-all;
/* This is the dangerous one in WebKit, as it breaks things wherever */
word-break: break-all;
/* Instead use this non-standard one: */
word-break: break-word;