Skip to content

Instantly share code, notes, and snippets.

@ohnotnow
ohnotnow / controller_snippet.php
Created June 7, 2016 16:08
Trying to build an array for laravel sync() method using a collection pipeline
/**
The allocate_ids and remove_ids are from a multiselect so just an array of id's.
Trying to end up with a structure like :
[
123 => ['is_accepted' => true],
345 => ['is_accepted' => true],
...
]
No matter how many variations of map/flatmap/values/blah I used I always either ended up
with a collection of collections, or had re-keyed the collection to something like :
@ohnotnow
ohnotnow / gist:ef81d8b4c9c7787a2eaa3450e7d8a126
Last active August 10, 2016 11:51
Versioning forms/models
For instance, say I have an 'annual review' form for people. Last year
they had to fill out training courses attended, this year they don't.
Next year the form changes completely but is still called an 'annual
review' as far as the business is concerned. The forms can change
pretty much any time - not just on a nice annual cycle (naturally).
There are also process/logic changes like one year a review has to be
signed off by the line manager. Next year it has to be also signed off
by their unit head. The year after there is an arbitration process
introduced so if the person appeals the decision of $whoever was supposed
@ohnotnow
ohnotnow / gist:697cf121525602c9c63abe46dbdcd53f
Created October 7, 2016 11:54
Testing/mocking stdlib function
<?php
/*
This is a contrived example - but I'm working on a large PHPv4 style legacy codebase
and it's full of this kind of code (only much, much worse - c70,000 lines of raw
mysql calls etc).
So in this case I could use the 'namespace' mocking trick to mock all of the
functions - but to test things like "everything passes", "connection works, but TLS
fails", "password is wrong" etc, seems hard to do without the tests
getting really quite nasty. Combined with all the raw mysql* function calls it
@ohnotnow
ohnotnow / gist:c92c488fa106b303bbf615058cc4b925
Created September 30, 2017 09:27
ublock origin rule to hide 'user X liked....' in the feed
twitter.com##body:not(.NotificationsPage) li.stream-item:has(.Icon--heartBadge)
@ohnotnow
ohnotnow / autostart.sh
Created December 2, 2017 15:47
Disabling wifi power management on rpi3/libreelec
# from : https://forum.libreelec.tv/thread/5074-wifi-issues-on-rpi-3-poor-speed-and-latency-solution/#codeLine_1_3e8919
# first install the 'network tools' add-on from the kodi repository then create a /storage/.config/autostart.sh file with
# this as the contents.
# then reboot the pi. runnning 'iwconfig' should now show the power-management as being off.
/storage/.kodi/addons/virtual.network-tools/bin/iw wlan0 set power_save off
@ohnotnow
ohnotnow / example.php
Created December 8, 2017 09:17
Rendering the contents of a laravel mail notification in a test
Notification::assertSentTo($user, MyNotification::class, function ($notification) use ($user) {
$markdown = app(\Illuminate\Mail\Markdown::class);
$mail = $notification->toMail($user);
dd($markdown->render($mail->markdown, $mail->data()));
});
@ohnotnow
ohnotnow / gist:bdd8f4e6f4eed6ec9b1d12c207b31d74
Last active February 19, 2018 10:27
Vuejs directive for pikaday
// npm install pikaday
// resources/assets/js/app.js
import Pikaday from "pikaday";
import "pikaday/css/pikaday.css";
Vue.directive("pikaday", {
bind: (el, binding) => {
el.pikadayInstance = new Pikaday({
field: el,
onSelect: () => {
@ohnotnow
ohnotnow / minio.service
Created March 3, 2018 18:19
Minio systemd for rpi
# /storage/.config/system.d/minio.service
[Unit]
Description=minio server
# if we do network mounts like here we *require* 'network-online.service'
# which checks if the network is online
Requires=network-online.service
# our scripts must start *after* 'network-online.service', on timeout and if
@ohnotnow
ohnotnow / app.js
Created May 24, 2018 14:33
csrf hackyness
document.addEventListener("DOMContentLoaded", function () {
setInterval(keepTokenAlive, 1000 * 60 * 15); // every 15 mins
function keepTokenAlive() {
axios.get('/keep-token-alive')
.then(response => {
let token = response.data.token;
window.axios.defaults.headers.common['X-CSRF-TOKEN'] = response.data.token;
const formFields = document.querySelectorAll('input[name="_token"]');
@ohnotnow
ohnotnow / SomethingBlewUp.php
Created July 27, 2018 16:00
Horrific mess slack laravel exception handler
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Messages\SlackMessage;