Skip to content

Instantly share code, notes, and snippets.

View ghostwriter's full-sized avatar
🐘
while(!succeed=try())

Nathanael Esayeas ghostwriter

🐘
while(!succeed=try())
  • 0.0.0.0
View GitHub Profile

The art of naming variables

Arrays

// bad
const fruit = ['apple', 'banana', 'cucumber']

// okay
const fruitArr = ['apple', 'banana', 'cucumber']

// good

Example list of first words to use in a git commit title

I like writing well-formed git commits that explain the intention behind why a code change was made.

Check out Chris Beams excellent How to Write a Git Commit Message if you haven't read it.

Anyway, for a project I've been working on I've gathered up 900+ commits that hold up a pretty high quality (except for one 😁). Let's look at some trends about these commits!

Most common first words in commit titles of a project

@ghostwriter
ghostwriter / intercept.js
Created February 26, 2021 18:51
intercept XMLHttpRequest
const intercept = (urlmatch, newurl) => {
const open = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function (method, url, ...rest) {
url = url.replace(urlmatch, newurl);
return open.call(this, method, url, ...rest);
};
}
intercept('example.com', 'example2.com');
@ghostwriter
ghostwriter / FinalClass.php
Last active May 5, 2021 19:31
How to correctly mock a "final" class in PHP - (Solves the issue Class "FinalClass\Bar" is declared "final" and cannot be mocked.)
<?php
namespace FinalClass;
require_once __DIR__ . '/vendor/autoload.php';
use PHPUnit\Framework\TestCase;
final class Foo
{
protected $bar;
@ghostwriter
ghostwriter / ValidGmailAddress.php
Created November 30, 2020 13:44
A custom Validation Rule for Laravel to ensure a given Gmail address exists.
<?php
namespace App\Rules;
use Illuminate\Contracts\Validation\Rule;
class ValidGmailAddress implements Rule
{
/**
* Determine if the validation rule passes.
@ghostwriter
ghostwriter / tag-input.blade.php
Created September 10, 2020 14:17
Tag input blade component
<div x-data="tagSelect()" x-init="init('parentEl')" @click.away="clearSearch()" @keydown.escape="clearSearch()">
<div class="relative" @keydown.enter.prevent="addTag(textInput)" @keydown.tab.prevent="addTag(textInput)">
<input
id="{{ $id }}"
type="{{ $formtype ?? 'text' }}"
x-model="textInput"
x-ref="textInput"
@input="search($event.target.value)"
class="form-input block w-full transition duration-150 ease-in-out sm:text-sm sm:leading-5"
placeholder="{{ $placeholder ?? '' }}">
@ghostwriter
ghostwriter / example.php
Created August 12, 2020 20:21
PHP && vs AND
<?php
// Expression to use && operator
$bool = TRUE && FALSE;
// Display the result of && operation
echo ($bool ? 'TRUE' : 'FALSE'); // Output: FALSE
// Expression to use AND operator
$bool = TRUE and FALSE;
// Display the result of AND operation
@ghostwriter
ghostwriter / QuantcastChoice.html
Created July 13, 2020 20:40
Obtain and manage consumer consent for GDPR across digital ecosystem with Quantcast Choice. Details here: https://help.quantcast.com/hc/en-us/articles/360047075914-Choice-Universal-Tag-Implementation
<!-- Quantcast Choice. Consent Manager Tag v2.0 (for TCF 2.0) -->
<script type="text/javascript" async="true">
(function() {
var host = window.location.hostname;
var element = document.createElement('script');
var firstScript = document.getElementsByTagName('script')[0];
var milliseconds = new Date().getTime();
var url = 'https://quantcast.mgr.consensu.org'
.concat('/choice/', 'CUSTOM_ID', '/', host, '/choice.js')
.concat('?timestamp=', milliseconds);
@ghostwriter
ghostwriter / cd.yml
Last active May 23, 2020 12:20
Deploy a Laravel app for free with GitHub Actions
name: CD
on:
push:
branches: [ production ]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
@ghostwriter
ghostwriter / webpack.mix.js
Created May 5, 2020 01:31
Laravel Mix with multiple Tailwind config and PurgeCSS
const mix = require("laravel-mix");
const tailwindcss = require("tailwindcss");
const rootPath = mix.paths.root.bind(mix.paths);
const tailwindPlugins = function (configFile, paths) {
const pluginList = [tailwindcss(configFile)];
if (mix.inProduction()) {
pluginList.push(
require("@fullhuman/postcss-purgecss")({