Skip to content

Instantly share code, notes, and snippets.

View samolabams's full-sized avatar

samolabams

  • Lagos, Nigeria
View GitHub Profile
@samolabams
samolabams / LongestWordFinder.js
Created June 9, 2018 17:44
Find the longest word in a sentence
function longest(sentence) {
var sentence_words = sentence.split(' ');
if (!Array.isArray(sentence_words) || sentence_words.length === 0) return false;
var longest_word = sentence_words[0];
for (let i=0; i < sentence_words.length; i++) {
if (sentence_words[i].trim().length > longest_word.trim().length) {
longest_word = sentence_words[i];
@samolabams
samolabams / Laravel-Container.md
Created December 19, 2018 13:51
Laravel's Dependency Injection Container in Depth

Laravel's Dependency Injection Container in Depth

Translations: Korean (by Yongwoo Lee)

Laravel has a powerful Inversion of Control (IoC) / Dependency Injection (DI) Container. Unfortunately the official documentation doesn't cover all of the available functionality, so I decided to experiment with it and document it for myself. The following is based on Laravel 5.4.26 - other versions may vary.

Introduction to Dependency Injection

I won't attempt to explain the principles behind DI / IoC here - if you're not familiar with them you might want to read What is Dependency Injection? by Fabien Potencier (creator of the Symfony framework).

@samolabams
samolabams / socket-cheatsheet.js
Created January 10, 2019 15:27 — forked from alexpchin/socket-cheatsheet.js
A quick cheatsheet for socket.io
// sending to sender-client only
socket.emit('message', "this is a test");
// sending to all clients, include sender
io.emit('message', "this is a test");
// sending to all clients except sender
socket.broadcast.emit('message', "this is a test");
// sending to all clients in 'game' room(channel) except sender
@samolabams
samolabams / virtualbox_restart.md
Created January 9, 2020 10:36 — forked from bwoodmansee/virtualbox_restart.md
Restart VirtualBox on OS X

sudo /Library/StartupItems/VirtualBox/VirtualBox restart

New Virtualbox: sudo launchctl load /Library/LaunchDaemons/org.virtualbox.startup.plist

@samolabams
samolabams / 1-install.sh
Created January 9, 2020 12:26 — forked from kevinswiber/1-install.sh
Kubernetes resources for standing up Express Gateway
#!/bin/bash
kubectl create -f https://gist.githubusercontent.com/kevinswiber/e6a8245930676c3da3448b2bb79f23fd/raw/0869b72410851e2ab02d0c1c30443f4083345066/configmap.yaml
kubectl create -f https://gist.githubusercontent.com/kevinswiber/e6a8245930676c3da3448b2bb79f23fd/raw/0869b72410851e2ab02d0c1c30443f4083345066/deployment.yaml
kubectl create -f https://gist.githubusercontent.com/kevinswiber/e6a8245930676c3da3448b2bb79f23fd/raw/0869b72410851e2ab02d0c1c30443f4083345066/service.yaml
function loadModule(filename, module, require) {
const wrappedSrc = `
function(module, exports, require) {
${fs.readFileSync(filename, 'utf8')}
}(module, module.exports, require)
`;
eval(wrappedSrc);
}
@samolabams
samolabams / service-checklist.md
Created October 18, 2021 16:57 — forked from acolyer/service-checklist.md
Internet Scale Services Checklist

Internet Scale Services Checklist

A checklist for designing and developing internet scale services, inspired by James Hamilton's 2007 paper "On Desgining and Deploying Internet-Scale Services."

Basic tenets

  • Does the design expect failures to happen regularly and handle them gracefully?
  • Have we kept things as simple as possible?
@samolabams
samolabams / caller.go
Created November 1, 2021 15:45 — forked from ribice/caller.go
A robust rabbitmq client for Go
go func() {
for {
err = rmq.Stream(cancelCtx)
if errors.Is(err, rabbitmq.ErrDisconnected) {
continue
}
break
}
}()
@samolabams
samolabams / queue.go
Created November 1, 2021 15:45 — forked from harrisonturton/queue.go
RabbitMQ client that automatically reconnects when the connection fails, and has a confirmed push method (i.e. the server is guaranteed to recieve the message)
package main
import (
"errors"
"github.com/streadway/amqp"
"log"
"os"
"time"
)
@samolabams
samolabams / TransformData.php
Created June 14, 2018 17:43
A laravel middleware that can transform request data
<?php
namespace App\Http\Middleware;
use Closure;
use Symfony\Component\HttpFoundation\ParameterBag;
class TransformData
{
/**