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 / SampleMigration.php
Last active April 17, 2018 09:49
A sample laravel model
<?php
namespace App\Models;
use App\Traits\ModelTableNameTrait;
class SampleMigration
{
use ModelTableNameTrait;
@mykeels
mykeels / ModelTableNameTrait.php
Created April 17, 2018 09:44
A trait that adds a static `name()` method to Laravel Models
<?php
namespace App\Traits;
trait ModelTableNameTrait
{
public static function name() {
return with(new static)->getTable();
}
}
@mykeels
mykeels / 2018_04_17_000000_sample_migration.php
Created April 17, 2018 09:29
A sample migration php class generated by Laravel
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class SampleMigration extends Migration
{
/**
* Run the migrations.
@mykeels
mykeels / states-and-cities.json
Created April 8, 2018 12:43
Nigerian States and Cities in JSON
[
{
"name": "Abia",
"cities": [
"Aba South",
"Arochukwu",
"Bende",
"Ikwuano",
"Isiala Ngwa North",
"Isiala Ngwa South",
const storage = {}
app.post('/', textBodyParser, (req, res) => {
storage[req.hash] = storage[req.hash] || req.body.split('\n').map((line) => line.split('').reverse().join('')).join('\n')
res.send(storage[req.hash])
})
const express = require('express')
const crypto = require('crypto')
const isPrime = require('./is-prime')
const app = express()
const calculateHash = function (req, res, buf, encoding){
const hash = crypto.createHash('sha1')
hash.setEncoding('hex')
hash.write(buf.toString(encoding || 'utf8'))
hash.end()
const express = require('express')
const textBodyParser = require('body-parser').text()
const isPrime = require('./is-prime')
const app = express()
app.post('/', textBodyParser, (req, res) => {
res.send(req.body.split('\n').map((line) => line.split('').reverse().join('')).join('\n'))
})
app.get('/', (req, res) => {
@mykeels
mykeels / index.js
Created April 4, 2018 12:50
Fork of https://gist.github.com/mykeels/8396f87d42a809697d08f6b6c9cd8db0 showing response interrupts in a factorial API
const express = require('express')
const app = express()
const storage = []
app.get('/factorial', (req, res) => {
const rootUrl = (url) => req.protocol + '://' + req.get('host') + url;
const id = storage.length + 1;
setTimeout(() => {
let sum = 1;
const express = require('express')
const os = require('os')
const app = express()
const workerFarm = require('worker-farm')
const worker = workerFarm(require.resolve('./worker.js'))
app.get('/', (req, res) => {
const max = Number(req.query.max) || 1000
worker(max, (err, primes) => {
if (err) res.status(500).send(err)
@mykeels
mykeels / child-process.js
Last active April 4, 2018 11:49
A simple example showing a Node program invoking the `ls` child process in a unix environment
(() => {
const { spawn } = require('child_process');
const ls = spawn('ls', ['-lh', '/usr']);
ls.stdout.on('data', (data) => {
console.log(`stdout: ${data}`);
});
ls.stderr.on('data', (data) => {
console.log(`stderr: ${data}`);