Skip to content

Instantly share code, notes, and snippets.

View mckabue's full-sized avatar

Kabui Charles mckabue

View GitHub Profile
@mckabue
mckabue / RequestResponseLoggingMiddleware.cs
Last active January 26, 2024 08:20
An ASP.NET CORE Request - Response Logger Middleware
using System;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Internal;
using Microsoft.IO;
// https://exceptionnotfound.net/using-middleware-to-log-requests-and-responses-in-asp-net-core/
// https://gist.github.com/elanderson/c50b2107de8ee2ed856353dfed9168a2
@mckabue
mckabue / C# Email Validator.cs
Created October 14, 2018 08:10
This handy extention validates email address with and without a display name. e.g: `Kabue Charles <me@mckabue.com>` and `me@mckabue.com`
/// <summary>
/// https://stackoverflow.com/a/1374644
/// </summary>
/// <param name="email"></param>
/// <returns></returns>
public static bool IsValidEmail(this string email)
{
try
{
var addr = new System.Net.Mail.MailAddress(email);
@mckabue
mckabue / C# Email Validator.cs
Created October 14, 2018 07:55
This handy extention validates email address with and without a display name. e.g: `Kabue Charles <me@mckabue.com>` and `me@mckabue.com`
/// <summary>
/// https://stackoverflow.com/a/1374644
/// </summary>
/// <param name="email"></param>
/// <returns></returns>
public static bool IsValidEmail(this string email)
{
try
{
var addr = new System.Net.Mail.MailAddress(email);
@mckabue
mckabue / JSON_to_URLEncoded.js
Created September 29, 2018 18:39 — forked from lastguest/JSON_to_URLEncoded.js
Convert JavaScript object to x-www-form-urlencoded format
function JSON_to_URLEncoded(element,key,list){
var list = list || [];
if(typeof(element)=='object'){
for (var idx in element)
JSON_to_URLEncoded(element[idx],key?key+'['+idx+']':idx,list);
} else {
list.push(key+'='+encodeURIComponent(element));
}
return list.join('&');
}
@mckabue
mckabue / reconfigure-virtualbox-dkms
Created September 6, 2018 08:33 — forked from kakoma/reconfigure-virtualbox-dkms
Reconfigure Ubuntu's virtualbox-DKMS after a kernel upgrade
#!/bin/bash
# Description: Everytime the Kernel is upgraded (which is quite often), virtualbox stops working and throws the following error:
#
# The provider 'virtualbox' that was requested to back the machine
# 'default' is reporting that it isn't usable on this system. The
# reason is shown below:
#
# VirtualBox is complaining that the installation is incomplete. Please
# run `VBoxManage --version` to see the error message which should contain
# instructions on how to fix this error.
@mckabue
mckabue / hide_broken_images_or_replace_then_gracefully.html
Last active June 20, 2018 06:57
Hide broken images, or replace then gracefully
<!-- https://stackoverflow.com/a/22051972 -->
<img src="Error.src" onerror="this.style.display='none'"/>
<img src="Error.src" onerror="this.src='fallback-img.jpg'"/>
@mckabue
mckabue / setting_minimum_and_maximum_CSS_values_for_font-size_padding_margin_and_may_more_not_just_height_and_width.scss
Last active June 20, 2018 06:56
Setting Minimum and maximum CSS values for `font-size`, `padding`, `margin`, and many more not just `height` and `width`
//
// https://stackoverflow.com/a/40530033
//
// ----
// libsass (v3.3.6)
// ----
// =========================================================================
//
// PRECISE CONTROL OVER RESPONSIVE TYPOGRAPHY FOR SASS
@mckabue
mckabue / visor-archivos-online.md
Created June 8, 2018 15:11 — forked from izazueta/visor-archivos-online.md
Google Docs Viewer & Office Web Apps Viewer

Google Docs Viewer

Only files under 25 MB can be previewed with the Google Drive viewer.

Google Drive viewer helps you preview over 16 different file types, listed below:

  • Image files (.JPEG, .PNG, .GIF, .TIFF, .BMP)
  • Video files (WebM, .MPEG4, .3GPP, .MOV, .AVI, .MPEGPS, .WMV, .FLV)
  • Text files (.TXT)
  • Markup/Code (.CSS, .HTML, .PHP, .C, .CPP, .H, .HPP, .JS)
  • Microsoft Word (.DOC and .DOCX)
@mckabue
mckabue / C#[Sharp]_Static_MineType_Detection.cs
Created June 8, 2018 14:20
C# Static MineType Detection
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
/// <summary>
/// https://github.com/samuelneff/MimeTypeMap/blob/master/src/MimeTypes/MimeTypeMap.cs
/// https://www.garykessler.net/library/file_sigs.html