Skip to content

Instantly share code, notes, and snippets.

View wlkns's full-sized avatar

JW wlkns

View GitHub Profile
@wlkns
wlkns / random_password
Created May 3, 2018 08:54
Random password command line with password copied to clipboard (Usage: random_password <length default:12>) - Save to /usr/local/bin/random_password and don't forget to chmod +x the resulting file.
#!/bin/sh
LENGTH=${1:-12}
RANDOM_STRING=`openssl rand -base64 ${LENGTH}`
`echo "${RANDOM_STRING}" | tr -d '\n' | pbcopy`
echo "\033[1;32mRandom Password: \033[0m"
echo ""
echo " ${RANDOM_STRING}"
echo ""
@wlkns
wlkns / uber.js
Created January 2, 2019 13:33
Get the dates and totals of Uber trips (must be logged into Uber, use in Chrome console.)
(function() {
let amts = [], dates = [];
Array.from(document.querySelectorAll('div.dh')).forEach(function(el) {
let date_amount = el.querySelector('div.an');
dates.push(date_amount.querySelector('div:first-child').innerText.split(',')[0]);
amts.push(date_amount.querySelector('div:last-child').innerText.replace('£', ''));
});
console.log(amts.join("\n"))
console.log(dates.join("\n"));
})();
@wlkns
wlkns / ValidTwigTemplate.php
Created February 19, 2019 12:58
Laravel Validate Twig Template
<?php
namespace App\Rules;
use Illuminate\Contracts\Validation\Rule;
use Twig_Environment;
use Twig_Filter;
use Twig_Loader_Array;
use Twig_Error_Syntax;
@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']);
@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 / 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 / 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 / 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 / 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 / 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
});