Skip to content

Instantly share code, notes, and snippets.

@tomjn
tomjn / custom_page.php
Last active July 3, 2018 11:50
A base class used to create arbitrary content at arbitrary URLs in WordPress without needing a post or listing/archive to host it
<?php
/**
* A helper class to implement arbitrary content at arbitrary URLs without a supporting post or page.
* Inherit from this class and implement the render_page method
*
* @author: Tom J Nowell ww.tomjn.com
* @License: GPL 2+
*/
abstract class Tomjn_Custom_Page {
@tomjn
tomjn / helloworld.php
Last active July 3, 2018 11:50
An example of how to use the class defined here: https://gist.github.com/Tarendai/6089867
<?php
require_once( 'custom_page.php' );
class Hello_World_Page extends Tomjn_Custom_Page {
public function render_page() {
echo 'hello world!';
}
}
@mantis
mantis / build.ps1
Created February 19, 2017 15:20
Windows Build File for admin-on-rest
<#
.SYNOPSIS
Manages the build of admin-on-rest on windows
.DESCRIPTION
This powershell script attempts to implement the linux makefile for admin-on-rest for those users who may wish to
develop the system on a windows based operating system.
Examples:
1) To install required modules
./make.ps1 -install
@ksassnowski
ksassnowski / functor.php
Last active October 15, 2021 12:50
Playing around with functors in PHP
<?php
interface Functor
{
// fmap :: Functor f => (a -> b) -> f a -> f b
public function fmap(callable $fn): Functor;
}
class Fn implements Functor
{
@niieani
niieani / gist:1213709
Created September 13, 2011 12:33
PHP Camel Case functions
<?php
// source: http://www.paulferrett.com/2009/php-camel-case-functions/
/**
* Translates a camel case string into a string with underscores (e.g. firstName -&gt; first_name)
* @param string $str String in camel case format
* @return string $str Translated into underscore format
*/
function from_camel_case($str) {
$str[0] = strtolower($str[0]);
@erikaheidi
erikaheidi / le-renew.sh
Last active February 23, 2022 02:13
Auto renewal for Let's Encrypt Apache
#!/bin/bash
#================================================================
# Let's Encrypt renewal script for Apache on Ubuntu/Debian
# @author Erika Heidi<erika@do.co>
# Usage: ./le-renew.sh [base-domain-name]
# More info: http://do.co/1mbVihI
#================================================================
domain=$1
le_path='/opt/letsencrypt'
le_conf='/etc/letsencrypt'
@gbuckingham89
gbuckingham89 / AuthServiceProvider.php
Last active August 22, 2022 12:01
Blog: Laravel Authentication Customer User Provider Demo
<?php
namespace App\Authentication;
use Auth;
use App\Authentication\UserProvider;
use Illuminate\Support\ServiceProvider;
class AuthServiceProvider extends ServiceProvider
{
@JacobBennett
JacobBennett / blog.md
Last active June 4, 2023 05:50
Sharing Laravel Cookies across subdomains

I recently ran into a problem where I had a suite of applications hosted on a set of subdomains that all needed to be able to share a single cookie. Any cookies other than the shared cookie needed to stay specific to their subdomain, but this one shared cookie needed to be accessible to any of them. I also wanted to accomplish this using Laravel's Cookie facade.

The Problem

To accomplish this, there were two issues to solve.

  1. All cookies created by the Laravel framework are encrypted by default. (link)
  2. I needed to figure out how to set a domain on the shared cookie that was different than the domain it was being set from.

Setting Non-Encrypted Cookies

In Laravel 5.1, a feature was added which allows you to add a list of cookie names that should not be encrypted to the EncryptCookies Middleware under the $except array. Check out [the docs](http://laravel.com/docs/5.1/responses#attaching-cookies

@johannesberdin
johannesberdin / convert.sh
Last active July 1, 2023 22:32
Script for recursively converting all files to UTF-8 (Mac OS X)
#!/bin/bash
# Original by LEXO, http://www.lexo.ch
# Link: https://www.lexo.ch/blog/2013/01/linux-bash-shell-script-for-recursively-converting-all-files-with-various-charsets-in-a-directory-into-utf-8-shell-skript-fur-das-rekursive-konvertieren-von-allen-files-in-einem-verzeichnis-mit-belie/
# Changed by Johannes Berdin, http://johannesberdin.de
# for running under Mac OS X
#
# Version 1.0
#
# This bash script converts all files from within a given directory from any charset to UTF-8 recursively
@iben12
iben12 / 1_Laravel_state-machine.md
Last active August 12, 2023 08:36
Laravel: State-machine on Eloquent Model

Implementing State Machine On Eloquent Model*

* Update (12.09.2017): I have improved the trait so that it can be used with objects other than Eloquent Models.

Some days ago I came across a task where I needed to implement managable state for an Eloquent model. This is a common task, actually there is a mathematical model called "Finite-state Machine". The concept is that the state machine (SM) "can be in exactly one of the finite number of states at any given time". Also changing from one state to another (called transition) depends on fulfilling the conditions defined by its configuration.

Practically this means you define each state that the SM can be in and the possible transitions. To define a transition you set the states on which the transition can be applied (initial conditions) and the only state in which the SM should be after the transition.

That's the theory, let's get to the work.