Skip to content

Instantly share code, notes, and snippets.

View Mestika's full-sized avatar

Emil Devantie Brockdorff Mestika

View GitHub Profile
@Mestika
Mestika / UserController.php
Last active August 9, 2023 19:54
Resource Meta Data
<?php
/**
* You may also call the additional() method on your API resource instance if you need to define meta data at the controller level.
*/
public function show(User $user)
{
return UserResource::make($user)->additional([
'meta' => [
'key' => 'value',
@Mestika
Mestika / DateTimeResource.php
Created August 9, 2023 19:50
Dedicated Resource For Datetimes
<?php
class DateTimeResource extends JsonRsource
{
public function toArray($request)
{
return [
'datetime' => $this->toISOString(),
'human_diff' => $this->diffForHumans(),
'human' => $this->toDayDateTimeString(),
@Mestika
Mestika / Elvis-vs-Coalescing.md
Last active August 20, 2021 09:25
PHP: ?? vs ?:

?: (Elvis Operator)

The elvis operator (?:) is actually a name used for shorthand ternary (which was introduced in PHP 5.3). It has the following syntax:

expr1 ?: expr2;

This is equivalent to:

expr1 ? expr1 : expr2;

?? (Null Coalescing Operator)

@Mestika
Mestika / Update-git-tower-2-repo
Last active January 12, 2021 14:13
Update Git Tower 2 Repository local location
Path Mac OS X
~/Library/Application Support/com.fournova.Tower2/
Database file
Tower.sqlite3
SQLite Application (Mac OS X)
https://sqlitebrowser.org/
Query to update
@Mestika
Mestika / string-jsx-component.jsx
Created December 11, 2020 11:47
React/JSX: Component as Element
const Button = ({ Component = 'button', ...props }) => <Component {...props} />
<Button>A Button</Button> // Renders a button element
<Button Component="a">A Link</Button> // Renders an anchor element
import React, { useState, useEffect, useRef } from "react";
export default function App() {
const [name, setName] = useState("");
const loaded = useRef(false);
useEffect(() => {
if (!loaded.current) {
console.log("Load on Init!");
setName("Bob");
@Mestika
Mestika / .htaccess
Created July 6, 2020 20:20
htaccess force HTTPS and non-www
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP:X-Forwarded-Proto} =http
#for proxy/load balancer 👆
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
const CombinedProviders = combineProviders(
SentryProvider,
NavbarProvider,
SidebarProvider,
FooterProvider,
BlogsProvider,
)
function App() {
return (
const stringifySafe = () => {
const stack = [];
const keys = [];
const cycleReplacer = (key, value) => {
if (stack[0] === value) {
return '[Circular ~]';
}
return `[Circular ~.${keys.slice(0, stack.indexOf(value)).join('.')}]`;
};
@Mestika
Mestika / wp-disable-plugin-update.php
Created April 30, 2020 19:48 — forked from ebetancourt/wp-disable-plugin-update.php
WordPress - Disable specific plugin update check
<?php
// have to add that opening tag to get syntax highlighting... ¯\_(ツ)_/¯
/**
* Prevent update notification for plugin
* http://www.thecreativedev.com/disable-updates-for-specific-plugin-in-wordpress/
* Place in theme functions.php or at bottom of wp-config.php
*/
function disable_plugin_updates( $value ) {