Skip to content

Instantly share code, notes, and snippets.

View wlkns's full-sized avatar

JW wlkns

View GitHub Profile
@wlkns
wlkns / utils.ts
Created September 22, 2022 08:51 — forked from erikvullings/utils.ts
Utility functions
/* A list of useful functions snippets */
/**
* Create a GUID
* @see https://stackoverflow.com/a/2117523/319711
*
* @returns RFC4122 version 4 compliant GUID
*/
export const uuid4 = () => {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
@wlkns
wlkns / chrome-console.js
Last active August 26, 2022 15:09
YouTube Subscription Feed Fixes (Chrome Console)
/* Remove any YT shorts */
[...document.querySelectorAll('ytd-grid-video-renderer')].filter(e => e.querySelector('[overlay-style="SHORTS"]')).forEach(e => e.remove())
/* Remove any videos under 5 minutes (or whatever the number is changed to.) */
const minimumVideoTimeInMinutes = 5;[...document.querySelectorAll('ytd-grid-video-renderer')].map(el => ({el, time: parseInt(el.querySelector('ytd-thumbnail-overlay-time-status-renderer')?.innerText.trim().split(":")[0], 10)})).filter(({el, time}) => isNaN(time) || time < minimumVideoTimeInMinutes).map(({el}) => el.remove());
/* Remove any channels you may not want to see but remain subbed to. (add to list) */
const badList = ['This Morning'];[...document.querySelectorAll('ytd-grid-video-renderer')].map(el => ({el, name: el.querySelector('ytd-channel-name')?.innerText.trim()})).filter(({name}) => badList.includes(name)).forEach(({el}) => el.remove());
/* Remove any videos based on channel name/length */
@wlkns
wlkns / .php-cs-fixer.php
Last active August 16, 2022 10:04
Laravel PHP-CS Configuration (composer require --dev friendsofphp/php-cs-fixer)
<?php
use PhpCsFixer\Finder;
use PhpCsFixer\Config;
$finder = Finder::create()
->in([
__DIR__.'/app',
__DIR__.'/config',
__DIR__.'/database',
@wlkns
wlkns / App.vue.js
Last active December 23, 2024 11:13
Re-usable Google Maps loader (for Vite/Vue)
import { onMounted } from 'vue';
import loadMap from './load-google-map';
// In vite env make sure VITE_GOOGLE_MAPS_API_KEY= is defined.
onMounted(() => {
// Google maps API is not loaded at all
await loadMap();
// Google maps API is ready and loaded
});
@wlkns
wlkns / install-vue-tailwind.zsh
Last active June 21, 2022 13:09
Install vue@latest with tailwind (command/macosx)
#!/bin/zsh
read -p 'Project folder: ' PROJECT
npm init vue@latest -- --router --typescript --pinia --eslint-with-prettier $PROJECT
cd $PROJECT
npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p
cat << EOF > tailwind.config.js
/** @type {import('tailwindcss').Config} */
@wlkns
wlkns / init-wordpress.sh
Created December 1, 2021 10:26
Install Wordpress Utility
#!/bin/bash
if [ $# -eq 0 ]
then
echo "Please provide installation directory as first parameter e.g. $BASH_SOURCE <dir>"
exit 1
fi
if [ -d $1 ]; then
echo 'Insallation (folder) already exists!'
@wlkns
wlkns / initialise-vue-files.js
Created February 1, 2021 11:19
Initialise empty .vue files with the file name (node initialise-vue-files.js)
// This file will initialise and empty .vue files with a basic name and structure.
const fs = require("fs");
const { exec } = require("child_process");
exec('find src -type f -iname "*.vue"', (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`);
return;
}
@wlkns
wlkns / lottery-numbers.js
Created December 16, 2020 13:18
Lottery number picker! No duplicates, 6 numbers of 1-59.
let numbers = [...new Array(59)].map((v,i) => i+1);
let picks = [...new Array(6)].map(() => numbers.splice(Math.floor(Math.random() * numbers.length), 1)).sort((a,b) => a-b).join(", ")
console.log(picks);
@wlkns
wlkns / AlwaysReturnJson.php
Created April 11, 2020 12:51
Always Return Json
<?php
namespace App\Http\Middleware;
use Closure;
class AlwaysReturnJson
{
/**
* Handle an incoming request.
@wlkns
wlkns / laravel-entities.php
Created March 18, 2020 20:51
Generate $fillable property of Model
<?php
$entities = glob("app/Entities/**/*.php");
foreach ($entities as $entity) {
$className = str_replace('/', '\\', ucfirst(substr($entity, 0, -4)));
$class = new $className;
dump($class->getTable());
$columns = collect(DB::select("SHOW COLUMNS FROM `{$class->getTable()}`"))->filter(function ($column) {
return !in_array($column->Field, ['id', 'created_at', 'updated_at', 'deleted_at']);