How I Created a Rate Limiting Proxy Middleware With Go

You have just released your shiny new API. With a cool data set that you intend to share with the world. Have you thought about rate limiting? What is Rate Limiting? Rate Limiting is where you restrict access to your service to a certain number of requests per timeframe, per client. Why Rate Limit? The most important reason is to prevent one user from making too many requests and hogging all the resource.
Read more

Using Self-Signed SSL Certificates with Docker and Nginx

This tutorial is going to go through how I create and install self signed SSL certificates for my nginx docker images The set up Assuming I start with dir following directory structure - ssl-docker-nginx/ - nginx - logs/ - my-site.com.access.log - nginx.conf - site/ - index.html - docker-compose.yml site/index.html looks like… <html> <head> <title>My Site</title> </head> <body> <h1>My Site</h1> </body> </html> Nginx/nginx.conf looks like… events { worker_connections 4096; ## Default: 1024 } http { server { listen 80; server_name my-site.
Read more

My Modern PHP Development Setup

tl;dr Use a Makefile and make good use of it Run everything in Docker Use CS Fixer To Adhere To Coding Standards Use PHP Stan Syncronise your team IDE’s with .editorconfig Use a Makefile and make good use of it Most developers use Makefiles, but very few use them effectively. Below is an example of my typical Makefile container=app up: docker-compose up -d build: docker-compose rm -vsf docker-compose down -v --remove-orphans docker-compose build docker-compose up -d down: docker-compose down require: docker-compose run {container} composer require require-dev: docker-compose run {container} composer require --dev run: docker-compose run {container} php index.
Read more

Go Concurrency Design Patterns - Generator

For me the biggest challenge in concurrent programming is making sure all the “jobs” have been ran, and that all channels are closed in a respectable manner. To help with this we have design patterns. I will be going through all of the ones frequently implemented in golang. Today is the simplest of the bunch. The Generator. The Generator pattern works best when you have a pre-defined set of “jobs” that need to be ran in a concurrent manner.
Read more

Efficient Logging in AWS Go Lambas

I have been working with Golang Lambdas for around 6 months now and one of the main problems, we have encountered over the development lifecycle is reporting and observability. Lambdas do not run constantly like code on traditional servers. Instead they are only spun up when needed and kept “warm” until they are no longer needed and then spun down. To diagnose problems, it is important that we have plenty of information going into the logs such as unique run ids, and lots of information about which part of your code is getting run.
Read more

How I build Go lambdas

I have been writing go lambdas for about six months and I have learnt a thing or two during that time. Below is an example of a lambda that sends an email, I will attempt to explain some of my design decisions. The architecture of this repo looks like; handler/ handler.go handler_test.go mail/ mail.go mail_test.go vendor/ // dependencies glide.lock glide.yaml main.go Glide for Dependency Management One of the first things I do when beginning work on any kind of go application is to set up glide.
Read more

Writing Concise and Informative Logs

Observability when working with lambdas is important, with so many getting spun up at different times and serving different requests it is good to have as much information as possible about what exactly is going on. When I wish to debug code my code or pull metrics I always use the json formatting. I do this because it is easily greppable by Cloudwatch and can hold some very valuable information, json is also an amazing format to work with.
Read more

Solving The Subset Problem in php

The subset problem is thus; Given that I have an array of values [100, 50, 25, 10, 1] And I have the target of 176 can i make 176 out of my subset values.? Looking at this simple example you can see that, that is intact the case. The subset of 176 is [100, 50, 25, 1] But lets solve this programatically; <?php function subset($target_number, $subset) { $total_of_numbers_used = 0; $numbers_used = []; foreach($subset as $subset_number) { if(($total_of_numbers_used + $subset_number) <= $target_number) { $total_of_numbers_used += $subset_number; $numbers_used[] = $subset_number; } } return compact('total_of_numbers_used', 'numbers_used'); } // The number we want to find $target_number = 176; // our subset, MUST be descending $sub_set = [100, 50, 25, 1]; print_r(subset($target_number, $sub_set)); // output: Array ( [total_of_numbers_used] => 176 [numbers_used] => Array ( [0] => 100 [1] => 50 [2] => 25 [3] => 1 ) ) So yes i can make the number 176 out of 100, 50, 25, and 1.
Read more

Testing File Uploads In Laravel PHP Unit

The Scenario In PHP unit when we would like to test the upload functionality of our site it is best (in most cases) to not actually upload anything to anywhere and instead use Laravels helpful Facade mockery capabilities. The Code // The name of the drive to use, for example profile pictures will not be placed in the same place as post images Storage::fake('profile-pictures'); // make a fake file using Laravel's facade mockery interface // Param1: name of file, Param 2: size in kbs $profileImage = UploadedFile::fake()->create('test-user.
Read more

PHP Is Set Magic Method

What it does The isset magic method is called when an unset or inaccessible property is called on an object. class user { public function __construct($name, $age) { // } public function __isset($value) { return 'That property does not exist'; } } $user = new User(); $user->age; // returns 'That property does not exist' As you can see abce we are trying to access the age property on the class, but unfortunately there isn’t one.
Read more