Skip to content

Instantly share code, notes, and snippets.

View tiagolisalves's full-sized avatar
🏠
Working from home

Tiago Lisalves tiagolisalves

🏠
Working from home
View GitHub Profile
@tiagolisalves
tiagolisalves / command-executor.ts
Last active October 17, 2020 01:38
Execute a command on node in an async and colorful way
import colors from 'colors'; //npm install --save colors
import { spawn } from 'cross-spawn'; //cross-platform spawn
import path from 'path';
interface CommandOptions {
command: [string, string];
errorMessage: string;
cwd: string;
}
@tiagolisalves
tiagolisalves / generate-type.js
Last active January 14, 2019 15:30
A way to protect against "Cannot read property 'x' of undefined" in javascript. Includes an utility for generate the type of the object.
var obj = {
list1: [1, 2],
name: 'Paul',
single: false,
children: {
mary: 'female'
}
};
console.log(obj.list1.constructor.name);
import { Component } from '@angular/core';
import { Produto } from './produto';
@Component({
selector: 'app-produto',
templateUrl: './produto.component.html'
})
export class ProdutoComponent {
produto: Produto;
mostra: Boolean;
Nome do produto: {{produto.nome}}
<p>
Nome do Produto:
<!-- <input type="text" [value]="produto.nome"> Apenas altera o valor do elemento html -->
<!-- <input type="text" [value]="produto.nome" (input)="produto.nome=$event.target.value"> -->
<input type="text" [(ngModel)]="produto.nome" name="nome">
</p>
<p>
public class VinhoBC extends DelegateCrud<Vinho, Long, VinhoDAO>{
private static final long serialVersionUID = 1L;
public List<VinhoDTO> obtemVinhos() {
List<Vinho> vinhos = findAll();
List<VinhoDTO> vinhosDTO = new ArrayList<>();
for (Vinho vinho : vinhos) {
package br.gov.serpro.vinhos.dto;
import java.math.BigDecimal;
import br.gov.serpro.vinhos.entity.Vinho;
public class VinhoDTO {
private Long id;
private BigDecimal valorPago;
private String nome;
@tiagolisalves
tiagolisalves / distanceBetweenCities.py
Last active November 18, 2017 22:13
Calculate distance between 2 cities using Haversine Formula and Google Geocoding API
"""
We need argparse, math & requests libs to run this program. We must install requests lib via pip:
pip install requests
"""
import argparse
import requests
from math import *
#put your google api key here