Snippet da Semana

#67 - Simple A/B variation class for experiments - 2019-06-29 - PHP

Class to do variation testing based on experiments and number of variations in PHP.

<?php
class Experiment {
    public static function getVariation($experiment, $numVariations = 2) {
        return hexdec(substr(sha1($experiment . '.' . ($_SERVER['REMOTE_ADDR'] ?? '') . '.' . ($_SERVER['HTTP_USER_AGENT'] ?? '')), 0, 4)) % $numVariations;
    }
}

Projectos

Flutter Animated Backgrounds
Animated Backgrounds for Flutter. Easily extended to paint whatever you want on the canvas.
Link
AutoRPC for Go/JS
Simple RPC library for Go and JavaScript.
Link
Stellar XLM Payment Test Service
Simple payment processor using the crypto-currency Stellar.
Link
XLM Federation Server
Simple Federation server that responds to requests of the Stellar federation protocol.
Link
Nuntius
Seamless connection service between devices (behind NAT). JavaScript and Go client implementations. Server in Go.
Link

Publicações do blog em andrebaltazar.com

Flutter Animated Backgrounds
In this post I will show you how to create a simple animated background from scratch using the Animated Backgrounds package available at pub.dartlang.org, created by me.
Ler mais
Blog Pagination is weird. Here's why.
This week I had to implement a pagination system for the blog. Because, as I write more posts, the blog needs these kind of features. I started looking around at the blogs I read frequently, and ended up more confused on how to implement these pages than when I started.
Ler mais
The PHP type cast that always returns NULL
A few days ago I was going through the a PHP RFC page when I found a vote for deprecation of a cast I had never used before, a cast to NULL. The keyword unset is used for this cast, for example, $b = (unset) $a, which results in $b being assigned with the value NULL, and nothing else.
Ler mais