Skip to content

Instantly share code, notes, and snippets.

View iamandrewluca's full-sized avatar
🚨
Git Inspector

Andrei Luca iamandrewluca

🚨
Git Inspector
View GitHub Profile
@Jakobud
Jakobud / _map-sort.scss
Last active June 20, 2022 14:50
Sort a SASS map
/// 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 {
@Jakobud
Jakobud / _list-sort.scss
Last active August 20, 2022 22:09
Sort a SASS list
/// 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);
@Jakobud
Jakobud / _list-remove.scss
Created April 25, 2017 20:12
Removed an item for a SASS list based on it's index (mimics behavior of the native map-remove function)
/// 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 {
@Jakobud
Jakobud / _linear-interpolation.scss
Last active February 21, 2023 18:40
Linear Interpolation SASS function
/// 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) {
@joseluisq
joseluisq / 1README.md
Last active January 3, 2022 13:22
Configure PHP Lumen 5 HTTP Exception Handlers with common JSON responses.

Lumen 5 HTTP Exception Handlers with JSON support.

Configure PHP Lumen 5 HTTP Exception Handlers with common JSON responses.

image

Setup

Copy (replace) only the attached files to their respective directories. app/Exceptions/Handler.php and app/Http/Middleware/Authenticate.php

@peggyrayzis
peggyrayzis / .babelrc
Last active February 7, 2019 03:31
Webpack 2 + PWA support (Tree Shaking, Code Splitting w/ React Router v4, Service Worker)
{
"presets": [
"react",
"stage-2",
[
"env",
{
"targets": {
"browsers": [
"last 2 versions",
@krstffr
krstffr / debounced-redux-thunk-action.js
Created December 16, 2016 12:04
Debouncing redux thunk actions.
// 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 });
@rchrd2
rchrd2 / test-php-basic-auth.php
Last active February 1, 2024 21:18 — forked from westonruter/test-php-basic-auth.php
PHP basic auth example
<?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
@jkulak
jkulak / git loglive
Created November 22, 2016 23:08
Display git log live
#!/bin/bash
while :
do
clear
git --no-pager log --oneline --decorate --all --graph --date=relative $*
sleep 2
done
@mhairston
mhairston / event-delegate.js
Created October 27, 2016 17:59
Event Delegation with Plain JavaScript
// 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;