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 / modalAside.css
Created April 5, 2017 15:12
Open modal as Aside - on Left , Right
/*******************************
* MODAL AS LEFT/RIGHT SIDEBAR
* Add "left" or "right" in modal parent div, after class="modal".
* Get free snippets on bootpen.com
*******************************/
.modal.left .modal-dialog,
.modal.right .modal-dialog {
position: fixed;
margin: auto;
@singhmohancs
singhmohancs / client.html
Created April 12, 2017 09:54 — forked from agrueneberg/client.html
HMAC-SHA256 example for verifying both the data integrity and the authentication of a request in Node.js and web browsers.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>HMAC-SHA256 Example</title>
</head>
<body>
<script src="http://crypto.stanford.edu/sjcl/sjcl.js"></script>
<script>
var sharedSecret, query, signature, hmac, xhr;
@singhmohancs
singhmohancs / uploadFile.js
Created April 28, 2017 19:33
Upload file in angularJs
$resource('/path/to/api/resource', null, {
upload: {
method: 'POST',
headers: { 'Content-Type': undefined },
transformRequest: function (data) {
var formData = new FormData();
formData.append("data", angular.toJson(data.model));
angular.forEach(data.files, function (fileData) {
@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;
@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 / 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 / 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 / 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 / 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 / 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" },