Skip to content

Instantly share code, notes, and snippets.

View jglozano's full-sized avatar

Javier Lozano jglozano

View GitHub Profile
@jglozano
jglozano / server.txt
Created March 30, 2024 00:35
Server URL
https://drive.google.com/uc?export=download&id=1n7Ji3ca9V9PgSud36-QNR0fU44r95YKr
@jglozano
jglozano / Startup.cs
Created August 19, 2022 15:45
OWIN/Okta/SameSite Cookies
using Microsoft.Owin;
using Owin;
using Microsoft.Owin.Security;
using Microsoft.Owin.Security.Cookies;
using Microsoft.Owin.Security.OpenIdConnect;
using System.Threading.Tasks;
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
using System.Configuration;
using System.Security.Claims;
using IdentityModel.Client;
@jglozano
jglozano / Startup.cs
Created August 4, 2022 22:07
OWIN Middleware for X-FORWARDED- Headers
using Microsoft.Owin;
using Owin;
using System.Threading.Tasks;
[assembly: OwinStartup(typeof(OWINSample.Startup))]
namespace OWINSample
{
public class Startup
{
@jglozano
jglozano / Program.cs
Created August 4, 2022 21:30
ASP.NET Core X-FORWARDED- Headers
using Microsoft.AspNetCore.HttpOverrides;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddRazorPages();
// Configure the Forwarded Headers
builder.Services.Configure<ForwardedHeadersOptions>(options =>
{
@jglozano
jglozano / AccessFilter.cs
Created January 21, 2022 22:24
Reading Body from HttpRequest
// snippet around reading from HttpRequest.Body
var request = context.Request;
request.EnableBuffering();
// deserialize into temp structure using System.Text.Json.JsonSeralizer
var temp = await JsonSerializer.DeserializeAsync<RequestTemp>(request.Body,
options: new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
request.Body.Seek(0, SeekOrigin.Begin);
@jglozano
jglozano / TempFiles.sh
Created October 12, 2019 20:18
Git Refresh - Create Temp Files
for d in {1..6}; do touch "file${d}.md"; git add "file${d}.md"; git commit -m "adding file ${d}"; done
@jglozano
jglozano / git_lol_alias.md
Last active August 30, 2018 21:21
Git log oneline with a pretty graph

The following alias, lol creates a clean, reable graph of the commits using the git log command as the base:

git config --global alias.lol 'log --oneline --graph --decorate --all'

@jglozano
jglozano / GetNextIdAsync.cs
Created March 2, 2018 16:07
Get Next ID from Sequence / StoredProc
public async Task<int> GetNextIdAsync()
{
using (var connection = GetDbConnection())
{
connection.Open();
var parameters = new DynamicParameters();
parameters.Add("@nextId", dbType: DbType.Int32, direction: ParameterDirection.ReturnValue);
await connection.ExecuteAsync("[Schema].[sp_GetNextId]", parameters, commandType: CommandType.StoredProcedure).ConfigureAwait(false);
var result = parameters.Get<int>("@nextId");
@jglozano
jglozano / ConfigCorsPolicyProvider.cs
Created February 12, 2018 16:26
Configuration CORS Policy Provider
public class ConfigCorsPolicyProvider : ICorsPolicyProvider
{
private readonly IConfigurationService configurationService;
public ConfigCorsPolicyProvider(IConfigurationService configurationService)
{
this.configurationService = configurationService;
}
public Task<CorsPolicy> GetCorsPolicyAsync(HttpRequestMessage request, CancellationToken cancellationToken)
@jglozano
jglozano / BrowserJsonFormatter.cs
Created February 12, 2018 15:20
Browser JSON Formatter
public class BrowserJsonFormatter : JsonMediaTypeFormatter
{
public BrowserJsonFormatter()
{
SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));
SerializerSettings.Formatting = Formatting.Indented;
}
public override void SetDefaultContentHeaders(Type type, HttpContentHeaders headers, MediaTypeHeaderValue mediaType)
{