Skip to content

Instantly share code, notes, and snippets.

View CristalT's full-sized avatar

Marcelo Forclaz CristalT

View GitHub Profile
@CristalT
CristalT / arrownav.js
Last active July 6, 2016 00:15
It allows navigate an HTML table by using keyboard arrows
$.fn.arrownav = function(options) {
var settings = $.extend({
focusOnLoad: true
}, options);
var curRow = this.children('tr:first-child'),
r=0;
if(settings.focusOnLoad) {
curRow.focus();
}
this.children('tr').click(function(){
@CristalT
CristalT / FileUploader.vue
Last active October 5, 2023 11:20
File Uploader Component for Vue.js using Firebase Storage
<template>
<div>
<input type="file" multiple accept="image/jpeg" @change="detectFiles($event.target.files)">
<div class="progress-bar" :style="{ width: progressUpload + '%'}">{{ progressUpload }}%</div>
</div>
</template>
<script>
@CristalT
CristalT / fbProductShare.js
Last active May 2, 2018 02:10
Cloud Function for Firebase for achive Share content in Facebook
const functions = require('firebase-functions')
const admin = require('firebase-admin')
admin.initializeApp()
const firestore = admin.firestore()
exports.fbProductShare = functions.https.onRequest((req, res) => {
const params = req.query
const ref = firestore.collection('products').doc(params.id).get()
ref.then(querySnapshot => {
const heros = [
{ label: 'Batman' },
{ label: 'Iron Man' },
{ label: 'Superman' },
{ label: 'Green Lantern' },
{ label: 'Cat Woman' },
{ label: 'Supergirl' },
{ label: 'Aquaman' }
]
// replicate an object excepting some items
const hero = {
name: 'Bruno',
alterego: 'Batman',
superpowers: false,
couching: 8
}
// Way one
const { couching, name, ...collection } = hero
// Two Ways To round a number at 2 decimals
const number = 19.5862365
// Way one
let result = Math.round(number * 100) / 100
console.log(result)
// Way two
result = parseFloat(number.toFixed(2)) // parseFloat() to keep number type
console.log(result)
// Two ways to remove array duplicates
const array = [1, 2, 3, 4, 4, 4, 5]
// Way 1
let uniq = array.filter((el, index) => array.indexOf(el) === index)
console.log(uniq)
// Way 2
uniq = [...new Set(array)]
console.log(uniq)
// Two ways to filter an Array of Objects
const heros = [
{ label: 'Batman' },
{ label: 'Iron Man' },
{ label: 'Superman' },
{ label: 'Green Lantern' }
]
const token = 'Superman'
// hypothetical undefined value
const name = undefined
// Way 1:
const firstName1 = name || 'Marcelo'
console.log(firstName1)
// Way 2:
const firstName2 = name ? name : 'Marcelo'
console.log(firstName2)
@CristalT
CristalT / QUploaderFirebaseExtension.js
Created April 12, 2019 04:38
Extension for QUploader component making it able to upload files throw Firebase Storage
import { QUploaderBase } from 'quasar'
export default {
props: ['refStorage'],
name: 'FirebaseUploader',
data () {
return {
uploading: '',
uploadTask: {}