Skip to content

Instantly share code, notes, and snippets.

View markusand's full-sized avatar

Marc Vilella markusand

View GitHub Profile
@markusand
markusand / cache-proxy.php
Created December 25, 2018 20:23
Simple cache proxy to throttle queries to APIs, for example to darksky.net
<?php
/* Cache proxy for darksky.net API requests */
define('API_KEY', '***********************');
define('TIMEOUT', 10 * 60); // In seconds (10 minutes)
// Coordinates MUST be the first element in URL as https://api.server.io/v1/weather/[LAT,LON]
$params = explode('/', trim($_SERVER['PATH_INFO'], '/'));
$coords = filter_var(array_shift($params), FILTER_SANITIZE_STRING);
// Validate coordinates
@markusand
markusand / drop-file.directive.js
Created December 24, 2018 16:54
Vue.js directive to trigger an event when a file is dropped on an element
export default {
bind(el, bindings) {
el.dragEvents = ['dragenter', 'dragover', 'dragleave', 'drop'];
el.dragEvents.forEach(dragEvent => {
el.addEventListener(dragEvent, (event) => {
if (!el.classList.contains(dragEvent)) {
el.classList.remove(...el.dragEvents);
el.classList.add(dragEvent);
}
event.preventDefault();
@markusand
markusand / directive.confim.js
Last active January 21, 2021 13:38
Vue.js directive to assign a confirmation to an element before triggering an action
export default {
bind(el, binding) {
const { value: { msg, callback } } = binding;
el.ask = () => {
if (confirm(msg)) callback();
};
el.addEventListener('click', el.ask);
},
unbind(el) { el.removeEventListener('click', el.ask); }
};
@markusand
markusand / directive.scroll.css
Last active January 21, 2021 13:40
Vue.js directive to show (or animate) elements when scrolled
.scroll-show {
opacity: 0;
transition: all 0.5s ease-in-out;
}
.scroll-show-enter { opacity: 1; }
@markusand
markusand / .eslintrc.js
Last active February 11, 2019 15:13
Custom eslint rules to override some AirBnB's defaults
rules: {
'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
'no-tabs': 'off',
'indent': ['error', 'tab', {
'SwitchCase': 1
}],
'max-len': ['error', {
'code': 100,
'ignoreTrailingComments': true,