Skip to content

Instantly share code, notes, and snippets.

View marlenesco's full-sized avatar

David Foliti marlenesco

View GitHub Profile
@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,
@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 / .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 / 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 / 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 / Entity-vs-Model.md
Last active October 8, 2022 22:41
Terminology in Symfony and Doctrine. Record vs Entity vs Document vs Model

I was just asked to write a small summary about the difference between a model and an entity. As I am too lazy to think up another topic for today I will just jump on that. And actually I wrote about this before as it can be quite irritating to see model folders in some bundles and entity folders in others. So what is what?

Before Doctrine 2.0 we were used to the ActiveRecord pattern in the symfony world. So let’s start from there.

The Record

is an object representation of a thing in the real world. It has some attributes that the real thing has as well (i.e. age, size, color, ..) and some methods the real thing can perform as well (i.e. walk, run, bark, ..).

The record in an ActiveRecord pattern also knows how to be persisted as it has a save() method and some other persistence related functionalities. To avoid duplicated code all this persistence code is written in a generic way and inherited by all record classes.

@marlenesco
marlenesco / put-object-on-aws-s3.php
Created May 30, 2018 15:18 — forked from keithweaver/put-object-on-aws-s3.php
Upload an image/object to an AWS S3 Bucket using PHP
<?php
// Installed the need packages with Composer by running:
// $ composer require aws/aws-sdk-php
$filePath = "https://example.com/test.png";
require 'vendor/autoload.php';
$bucketName = 'YOUR_BUCKET_NAME';
$filePath = './YOUR_FILE_NAME.png';
@marlenesco
marlenesco / DateUtils.php
Last active February 1, 2018 14:20
Get date range for week or month
<?php
/**
* Created by PhpStorm.
* User: david.foliti
* Date: 01/02/18
* Time: 11:46
*/
namespace CalendarDipBundle\Utils;
@marlenesco
marlenesco / text-strike.less
Last active January 23, 2018 14:25
Bootstrap text stripe
.text-stripe {
position: relative;
&:before {
position: absolute;
content: "";
left: -0.1em;
top: 50%;
right: -0.1em;
border-top: .09em solid;
@marlenesco
marlenesco / MacOSXSierra:Brew+Apache+Mysql+PHPSwitcher+DNSMasq+SSL.md
Created December 22, 2017 17:08 — forked from andrewstobbe/MacOSXSierra:Brew+Apache+Mysql+PHPSwitcher+DNSMasq+SSL.md
Mac OSX Sierra : Brew Apache + Mysql + PHP Switcher + DNSMasq + SSL

Mac OSX Sierra : Brew Apache + Mysql + PHP Switcher + DNSMasq + SSL 👍

Things I had to do using Homebrew to get my local web dev environment back up and running after migration to OSX Sierra + Xcode 8.1.

Note: I used brew reinstall because I had already installed most of this previously under Yosemite. Probably better ways to do this, but this is what worked for me.

brew doctor

brew tap homebrew/dupes
brew tap homebrew/versions