Skip to content

Instantly share code, notes, and snippets.

View code-atom's full-sized avatar
🏠
Working from home

Ankit Rana code-atom

🏠
Working from home
View GitHub Profile
@code-atom
code-atom / IpAddressToLocation.cs
Created February 22, 2017 09:45
Find the IPAddress to Location
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Net;
using System.Text;
using System.Threading.Tasks;
"use strict";
const { addObserver, notifyObservers } = Cc["@mozilla.org/observer-service;1"].
getService(Ci.nsIObserverService);
const { getEnumerator } = Cc["@mozilla.org/appshell/window-mediator;1"].
getService(Ci.nsIWindowMediator);
const isBrowser = window => {
try {
return window.document.documentElement.getAttribute("windowtype") === "navigator:browser";
using System.IO;
using System.Net;
using System.Text.RegularExpressions;
using ClassLibraries.SiteSettings.Classes;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
@code-atom
code-atom / MultipleNestingPromise.js
Created January 19, 2017 11:02
Understand the nested promise
var app = angular.module('app',[]);
app.run(function ($http, $q) {
getExample($q)
.then(function(value){
console.log(value);
});
})
function getExample($q) {
@code-atom
code-atom / Promise.js
Created January 17, 2017 11:39
Understand how promise work and execute in javascript
app.run(function ($http, $q) {
var promise = $q.when('i m resolved');
promise.then(function(value){
console.log(value + " 1");
});
var innerPromise = promise.then(function(value){
console.log(value + " 2");
})
var innerPromise2 = promise.then(function(value){
console.log(value + " 3");
@code-atom
code-atom / SSLExpirationCheck.cs
Created January 6, 2017 04:33
Check when SSL get expire.
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://mail.google.com");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
response.Close();
//retrieve the ssl cert and assign it to an X509Certificate object
X509Certificate cert = request.ServicePoint.Certificate;
//convert the X509Certificate to an X509Certificate2 object by passing it into the constructor
X509Certificate2 cert2 = new X509Certificate2(cert);
@code-atom
code-atom / MultipleNameBindOfParameter.cs
Created December 12, 2016 11:38
Bind value of action parameter with multiple name specify in list
[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)]
public class MultipleNameBindAttribute : Attribute
{
public MultipleNameBindAttribute(string parameters)
{
if (!String.IsNullOrEmpty(parameters))
{
AvailableName = parameters.Split(',');
}
}
@code-atom
code-atom / FakeDbSet.cs
Last active November 30, 2016 05:04
Create Fake DbSet from Moq Framework
public class Utility
{
public static Mock<DbSet<TEntity>> GenerateMockEntity<TEntity>(List<TEntity> entityList) where TEntity : class
{
var list = new List<TEntity>();
list.AddRange(entityList);
var query = list.AsQueryable();
var entityMockSet = new Mock<DbSet<TEntity>>() { CallBase = true};
entityMockSet.As<IQueryable<TEntity>>().Setup(m => m.Provider).Returns(query.Provider);
entityMockSet.As<IQueryable<TEntity>>().Setup(m => m.Expression).Returns(query.Expression);
@code-atom
code-atom / RND
Created November 15, 2016 07:01
Random number Generator for Sql
abs(checksum(NewId()) % 1000);
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Series
{
public class SubMenuBuilder
{