Skip to content

Instantly share code, notes, and snippets.

View wafs's full-sized avatar
🦍

wafs

🦍
  • Sydney, Australia
View GitHub Profile
@wafs
wafs / FindOrFail.ts
Last active December 23, 2018 02:25
Type safe FindOrfail implementation in typescript
// Takes an array of data, then a comparator, then returns a function that will search for the item given some key
const finder = <T>(arr: T[]) =>
<K>(comparator: (key: K, item: T) => boolean) =>
(key: K) => arr.find(v => comparator(key, v));
// Wraps the input function to throw on undefined while keeping it type safe
const throwOnUndefined = <F extends Function>(f: F): F => {
return <any>function (...args: any[]): F {
@wafs
wafs / jquery_overlay_demo.html
Created July 14, 2016 14:16
Jquery overlay that works with any obnoxious framework (so long as have no need to maintain the overlay's state)
<style>
#background-overlay {
cursor: zoom-out;
position: fixed;
top: 0;
left: 0;
background-color: rgba(0, 0, 0, 0.75);
width: 100%;
height: 100%;
z-index: 1000;
@wafs
wafs / Select2 + Bindjs helper
Created October 30, 2015 10:07
If you're trying to bind a select box and you have select2 implemented, you're gonna have a bad time. Do this and it should fix most things with select dropdowns.
// Helper for Select2, since bind.js uses input events and select2 uses onchange.
var inputChangeEvent = new Event('input');
$('select').on("select2:select", function(e){
e.currentTarget.dispatchEvent(inputChangeEvent);
});
@wafs
wafs / BladeExtensionServiceProvider.php
Last active November 10, 2016 10:49
Set variables in blade without having them echo out
<?php namespace App\Providers;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
class BladeExtensionServiceProvider extends ServiceProvider {
/**
* Bootstrap the application services.
*