Skip to content

Instantly share code, notes, and snippets.

View mykeels's full-sized avatar
😄
faffing!

Ikechi Michael mykeels

😄
faffing!
View GitHub Profile
@mykeels
mykeels / README.md
Last active December 18, 2016 15:31
Easy way to work with `System.Web.Caching` when building .NET C# Web Applications

While Caching in .NET is a thing of beauty, using it can be a bit cumbersome, and makes my code look clunky. I'm talking about usage like:

  if (Cache.Get("myKey") == null) {
    Cache.Insert("myKey", getValue());
    return Cache.Get("myKey");
  }

The class in Cache.cs contains helper methods that make this much easier and cleaner to do

@mykeels
mykeels / WorkHourInfo.cs
Created January 12, 2017 12:02
WorkHourInfo can take strings as parameters, and handle datetime too.
public class WorkHourInfo
{
public string dayOfWeek { get; set; }
public DateTime? startTime { get; set; }
public DateTime? endTime { get; set; }
public string start
{
get
{
return startTime == null ? "closed" : Convert.ToDateTime(startTime).ToShortTimeString();
@mykeels
mykeels / get-depth.js
Created January 19, 2017 14:51
Breadth-First Search to get Tree Depth
//pseudocode
function Node() {
this.children = [];
var me = this;
this.hasChildren = function () {
return me.children.length > 0;
}
}
function getDepth(node, count, max) {
@mykeels
mykeels / README.md
Last active January 20, 2017 09:10
Tree with auto-get-depth

Tree with Automatic Get-Depth

Meant for very large tree-sets, yea? This tree is aimed at implementing an idea that the depth of a tree can be known from the root-node without a breadth-first or depth-first search.

Every time a node is updated on the tree, it increases the depth-count of its parent, which also increases the depth count of its parent in a recursive manner, so the depth of the entire tree is always known from the root-node.

Ofcourse, this is only a prototype, and i'll be happy to accept notes on improving the algorithm.

Notes for Improvement

  • For now, nodes are only added and not removed.
@mykeels
mykeels / hill-climb-sphere-fn.js
Last active February 2, 2017 11:39
Hill-Climbing Algorithm implementation for the sphere function
//every metaheuristic needs ->
// - solution initialization function (must generate a random solution everytime)
// - fitness function
// - mutation function
// - clone function
function hillClimb() {
var sol1 = getRandomSolution(5);
var fit1 = getFitness(sol1);
for (var i = 1; i <= 1000; i++) {
@mykeels
mykeels / HttpResponseCodes.cs
Last active March 17, 2017 08:30
Http Response Status Codes in JSON, JavaScript, CSharp, (feel free to add yours), etc.
public enum STATUS_CODES {
OK = 200,
CREATED = 201,
ACCEPTED = 202,
NON_AUTHORITATIVE_INFORMATION = 203,
NO_CONTENT = 204,
RESET_CONTENT = 205,
PARTIAL_CONTENT = 206,
MULTIPLE_CHOICE = 300,
MOVED_PERMANENTLY = 301,
@mykeels
mykeels / JwtToken.md
Created June 4, 2017 16:48
A JWT Token Handler wrapper class for .NET

Json Web Tokens in .NET

A handler for JWT Authentication in .NET

@mykeels
mykeels / _default-image.md
Last active July 7, 2017 05:16
Specify Default Images in Javascript

Default Image Script

Specify Default Images for your <img> tags to be loaded when their images fail to load.

How to use

Simply place the script in default-src.js at the bottom of your page.

@mykeels
mykeels / GraphQLFormatter.cs
Last active July 8, 2017 22:10
ASP.NET WebAPI Custom Formatter for GraphQL Syntax
using System;
using System.Net.Http.Headers;
using System.Net.Http.Formatting;
using System.IO;
using System.Threading;
using System.Net.Http;
using GraphQL;
using GraphQL.Types;
namespace GraphQLWebAPI.Formatters
@mykeels
mykeels / clarg.md
Created July 28, 2017 15:15 — forked from pksunkara/clarg.md
Command Line Arguments Specification

Command Line Arguments Specification

This specification defines Command Line Arguments level 1 (CLARG 1.0). This document aims to direct development of command line tools conform to a set of rules while parsing options.

Arguments

The different type of arguments are:

  • Short Option
  • Long Option