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 / 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>
/*
C# Generic Enum Parser With Extension Methods
Code Snippet By: Pinal Bhatt [www.PBDesk.com]
*/
public static class EnumUtils
{
#region String to Enum
/*
C# Generic String Parser Extension Method
Code Snippet By: Pinal Bhatt [www.PBDesk.com]
http://blogs.pbdesk.com/c-generic-string-parser-extension-method/
Working Example at http://ideone.com/ZP5xo
Usage:
string s = "32";
int i = s.As<int>();
*/
@pinalbhatt
pinalbhatt / rename git branch locally and remotely
Last active August 29, 2015 14:12 — forked from lttlrck/gist:9628955
Rename git branch locally and remotely
git branch -m old_branch new_branch # Rename branch locally
git push origin :old_branch # Delete the old branch
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote
#Set of commands i use to rename feature/15.0 to feature/SignupRefactor locally and remotely
#rename local feature/15.0 to feature/SignupRefactor
git branch -m feature/15.0 feature/SignupRefactor
#delete remote feature/15.0
@pinalbhatt
pinalbhatt / gist:2fc114f817a1d294e6ea
Last active September 12, 2015 01:36 — forked from cakebaker/gist:823574
Nicer interface for removing query string params with Node.js
var urlLib = require('url');
function UrlAdapter(urlString) {
this.urlObj = urlLib.parse(urlString, true);
// XXX remove the search property to force format() to use the query object when transforming the url object to a string
delete this.urlObj.search;
}
exports.UrlAdapter = UrlAdapter;