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 / 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;
@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 / Cocoapods-Build-Phase.md
Last active March 23, 2019 03:27
Add file to specific Pods' Frameworks Build Phase using cocoapods' post_install

In a large, nested project where I prefer to control the workspace, I run pod install --no-integrate on my root project. However, some pods don't include their required static libs correctly within their target's framework build phases.

For example, Pod-TestFlightSDK's required libTestFlight.a is excluded and removed every time I update my pods. Which required me to manually update the Pod target each time to include the static lib, which required me to automate it:

post_install do |installer_representation|
    installer_representation.project.targets.each do |target|
        if target.name == 'Pods-TestFlightSDK'
            libFile = installer_representation.project.new_file('TestFlightSDK/libTestFlight.a')
        end
@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