Skip to content

Instantly share code, notes, and snippets.

View mykeels's full-sized avatar
😄
faffing!

Michael Ikechi mykeels

😄
faffing!
View GitHub Profile
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}`);
@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()
}
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 / 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 :=
@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 / 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 / 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')