Skip to content

Instantly share code, notes, and snippets.

View pinalbhatt's full-sized avatar
💭
from the desk of Pinal Bhatt

Pinal Bhatt pinalbhatt

💭
from the desk of Pinal Bhatt
View GitHub Profile
/*
Javascript
ResolveReferences - To resolve references in JSON object with circular references.
*/
function ResolveReferences(json) {
if (typeof json === 'string')
json = JSON.parse(json);
var byid = {}, // all objects by id
refs = []; // references to objects that could not be resolved
@pinalbhatt
pinalbhatt / Javascript isNumeric
Last active November 14, 2020 22:00
Javascript isNumeric() function
/*
isNumeric function in Javascript
*/
function isNumeric(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
}
@pinalbhatt
pinalbhatt / Multi-Line JavaScript Strings
Last active August 29, 2015 13:57
Multi-Line JavaScript Strings
var multiStr = "This is the first line" +
"This is the second line" +
"This is more...";
//Alternate way to create multiline strings
var multiStr = "This is the first line \
This is the second line \
This is more...";
@pinalbhatt
pinalbhatt / JSDefaultParamaterValue
Created April 19, 2014 11:44
Javascript Function with default parameter value
function foo(age, isValid)
{
a = typeof a !== 'undefined' ? a : 18;
b = typeof b !== 'undefined' ? b : false;
/*
rest function body here
*/
}
@pinalbhatt
pinalbhatt / RandomNumber
Created July 23, 2014 21:12
Javascript: Random Number between two integers
/*
Javascript: Random Number between two integers
http://blogs.pbdesk.com/javascript-random-number-between-two-integers/
*/
function randomFromTo(from, to){
return Math.floor(Math.random() * (to - from + 1) + from);
}
//Invocation:
@pinalbhatt
pinalbhatt / Clone
Last active August 29, 2015 14:04
Clone Object in Javascript
/*
Clone Object in Javascript
*/
function Clone(obj) {
// Handle the 3 simple types, and null or undefined
if (null == obj || "object" != typeof obj) return obj;
// Handle Date
if (obj instanceof Date) {
var copy = new Date();
@pinalbhatt
pinalbhatt / DeepCompare
Created August 3, 2014 13:20
DeepCompare() // Usage: DeepCompare(obj1, obj2) // Usage: DeepCompare(obj1, obj2, obj3)
function DeepCompare() {
var leftChain, rightChain;
function compare2Objects(x, y) {
var p;
// remember that NaN === NaN returns false
// and isNaN(undefined) returns true
if (isNaN(x) && isNaN(y) && typeof x === 'number' && typeof y === 'number') {
return true;
@pinalbhatt
pinalbhatt / ReadingQueryStringWithJavaScript
Last active August 29, 2015 14:04
Reading Query String with JavaScript
/*
Javascript function to read QueryString parameters.
More details bloged at http://blog.pbdesk.com/2008/11/reading-query-string-with-javascript.html
JSFiddle: http://jsfiddle.net/PinalBhatt/sBkur/
*/
function GetQueryStringValue(parameterName) {
var objQRs = new Object();
window.location.search.replace(new RegExp("([^?=&]+)(=([^&]*))?", "g"),
@pinalbhatt
pinalbhatt / DynamicObjectNestedMemberCall.cs
Created August 3, 2014 13:26
C# Dynamic Object Nested Member Call
using System;
using System.Dynamic;
namespace WW.COM.Framework.WWConfiguration
{
public class EnvSettings : DynamicObject
{
private string Category { get; set; }
public EnvSettings()
{
/*
C# Some Handy String Extension Methods
Code Snippet By: Pinal Bhatt [www.PBDesk.com]
*/
using System;
public static class StringExtensions
{
/// <summary>