Enjoy these free Code Nuggets?

Your support helps us create more high-quality content and unlocks exclusive premium nuggets via a personal activation link.

Support Our Work & Get Exclusive Access
🤖 New — AI Training

Learn to code with AI, not just about it.

Beyond free snippets, we run hands-on training in AI-assisted coding — teaching developers, teams and beginners how to build real software faster using modern AI tools. You bring the ideas; we show you how to ship them with an AI pair-programmer at your side.

  • ✔ Prompting & pairing with AI coding assistants to write, debug and refactor real code
  • ✔ Turning plain-English ideas into working apps, scripts and automations
  • ✔ Reviewing AI output safely — spotting bugs, security gaps and hallucinations
  • ✔ Live cohorts, team workshops and 1-on-1 mentoring — remote or on-site in Kenya
ai-pair-session.md

# You describe it…

"Build me a booking form that emails the client."

# …the AI drafts it…

▸ generating form + mailer…

â–¸ 24 lines written, 0 errors

# …and we teach you to lead it.

✱ You stay the engineer. AI is the tool.

PHP nuggets

3 nuggets found

Clear filter

KenyaVerified Gateway: National ID & Business Registry Verification API (Premium)

PHP php

Unified identity verification & anti-fraud gateway for verifying Kenya National ID numbers, business registration status, and tax compliance via secure REST webhooks.

// KenyaVerified National Registry Verification API
namespace App\Services;

use Illuminate\Support\Facades\Http;

class KenyaVerifiedService {
    public static function verifyNationalId(string $idNumber, string $dob): array {
        $response = Http::withHeaders([
            'X-API-KEY' => confi...

Immutable Value Objects with readonly Properties (Premium)

PHP php

PHP 8.1 introduced readonly properties. Combined with constructor promotion, they let you build small value objects that cannot be mutated after creation — fewer bugs, clearer intent.

final class GeoPoint
{
    public function __construct(
        public readonly float $lat,
        public readonly float $lng,
    ) {}

    public function distanceTo(GeoPoint $other): float
    {
        $r = 6371; // km
        $dLat = deg2rad($other->lat - $this->lat);
        $dLng = deg2rad($...

Transforming Arrays with map, filter and reduce (Premium)

PHP php

Loops that build up a result variable are easy to get wrong. PHP's array functions let you describe what you want — transform, keep, or fold — in a single...

$orders = [
    ['item' => 'Pen',    'qty' => 3, 'price' => 50],
    ['item' => 'Book',   'qty' => 1, 'price' => 400],
    ['item' => 'Marker', 'qty' => 5, 'price' => 80],
];

// Only orders worth 200+, as "item: total"
$lines = array_map(
    fn ($o) => "{$o['item']}: " . ($o['qty'] * $o['price']),...