Skip to content

Instantly share code, notes, and snippets.

View wlkns's full-sized avatar

JW wlkns

View GitHub Profile
@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 / 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 / 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 / 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 / gulpfile.js
Created March 4, 2018 12:23
Gulp + Babel + import
gulp.task('scripts:search', () => {
return gulp.src('./search-module/index.js', { read: false })
.pipe(tap((file) => {
file.contents = browserify(file.path, {
debug: true
}).transform(babel, {
presets: ["es2015"],
plugins: ["angularjs-annotate"]
}).bundle();
}))
@wlkns
wlkns / gulpfile.babel.js
Created March 2, 2018 10:51 — forked from nicekiwi/gulpfile.babel.js
New ES6 project with Babel, Browserify & Gulp + Bundling/Watching Multiple Files
import gulp from 'gulp';
import sourcemaps from 'gulp-sourcemaps';
import buffer from 'gulp-buffer';
import uglify from 'gulp-uglify';
import tap from 'gulp-tap';
import browserify from 'browserify';
import babel from 'babelify';
gulp.task('build', () => {
@wlkns
wlkns / RegionRedirectCookieMiddleware.php
Created October 6, 2017 12:18
Laravel region selector (with cookies)
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Cookie;
class RegionCookieRedirect
{
/**
* Returns the value at the given property.
*
* @param {object} - the input object
* @param {string} - the property accessor expression.
* @returns {*}
* @alias module:object-get
* @example
* > objectGet({ animal: 'cow' }, 'animal')
* 'cow'
;(function() {
'use strict';
angular.module('app').filter('address', Filter);
function Filter($sce) {
return function(input, seperator, defaultValue) {
seperator = seperator || ', ';
defaultValue = defaultValue || '';
mixin csrf
div
input(type='hidden', name='_csrf', value=csrfToken)
block
mixin formErrors(form)
errors = form.nonFieldErrors().errors
for error in errors
.alert.alert-error= error