Skip to content

Instantly share code, notes, and snippets.

View adamwathan's full-sized avatar

Adam Wathan adamwathan

  • Ontario, Canada
View GitHub Profile
@adamwathan
adamwathan / Statamic+Tailwind+PurgeCSS.md
Last active January 8, 2024 19:52 — forked from binoclard/Statamic+Tailwind+PurgeCSS.md
Fresh Statamic install, with Tailwind CSS and PurgeCSS configured

In 5 minutes, you’ll have a brand new clean Statamic site, with Tailwind CSS and PurgeCSS configured.

It assumes that you work on a Mac, you put your site in ~/sites and you use Laravel Valet.

All the credit go to Jack McDade and philipboomy, from whom I stole and adapt the build scripts and the PurgeCSS config, this is only a detailed write up of the process.

You'll need Yarn and Node. You can install them both in one command via Brew: brew install yarn

@adamwathan
adamwathan / Marge.php
Last active September 19, 2023 13:11 — forked from davidhemphill/Marge.php
<?php
namespace App\Merge;
class Marge
{
protected $data = [];
public function setData($data)
{
@adamwathan
adamwathan / v-cloak.md
Last active February 26, 2023 14:26
Useful CSS utilities for Vue.js cloaking

Handy helpers for controlling visibility of elements until Vue has compiled.

Use like:

<div v-cloak>
  <h1>
    <span class="v-cloak--inline">Loading...</span> <!-- Only displayed before compiling -->
    <span class="v-cloak--hidden">{{ post.title }}</span> <!-- Hidden until compiling is finished -->
 
@adamwathan
adamwathan / promise-take-at-least.js
Last active February 26, 2023 14:25
Promise.takeAtLeast
// Creates a new promise that automatically resolves after some timeout:
Promise.delay = function (time) {
return new Promise((resolve, reject) => {
setTimeout(resolve, time)
})
}
// Throttle this promise to resolve no faster than the specified time:
Promise.prototype.takeAtLeast = function (time) {
return new Promise((resolve, reject) => {
@adamwathan
adamwathan / easing.css
Created November 11, 2017 01:24 — forked from bendc/easing.css
Easing CSS variables
:root {
--ease-in-quad: cubic-bezier(.55, .085, .68, .53);
--ease-in-cubic: cubic-bezier(.550, .055, .675, .19);
--ease-in-quart: cubic-bezier(.895, .03, .685, .22);
--ease-in-quint: cubic-bezier(.755, .05, .855, .06);
--ease-in-expo: cubic-bezier(.95, .05, .795, .035);
--ease-in-circ: cubic-bezier(.6, .04, .98, .335);
--ease-out-quad: cubic-bezier(.25, .46, .45, .94);
--ease-out-cubic: cubic-bezier(.215, .61, .355, 1);
@adamwathan
adamwathan / Uppercase.php
Created December 1, 2017 23:55
Unit Testing Custom Validation Rules
<?php
namespace App\Rules;
use Illuminate\Contracts\Validation\Rule;
class Uppercase implements Rule
{
public function passes($attribute, $value)
{
@adamwathan
adamwathan / maxBy.php
Created June 23, 2016 18:44
maxBy/minBy macros
<?php
Collection::macro('maxBy', function ($callback) {
$callback = $this->valueRetriever($callback);
return $this->reduce(function ($result, $item) use ($callback) {
if ($result === null) {
return $item;
}
return $callback($item) > $callback($result) ? $item : $result;
@adamwathan
adamwathan / laravel-cors.php
Last active September 16, 2022 00:16
Need to do something like this to serve APIs that are going to be consumed by JS clients.
<?php
App::before(function($request) {
if ($request->getMethod() == 'OPTIONS') {
$response = Response::make('', 204);
$response->header('Access-Control-Allow-Methods', 'GET, POST, PUT, OPTIONS');
$response->header('Access-Control-Allow-Origin', '*');
$response->header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, Authorization');
return $response;
}
@adamwathan
adamwathan / less-bem.less
Created November 2, 2014 14:53
BEM-ish nesting in Less
.episode {
margin-bottom: 5em;
&-header {
&-title {
margin-top: 0;
margin-bottom: (@line-height-computed / 4);
font-size: @font-size-h4;
}
&-meta {
margin-top: 0;
@adamwathan
adamwathan / struct.php
Last active September 9, 2022 11:12
Structs in PHP
<?php
// Wow this whole thing is horrible
class Struct
{
public function __construct($properties)
{
foreach ($properties as $key => $value) {
if (property_exists($this, $key)) {
$this->{$key} = $value;