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 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 / 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 / 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 February 19, 2018 09:06
Regex for Find & Replace in JavaScript Webpack Code Splitting

Regex for Find & Replace to convert

import MyComponent from './my-component'

to

const MyComponent = () =&gt; import(/* webpackChunkName: "chunk" */ './my-component')
@mykeels
mykeels / ApiClient.cs
Last active February 28, 2018 14:23
A helper class for working with most API requests
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Diagnostics;
using Newtonsoft.Json;
using System.Text;
@mykeels
mykeels / introrx.md
Created March 1, 2018 14:37 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing
@mykeels
mykeels / Makefile
Created March 3, 2018 15:26
Build S.I.M.P.L.E for macOS
# to be placed in ./bootsrc/sources of https://github.com/simple-lang/simple
program_NAME := simple
program_C_SRCS := $(wildcard *.c)
program_CXX_SRCS := $(wildcard *.cpp)
program_C_OBJS := ${program_C_SRCS:.c=.o}
program_CXX_OBJS := ${program_CXX_SRCS:.cpp=.o}
program_OBJS := $(program_C_OBJS) $(program_CXX_OBJS)
program_INCLUDE_DIRS :=
program_LIBRARY_DIRS :=
const express = require('express')
const isPrime = require('./is-prime')
const app = express()
app.get('/', (req, res) => {
const primes = []
const max = Number(req.query.max) || 1000
for (let i = 1; i <= max; i++) {
if (isPrime(i)) primes.push(i)
}
@mykeels
mykeels / index.js
Created April 4, 2018 09:13
Fork of index.js in https://gist.github.com/mykeels/8396f87d42a809697d08f6b6c9cd8db0 showing how clusters can be used
const cluster = require('cluster')
const os = require('os')
const express = require('express')
const isPrime = require('./is-prime')
if (cluster.isMaster) {
const cpuCount = os.cpus().length
for (let i = 0; i < cpuCount; i++) {
cluster.fork()
}