Skip to content

Instantly share code, notes, and snippets.

View williamjulianvicary's full-sized avatar

William Julian-Vicary williamjulianvicary

View GitHub Profile
@kamilogorek
kamilogorek / _screenshot.md
Last active May 2, 2024 13:48
Clutter-free VS Code Setup
image
@markrittman
markrittman / ga4_attribution_model.sql
Last active February 2, 2023 17:54
First-Click, Last-Click, Even-Click and Time Decay Attribution for GA4
/*
First-Click, Last-Click, Even-Click and Time Decay Attribution for GA4
Replace "event_name in ('Contact Us','Contact Us Clicked','CTA Pressed','Form Submitted')" with the name(s) of your conversion event in lines 54, 57, 61 and 76
*/
WITH
events AS (
SELECT
event_timestamp as event_ts,
user_pseudo_id AS user_pseudo_id,
user_id,
@renalpha
renalpha / DockerFile
Last active January 5, 2024 16:04
Traefik
FROM php:7.4-fpm
RUN apt-get update && apt-get install -y libldb-dev libldap2-dev libzip-dev libpng-dev libjpeg62-turbo-dev libfreetype6-dev \
&& docker-php-ext-configure gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/ \
&& docker-php-ext-install -j$(nproc) zip pdo pdo_mysql gd ldap pcntl opcache
@troatie
troatie / CreatesWithLock.php
Last active September 12, 2023 13:51
Guard against race conditions in Laravel's firstOrCreate and updateOrCreate
trait CreatesWithLock
{
public static function updateOrCreate(array $attributes, array $values = [])
{
return static::advisoryLock(function () use ($attributes, $values) {
// emulate the code found in Illuminate\Database\Eloquent\Builder
return (new static)->newQuery()->updateOrCreate($attributes, $values);
});
}
@brunogaspar
brunogaspar / macro.md
Last active May 1, 2024 07:24
Recursive Laravel Collection Macros

What?

If a nested array is passed into a Laravel Collection, by default these will be threaded as normal arrays.

However, that's not always the ideal case and it would be nice if we could have nested collections in a cleaner way.

This is where this macro comes in handy.

Setup

@jhpacker
jhpacker / get_ga_resources.js
Last active June 6, 2018 15:25 — forked from duncanmorris/get_ga_resources.js
Using PhantomJS to monitor Google Analytics - full code
// initialise various variables
var page = require('webpage').create(),
system = require('system'),
address;
// how long should we wait for the page to load before we exit
// in ms
var WAIT_TIME = 5000;
// if the page hasn't loaded after this long, something is probably wrong.
@simonhamp
simonhamp / AppServiceProvider.php
Last active May 4, 2024 04:21
A pageable Collection implementation for Laravel
<?php
namespace App\Providers;
use Illuminate\Support\Collection;
use Illuminate\Pagination\LengthAwarePaginator;
class AppServiceProvider extends ServiceProvider
{
public function boot()
@rodrigopedra
rodrigopedra / gist:a4a91948bd41617a9b1a
Last active March 30, 2024 16:30
Laravel 5 Middleware for Database Transactions
<?php namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Response;
class DBTransaction
{
/**
* Handle an incoming request.
*