Configure PHP Lumen 5 HTTP Exception Handlers with common JSON responses.
Copy (replace) only the attached files to their respective directories. app/Exceptions/Handler.php
and app/Http/Middleware/Authenticate.php
/// map-sort | |
/// Sort map by keys | |
/// @param $map - A SASS map | |
/// @returns A SASS map sorted by keys | |
/// @requires function list-sort | |
/// @author Jake Wilson <jake.e.wilson@gmail.com> | |
@function map-sort($map) { | |
$keys: list-sort(map-keys($map)); | |
$sortedMap: (); | |
@each $key in $keys { |
/// list-sort | |
/// Sort a SASS list | |
/// @param $list - A SASS list | |
/// @returns A sorted SASS list | |
/// @requires function list-remove | |
/// @author Jake Wilson <jake.e.wilson@gmail.com> | |
@function list-sort($list) { | |
$sortedlist: (); | |
@while length($list) > 0 { | |
$value: nth($list,1); |
/// list-remove | |
/// Remove an item from a list | |
/// @param $list - A SASS list | |
/// @param $index - The list index to remove | |
/// @returns A SASS list | |
/// @author Jake Wilson <jake.e.wilson@gmail.com> | |
@function list-remove($list, $index) { | |
$newList: (); | |
@for $i from 1 through length($list) { | |
@if $i != $index { |
/// linear-interpolation | |
/// Calculate the definition of a line between two points | |
/// @param $map - A SASS map of viewport widths and size value pairs | |
/// @returns A linear equation as a calc() function | |
/// @example | |
/// font-size: linear-interpolation((320px: 18px, 768px: 26px)); | |
/// @author Jake Wilson <jake.e.wilson@gmail.com> | |
@function linear-interpolation($map) { | |
$keys: map-keys($map); | |
@if (length($keys) != 2) { |
Configure PHP Lumen 5 HTTP Exception Handlers with common JSON responses.
Copy (replace) only the attached files to their respective directories. app/Exceptions/Handler.php
and app/Http/Middleware/Authenticate.php
{ | |
"presets": [ | |
"react", | |
"stage-2", | |
[ | |
"env", | |
{ | |
"targets": { | |
"browsers": [ | |
"last 2 versions", |
// A common redux pattern when dealing with async functions is to use thunk. | |
// This usually means your action returns a new function instead of an action object, | |
// and the thunk middleware will make it all work. Example: | |
const asyncAction = () => dispatch => setTimeout(() => dispatch(someOtherAction()), 10000); | |
// Now: maybe that async stuff going on is calling some API which you don't want to overload | |
// with request, and that's what debounce is for. | |
// This is an example of a debounced function which will only be calleable once every second. | |
import { debounce } from 'lodash'; | |
const debouncedFn = debounce(() => callApi(), 1000, { leading: true, trailing: false }); |
<?php | |
function require_auth() { | |
$AUTH_USER = 'admin'; | |
$AUTH_PASS = 'admin'; | |
header('Cache-Control: no-cache, must-revalidate, max-age=0'); | |
$has_supplied_credentials = !(empty($_SERVER['PHP_AUTH_USER']) && empty($_SERVER['PHP_AUTH_PW'])); | |
$is_not_authenticated = ( | |
!$has_supplied_credentials || | |
$_SERVER['PHP_AUTH_USER'] != $AUTH_USER || | |
$_SERVER['PHP_AUTH_PW'] != $AUTH_PASS |
#!/bin/bash | |
while : | |
do | |
clear | |
git --no-pager log --oneline --decorate --all --graph --date=relative $* | |
sleep 2 | |
done |
// Event Delegation with Plain Javascript | |
// from Adam Beres-Deak | |
// http://bdadam.com/blog/plain-javascript-event-delegation.html | |
function on(elSelector, eventName, selector, fn) { | |
var element = document.querySelector(elSelector); | |
element.addEventListener(eventName, function(event) { | |
var possibleTargets = element.querySelectorAll(selector); | |
var target = event.target; |