Skip to content

Instantly share code, notes, and snippets.

View morbidcamel101's full-sized avatar
🎯
Focusing

MorbidCamel morbidcamel101

🎯
Focusing
View GitHub Profile
@morbidcamel101
morbidcamel101 / SumOfDigits.cs
Created January 10, 2017 22:00
Sum of Digits
sum = 0;
while (n != 0) {
sum += n % 10;
n /= 10;
}
@morbidcamel101
morbidcamel101 / throttle.js
Created November 2, 2016 06:39
Generic Throttling mecanism in Javascript
function throttle(f, delay)
{
var timer = null;
return function () {
var context = this, args = arguments;
clearTimeout(timer);
timer = window.setTimeout(function () {
f.apply(context, args);
},
delay || 500);
@morbidcamel101
morbidcamel101 / getformobj.js
Created October 30, 2016 09:41
Get Form Object in JQuery (with checkboxes!)
function getFormObj($form) {
var formObj = {};
var inputs = $form.serializeArray();
inputs = inputs.concat(
$form.find('input[type=checkbox]').map(
function () {
return { "name": this.name, "value": this.value }
}).get());
$.each(inputs, function (i, input) {
@morbidcamel101
morbidcamel101 / OverrideWindowAlert.css
Last active May 18, 2021 08:22
Override window.alert with custom dialog JQuery
.overlay {
display: none;
position: fixed;
left: 0;
top: 0;
width: 100%;
height: 100%;
text-align:center;
z-index: 200;
background-color: rgba(0,0,0,0.5);
@morbidcamel101
morbidcamel101 / MoveElements.js
Last active September 2, 2016 06:34
Move an element up and down - JS
$(function()
{
$(document).on('click', '.btn-move-up',
function (e) {
e.preventDefault();
moveUp($(this).closest('.tile-list'), $(this).closest('.showcase'));
updateMoveState();
});
$(document).on('click', '.btn-move-down',
@morbidcamel101
morbidcamel101 / ExtractWikipediaTable.js
Created August 31, 2016 03:03
Extract a WikiPedia table using the Chrome Developer Console
// Will extract the contents of a table in wikipedia into JSON
JSON.stringify($('table.sortable tr').map(function() {
return new Array($('td', this).map(function() {
return $(this).text()
}).slice(2, 5).get())
}).get())
@morbidcamel101
morbidcamel101 / ConvertUtil.cs
Created August 29, 2016 03:13
Common Conversion Extensions
public static class ConvertUtil
{
#region GetDefaultValue
/// <summary>
/// Initialize a value based on a type reference if the value specified is <c>null</c>.
/// </summary>
/// <param name="value">An object value to initialize. If it's not null the value is returned.</param>
/// <param name="type">Type to use as a reference to initialize the value.</param>
/// <returns>The "initialized" version of the value if it was <c>null</c> or the original value if it was not.</returns>
public static object GetDefaultValue(Type type)
@morbidcamel101
morbidcamel101 / ReflectionUtil.cs
Last active February 3, 2017 14:57
Common reflection extensions
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Web;
namespace GCFinder.Models
{
public static class ReflectionUtil
{
@morbidcamel101
morbidcamel101 / HexStringConversiond.cs
Created March 15, 2016 18:42
Converting Hex Strings
private static byte[] HexStringToByteArray(string input) {
byte[] Bytes;
int ByteLength;
string HexValue = "\x0\x1\x2\x3\x4\x5\x6\x7\x8\x9|||||||\xA\xB\xC\xD\xE\xF";
ByteLength = input.Length / 2;
var queryParameters = {}, queryString = location.search.substring(1), re = /([^&=]+)=([^&]*)/g, m;
while (m = re.exec(queryString)) {
queryParameters[decodeURIComponent(m[1])] = decodeURIComponent(m[2]);
}
queryParameters['division'] = divisionId;
location.search = $.param(queryParameters);