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 / Parser.cs
Created October 7, 2016 11:20
Cron to Quartz parser
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WhoGroup.Schedulers
{
internal static class SchedulerHelper
{
@code-atom
code-atom / CancallationTokenExample.cs
Created October 17, 2016 12:29
How to use Cancellation Token thread in Order to cancel its execution.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Threading
{
class Program
@code-atom
code-atom / ScrollHandler.js
Created October 24, 2016 13:06
Best Practice of use Scroll event in application
var timer = null;
var scrollEvent = function () {
if(timer!=null)
clearTimeout(timer);
timer = setTimeout(function(){
console.log('hello');
}, 100);
}
@code-atom
code-atom / Promise.js
Created October 25, 2016 05:48
Define the Promise
var promise = function(){
return new Promise(function(resolve, reject) {
resolve(promise2('promise 1 Complete'));
});
}
var promise2 = function(value) {
return new Promise(function(resolve, reject) {
resolve(promise3('promise 2 Complete'));
});
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Series
{
public class SubMenuBuilder
{
@code-atom
code-atom / RND
Created November 15, 2016 07:01
Random number Generator for Sql
abs(checksum(NewId()) % 1000);
@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 / 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 / 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 / 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");