Skip to content

Instantly share code, notes, and snippets.

@tomredman
tomredman / webhooks.ts
Created February 16, 2024 17:37
Accepting & verifying Facebook webhooks in NextJS
import crypto from "crypto";
import type { NextApiRequest, NextApiResponse } from "next";
import { buffer } from "micro";
export const config = {
api: {
bodyParser: false,
},
};
@tomredman
tomredman / tailwind-colors.js
Last active April 3, 2022 14:57
Index of all possible TailwindCSS 3.0.23 color variables
/**
* Importing this file and applying this string to `className` on a hidden div
* will allow you to dynamically create tailwind components with any color you
* want, because Tailwind will compile and include all the colors it sees in your
* final CSS.
*
* BE WARNED this will increase the size of your compiled CSS file, which negates
* one of Tailwind's killer features: smallest CSS file based on just-what-you-use.
*/
@tomredman
tomredman / CreateNewUser.php
Created November 22, 2020 01:01
CreateNewUser.php
<?php
namespace App\Actions\Fortify;
use App\Models\User;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Laravel\Fortify\Contracts\CreatesNewUsers;
class CreateNewUser implements CreatesNewUsers
@tomredman
tomredman / api.php
Created November 22, 2020 00:59
api-routes.php
/*
|--------------------------------------------------------------------------
| Authentication
|--------------------------------------------------------------------------
*/
Route::post('/register', [UserController::class, 'register']);
Route::post('/login', [UserController::class, 'login']);
Route::post('/logout', [UserController::class, 'logout']);
@tomredman
tomredman / AuthController.php
Created November 22, 2020 00:47
Simple Laravel Sanctum API auth controller for 3rd party/mobile register, login and logout
<?php
namespace App\Http\Controllers\Api;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Auth;
use Illuminate\Auth\Events\Registered;
use App\Actions\Fortify\CreateNewUser;
use Illuminate\Validation\ValidationException;
@tomredman
tomredman / explicit.java
Last active April 13, 2016 13:56
Code Principle Example: "Explicit is better than Implicit"
/**
* You've probably heard it before, "explicit is better than implicit". Here's a simple
* example of that principle in action.
*
* In this example, our app has only two Fragments that can be visible at any given
* moment: CreateFragment and TrendingFragment. Both examples achieve the same result
* when everything is working as expected, however...
*
* In the explicit example, a final else{} branch would indiciate something's not
* quite right with our code somewhere since we know there are only two possible
@tomredman
tomredman / ColorFadeTransform.java
Last active April 13, 2016 13:23
ColorFadeTransform for Picasso
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.Shader;
import android.support.annotation.ColorInt;
import com.squareup.picasso.Transformation;
@tomredman
tomredman / FAQCustomTab.java
Last active September 9, 2015 19:42
Example usage of the ChromeCustomTab class
package org.buffer.android.helpers.customtabs;
import android.app.Activity;
/**
* -----------------------
* FAQCustomTab
* -----------------------
*
* @author Tom Redman
@tomredman
tomredman / ChromeCustomTab.java
Created September 9, 2015 19:31
A simple, reusable implementation of Chrome custom tabs for Android
package org.buffer.android.helpers.customtabs;
import android.app.Activity;
import android.content.ComponentName;
import android.net.Uri;
import android.os.Bundle;
import android.support.customtabs.CustomTabsCallback;
import android.support.customtabs.CustomTabsClient;
import android.support.customtabs.CustomTabsIntent;
import android.support.customtabs.CustomTabsServiceConnection;

Keybase proof

I hereby claim:

  • I am tomredman on github.
  • I am redman (https://keybase.io/redman) on keybase.
  • I have a public key whose fingerprint is 5A15 04A9 5579 5F27 0E55 101B 5A11 0A7C 9728 3A1B

To claim this, I am signing this object: