Skip to content

Instantly share code, notes, and snippets.

View marlenesco's full-sized avatar

David Foliti marlenesco

View GitHub Profile
@marlenesco
marlenesco / just-do-pattern.php
Last active September 21, 2018 15:10
ZipCode pattern generator
<?php
$patterns = [];
$data = json_decode(file_get_contents('http://i18napis.appspot.com/address/data'), true);
$countries = explode('~', $data['countries']);
foreach ($countries as $country) {
$data = json_decode(file_get_contents('http://i18napis.appspot.com/address/data/'.$country), true);
if (isset($data['zip'])) {
$patterns[$country] = $data['zip'];
}
@marlenesco
marlenesco / back_forward.js
Created April 10, 2020 14:25 — forked from sstephenson/back_forward.js
How to detect whether a hash change came from the Back or Forward button
var detectBackOrForward = function(onBack, onForward) {
hashHistory = [window.location.hash];
historyLength = window.history.length;
return function() {
var hash = window.location.hash, length = window.history.length;
if (hashHistory.length && historyLength == length) {
if (hashHistory[hashHistory.length - 2] == hash) {
hashHistory = hashHistory.slice(0, -1);
onBack();
@marlenesco
marlenesco / .gulp-completion.sh
Created June 12, 2020 14:31 — forked from leventebalogh/.gulp-completion.sh
Fast Gulp auto completion
# Adds basic, but really fast autocompletion for gulp.
#
# NOTE!
# Only the tasknames will be autocompleted.
#
# Why?
# ----
# Default gulp completion is really-really slow, hard to work with.
# However this solution is quite dump, it covers 90% of my workflow.
#
@marlenesco
marlenesco / grafana-dashboard-exporter
Created March 10, 2021 01:18 — forked from crisidev/grafana-dashboard-exporter
Command to export all grafana 2 dashboard to JSON using curl
KEY=XXXXXXXXXXXX
HOST="https://metrics.crisidev.org"
mkdir -p dashboards && for dash in $(curl -k -H "Authorization: Bearer $KEY" $HOST/api/search\?query\=\& |tr ']' '\n' |cut -d "," -f 5 |grep slug |cut -d\" -f 4); do
curl -k -H "Authorization: Bearer $KEY" $HOST/api/dashboards/db/$dash > dashboards/$dash.json
done
@marlenesco
marlenesco / put.js
Last active August 9, 2023 13:15
Storage class for aws-sdk v3, use it in node adn serverless app
// locate the storage class in your application
const storage = require('../path-to/storage');
module.exports = async (body, key) => {
try {
//using that class to put object in s3
await storage.put(
process.env.ASSETS_BUCKET,
key,
body,