Skip to content

Instantly share code, notes, and snippets.

@singhmohancs
singhmohancs / AngularJS-Cachebusting.js
Created November 30, 2016 19:25 — forked from ProLoser/AngularJS-Cachebusting.js
Elegant cache-busting for AngularJS HTML assets
anglar.module('myApp',['ui']).config(["$provide", function($provide) {
return $provide.decorator("$http", ["$delegate", function($delegate) {
var get = $delegate.get;
$delegate.get = function(url, config) {
// Check is to avoid breaking AngularUI ui-bootstrap-tpls.js: "template/accordion/accordion-group.html"
if (!~url.indexOf('template/')) {
// Append ?v=[cacheBustVersion] to url
url += (url.indexOf("?") === -1 ? "?" : "&");
url += "v=" + cacheBustVersion;
}
@singhmohancs
singhmohancs / default.value.directive.js
Created January 27, 2017 09:32
Toggle default value on focus and blur on text field
/**
* @ngdoc Directive
* @name defaultValue
* @restrict 'A'
* @element ANY
* @author Mohan Singh ( gmail::mslogicmaster@gmail.com, skype :: mohan.singh42 )
**/
(function () {
'use strict';
angular
@singhmohancs
singhmohancs / detectDevice.directive.js
Last active March 3, 2017 18:18
Determine device type from container width
/**
* @ngdoc Directive
* @name app.directive.detectViewPort
* @module app
*
* @description
* detectViewPort staring component with star
* @TODO
* onDetectViewPort callback
* @author Mohan Singh ( gmail::mslogicmaster@gmail.com, skype :: mohan.singh42 )
/* Checks if localStorage exists on the browser, if not, creates a JSONFallbackStorage object where all the data will be stored. Also creates the localStorage methods so you won't need to change anything on your script. Just remember to send the data on JSONFallbackStore to the server. */
(function(window, undefined){
if (typeof(localStorage) === undefined) {
JSONFallbackStore = {};
window.localStorage = {
getItem: function(key){
return JSONFallbackStore[key];
},
setItem: function(key, value){
@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;
@sunilmadaan07
sunilmadaan07 / bind.js
Last active July 11, 2017 07:05
bind, call and apply in javascript (brief description of bind, apply and call in javascript)
//@bind, apply, call in javascript
//@description
//@Question: If you want to use an arbitrary object as value of this, how will you do that?
/***********
Answer: There are at least three different ways to doing this by using bind, call and apply.
For example, I have a method named deductMontlyFee in the object monika
and by default value of this would be monika inside the method.
************/
/***********
If I bind the deductMontlyFee of monika with another object vikas
@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 />