Skip to content

Instantly share code, notes, and snippets.

View rafaeldo's full-sized avatar

Rafael de Oliveira rafaeldo

  • Freelancer
  • Brazil
View GitHub Profile
@rafaeldo
rafaeldo / generate-pushid.js
Created November 5, 2018 20:51 — forked from mikelehen/generate-pushid.js
JavaScript code for generating Firebase Push IDs
/**
* Fancy ID generator that creates 20-character string identifiers with the following properties:
*
* 1. They're based on timestamp so that they sort *after* any existing ids.
* 2. They contain 72-bits of random data after the timestamp so that IDs won't collide with other clients' IDs.
* 3. They sort *lexicographically* (so the timestamp is converted to characters that will sort properly).
* 4. They're monotonically increasing. Even if you generate more than one in the same timestamp, the
* latter ones will sort after the former ones. We do this by using the previous random bits
* but "incrementing" them by 1 (only in the case of a timestamp collision).
*/
const puppeteer = require('puppeteer');
const nodemailer = require('nodemailer');
class Webpage {
static async generatePDF(url) {
const browser = await puppeteer.launch({ headless: true }); // Puppeteer can only generate pdf in headless mode.
const page = await browser.newPage();
await page.goto(url, { waitUntil: 'networkidle', networkIdleTimeout: 5000 }); // Adjust network idle as required.
const pdfConfig = {
format: 'A4',
@rafaeldo
rafaeldo / router.js
Created October 24, 2018 18:02
Dynamic Load Component in Vue (Example)
import Vue from 'vue'
import Router from 'vue-router'
import Home from './views/Home.vue'
Vue.use(Router)
export default new Router({
mode: 'history',
base: process.env.BASE_URL,
routes: [
<template>
<v-container class="maiuscula">
<!-- CARREGANDO -->
<v-card>
<v-layout v-if="loading" row wrap>
<v-flex class="pa-3">
<span class="montserrat display-1">
CARREGANDO...
</span>
</v-flex>
<template>
<v-container class="pt-0">
<!-- Titulo -->
<HeaderSemLeitor :tipo="'retornar'" />
<!-- Corpo -->
<v-layout row wrap>
<v-flex
class="green lighten-4 borda-arredondada
borda-fina pa-4"
xs12 sm6 offset-sm3>
<template>
<v-container>
<v-card class="elevation-20">
<!-- Cabeçalho -->
<Cabecalho
@date="pegarData"
@cliente="pegarCliente" />
<!-- Movimentacao -->
<Movimentacao
@saldoVazio="atualizaSaldo"
@rafaeldo
rafaeldo / Componente.vue
Created July 30, 2018 19:25
Chamando um método no Template.
<template>
<div>
<div
v-for="item in carrosDoBackend">
{{ escreveCategoria(item.categoriaId) }}
</div>
</div>
</template>
<script>
// http://eslint.org/docs/user-guide/configuring
module.exports = {
root: true,
parser: 'babel-eslint',
parserOptions: {
sourceType: 'module'
},
env: {
browser: true,