Skip to content

Instantly share code, notes, and snippets.

View wlkns's full-sized avatar

JW wlkns

View GitHub Profile
@wlkns
wlkns / time-ago.ts
Last active December 8, 2023 11:15
Time Ago.js
const oneDay = 60 * 60 * 24 * 1000
const weekDays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
const months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
const getTime = (date: Date) => {
const amPM = date.getHours() > 12 ? 'PM' : 'AM'
const time = [date.getHours() % 12, String(date.getMinutes()).padStart(2, '0')].join(':')
return time + ' ' + amPM
}
@wlkns
wlkns / output.txt
Last active October 26, 2023 07:51
Unique Sequencer
"AAA"
"BAA"
"CAA"
"DAA"
"EAA"
"FAA"
"GAA"
"HAA"
"IAA"
"JAA"
@wlkns
wlkns / nginx-wordpress.conf
Created September 16, 2023 10:52 — forked from nfsarmento/nginx-wordpress.conf
Harden wordpress security nginx
############ WordPress ####################
# Disable logging for favicon and robots.txt
location = /favicon.ico {
try_files /favicon.ico @empty;
access_log off;
log_not_found off;
expires max;
}
@wlkns
wlkns / fill-empty-files.mjs
Created August 1, 2023 13:27
Fill empty .vue files with a template.
import { resolve } from 'path';
import { readdir, stat, writeFile } from 'node:fs/promises';
async function* getFiles(dir) {
const dirents = await readdir(dir, { withFileTypes: true });
for (const dirent of dirents) {
const res = resolve(dir, dirent.name);
if (dirent.isDirectory()) {
yield* getFiles(res);
} else {
@wlkns
wlkns / build-indexes.js
Last active July 18, 2023 15:37
Package up Vue components & exports into index.js (no deps, tested Node 18 LTS)
import { readdir, readFile, writeFile } from 'node:fs/promises';
const parseDir = async (path, directoriesOnly) => {
return (await readdir(path, {withFileTypes: true}))
.filter(file => file.isDirectory() == directoriesOnly)
.map(file => file.name);
}
const determineImportExports = async ({dir, file}) => {
if ( file.endsWith('.vue') )
@wlkns
wlkns / HttpProxyAdapter.php
Created May 25, 2023 07:47
Laravel HTTP Proxy Filesystem Adapter
<?php
namespace App\Filesystem\Adapters;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Str;
use League\Flysystem\Config;
use League\Flysystem\FileAttributes;
use League\Flysystem\FilesystemAdapter;
@wlkns
wlkns / php_unique_array_combinations.php
Last active February 16, 2023 07:44
Generate unique combinations of PHP arrays
<?php
/**
* Generate unique combinations of an array...
*/
function combinations($array)
{
$return = [];
$num = count($array);
// The total number of possible combinations
$total = pow(2, $num);
@wlkns
wlkns / conclusion.md
Last active October 4, 2022 09:41
Testing MySQL vs PHP format for matching Week Year formats (Laravel)
@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 */