Skip to content

Instantly share code, notes, and snippets.

View McKabue's full-sized avatar

Kabue Charles McKabue

View GitHub Profile
@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 / 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 / C# Pager On IEnumerable.cs
Last active September 24, 2018 12:15
C# Pager On IEnumerable
using System;
using System.Collections.Generic;
using System.Linq;
public static class Pager
{
/// <summary>
/// Pages the specified items.
@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 / 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 / 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 / clearRAM.sh
Created January 14, 2019 08:07 — forked from pklaus/clearRAM.sh
A Script to Clear Cached RAM on Linux
#!/bin/bash
## Bash Script to clear cached memory on (Ubuntu/Debian) Linux
## By Philipp Klaus
## see <http://blog.philippklaus.de/2011/02/clear-cached-memory-on-ubuntu/>
if [ "$(whoami)" != "root" ]
then
echo "You have to run this script as Superuser!"
exit 1
fi
@McKabue
McKabue / flush-dns.sh
Created March 27, 2019 05:09 — forked from craigvantonder/flush-dns.sh
Flushing the DNS in Ubuntu 16.04
#!/bin/bash
# NB: First install nscd with sudo apt-get install nscd
# run this command to flush dns cache:
sudo /etc/init.d/dns-clean restart
# or use:
sudo /etc/init.d/networking force-reload
# Flush nscd dns cache:
sudo /etc/init.d/nscd restart