Skip to content

Instantly share code, notes, and snippets.

View mykeels's full-sized avatar
😄
faffing!

Michael Ikechi mykeels

😄
faffing!
View GitHub Profile
@mykeels
mykeels / cast.php
Last active February 5, 2018 15:20
Cast an associative array or object in PHP to an instance of a class (uses a Laravel helper method)
<?php
function cast($object, $class) {
if( !is_object($object) )
throw new InvalidArgumentException('$object must be an object.');
if( !is_string($class) )
throw new InvalidArgumentException('$class must be a string.');
if( !class_exists($class) )
throw new InvalidArgumentException(sprintf('Unknown class: %s.', $class));
$ret = app($class);
@mykeels
mykeels / README.md
Last active October 1, 2018 00:59
Kill Apache Service on Mac - bind() to 0.0.0.0:80 failed (48: Address already in use)

To find out the program interfering with port 80 on Mac,

sudo lsof -i:80

If it's httpd it's the Apache Service, so use the command in kill-apache.sh in your terminal to shut it down, then valet restart

If you get a 404, try valet link in your app directory.

@mykeels
mykeels / FriendsContainer.js
Last active October 6, 2017 14:25
The ultimate explanation for React's component lifecycle event handlers from https://tylermcginnis.com/reactjs-tutorial-a-comprehensive-guide-to-building-apps-with-react/
var FriendsContainer = React.createClass({
getInitialState: function(){
alert('In getInitialState');
return {
name: 'Tyler McGinnis'
}
},
// Invoked once before first render
componentWillMount: function(){
// Calling setState here does not cause a re-render
@mykeels
mykeels / README.md
Last active August 25, 2017 15:31
A Simple Sort challenge

Write a program in any language of your choice that has a function that sorts the json data by Name in alphabetical order and Age and returns the result.

E.g.

  function sortData(arr) {
    // ... do stuff to sort the array
    return arr;
  }
@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
@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 / 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 / NotificationHandler.md
Last active January 28, 2021 19:22
A notification system for ASP.NET MVC applications

AlertHandler

I'll go straight to the point ... sometimes, you have to notify a user of something on the following web page. What I used to do:

TempData["Notification"] = "You have succesfully logged in"; //c# code
@if (TempData["Notification"]) {
@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.