Skip to content

Instantly share code, notes, and snippets.

View McKabue's full-sized avatar

Kabue Charles McKabue

View GitHub Profile
@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
@McKabue
McKabue / ERROR.js
Last active April 16, 2024 13:20
Handling JavaScript Errors Like a boss by logging them to the server and possibly returning a behavior. WE THEN MAKE A REQUEST TO YOUR SERVERS AS IF YOU ARE LOADING A JAVASCRIPT FILE. THE URL WILL CONTAIN THE QUERY PARAMETERS THAT YOU WANT TO PASS TWO THE SERVER. THIS METHOD HAS TO ADVANTAGES: 1. THE CODE FOR SENDING THE REQUEST IS SIMPLE AS WE …
//https://developer.mozilla.org/en/docs/Web/API/GlobalEventHandlers/onerror
//https://blog.sentry.io/2016/01/04/client-javascript-reporting-window-onerror.html
//https://danlimerick.wordpress.com/2014/01/18/how-to-catch-javascript-errors-with-window-onerror-even-on-chrome-and-firefox/
window.onerror = function (messageOrEvent, source, lineno, colno, error) {
try {
console.log({
//error message(string).Available as event (sic!) in HTML onerror = "" handler.
messageOrEvent: messageOrEvent,
//URL of the script where the error was raised(string)
@McKabue
McKabue / HeidiDecode.js
Created May 31, 2018 21:17 — forked from jpatters/HeidiDecode.js
Decodes a password from HeidiSQL. HeidiSQL passwords can be found in the registry. Use File -> Export Settings to dump all settings. Great for if you forget a password.
function heidiDecode(hex) {
var str = '';
var shift = parseInt(hex.substr(-1));
hex = hex.substr(0, hex.length - 1);
for (var i = 0; i < hex.length; i += 2)
str += String.fromCharCode(parseInt(hex.substr(i, 2), 16) - shift);
return str;
}
document.write(heidiDecode('755A5A585C3D8141786B3C385E3A393'));