Skip to content

Instantly share code, notes, and snippets.

View abhishekbhalani's full-sized avatar
🎄
working on latest framework...

Abhishek B. abhishekbhalani

🎄
working on latest framework...
View GitHub Profile
@DalSoft
DalSoft / DalSoftDbContext.cs
Last active March 12, 2018 07:41
Entity Framework Core Migrations and Seeding
using System;
using System.IO;
using System.Linq.Expressions;
using System.Reflection;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.Extensions.Configuration;
namespace DalSoft.Data
@regisdiogo
regisdiogo / Startup.cs
Last active May 5, 2025 09:51
ASP.NET Core - Json serializer settings Enum as string and ignore null values
public class Startup
{
public IServiceProvider ConfigureServices(IServiceCollection services)
{
services.AddMvc().AddJsonOptions(options =>
{
options.SerializerSettings.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter());
options.SerializerSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore;
});
}
@guitarrapc
guitarrapc / ELBv2Sample.cs
Last active March 11, 2022 12:32
Amazon Application Elastic Load Balancing (ELB v2) C# Sample with HTTPS -> HTTP (HTTPS by ACM Certificate)
using Amazon.CertificateManager
using Amazon.EC2
using Amazon.ElasticLoadBalancingV2
using Amazon.ElasticLoadBalancingV2.Model
using System.Net.Http
using System.Threading.Tasks
using System.Windows.Forms.DataVisualization.Charting
public class Program
{
@Teivaz
Teivaz / gdrive.js
Last active September 1, 2023 18:03
Google Drive API V3 simple but working use case.
'use strict';
const driveUploadPath = 'https://www.googleapis.com/upload/drive/v3/files';
// 'id' is driveId - unique file id on google drive
// 'version' is driveVersion - version of file on google drive
// 'name' name of the file on google drive
// 'appProperties' keep the custom `ifid` field
const fileFields = 'id,version,name,appProperties';
// Filter
public class CorsFilter : ActionFilterAttribute
{
public override void OnActionExecuted(ActionExecutedContext filterContext)
{
base.OnActionExecuted(filterContext);
var response = filterContext.RequestContext.HttpContext.Response;
// Add header to response
response.AddHeader("Access-Control-Allow-Origin", "*");
// OLD CODE WITH INLINE REMARKS
public class TestController : Controller
{
[HttpOptions]
public ActionResult Xlsx()
{
// Catches and authorises pre-flight requests for /data/xlsx from remote domains
// Remark: Don't touch Response / Request object directly inside the Controller
Response.AddHeader("Access-Control-Allow-Origin", "*");
@btroncone
btroncone / authentication.ts
Last active April 10, 2022 06:44
Angular 2 application role access decorator, wrapping built in CanAccess functionality. Prevents view transitions when user roles are not appropriate.
import { Injectable } from 'angular2/core';
import { Storage } from './storage';
import { CurrentUser } from '../interfaces/common';
@Injectable()
export class Authentication{
private _storageService : Storage;
private _userKey : string = "CURRENT_USER";
constructor(storageService : Storage){
@objarni
objarni / Install Gulp.txt
Last active January 16, 2023 13:30
Installing gulp in Windows
1. Install nodejs. https://nodejs.org/en/
2. Check npm (node package manager) is installed via command prompt:
$ npm
3. Install gulp:
$ npm install gulp --global
4. In relevant project folder, create 'gulpfile.js':
@herman1vdb
herman1vdb / MinifyHtmlAttribute.cs
Last active May 7, 2020 07:22
Minify HTML with inline css/javascript for MVC C# as a ActionFilterAttribute
using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
using System.Web.Optimization;
using ZetaProducerHtmlCompressor.Internal;
namespace PmdWebsite.Helpers.ActionFilters
@ptsurbeleu
ptsurbeleu / example.cs
Created October 6, 2015 18:31
How to decode JWT token
// NOTE: For that code to work, you need install System.IdentityModel.Tokens.Jwt package from NuGet (the link includes the latest stable version)
// Link: https://www.nuget.org/packages/System.IdentityModel.Tokens.Jwt/4.0.2.206221351
using System.IdentityModel.Tokens;
// a sample jwt encoded token string which is supposed to be extracted from 'Authorization' HTTP header in your Web Api controller
var tokenString = "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6Ik1uQ19WWmNBVGZNNXBPWWlKSE1iYTlnb0VLWSJ9.eyJhdWQiOiIwMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAwMDAiLCJpc3MiOiJodHRwczovL3N0cy53aW5kb3dzLm5ldC8wMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAwMDAiLCJpYXQiOiIxNDI4MDM2NTM5IiwibmJmIjoiMTQyODAzNjUzOSIsImV4cCI6IjE0MjgwNDA0MzkiLCJ2ZXIiOiIxLjAiLCJ0aWQiOiIwMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAwMDAiLCJhbXIiOiJwd2QiLCJvaWQiOiIwMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAwMDAiLCJlbWFpbCI6Impkb2VAbGl2ZS5jb20iLCJwdWlkIjoiSm9obiBEb2UiLCJpZHAiOiJsaXZlLmNvbSIsImFsdHNlY2lkIjoiMTpsaXZlLmNvbTowMDAwMDAwMDAwMDAwMDAw