Skip to content

Instantly share code, notes, and snippets.

View edvasqueza's full-sized avatar

Eduardo Vásquez edvasqueza

  • Banco Bice
  • Santiago, Chile
  • 00:51 (UTC -03:00)
View GitHub Profile
import { Injectable } from '@angular/core';
import { HttpEvent, HttpInterceptor, HttpHandler, HttpRequest, HttpResponse, HttpClient } from '@angular/common/http';
import { Observable, of, throwError, timer } from 'rxjs';
import { mergeMap } from 'rxjs/operators';
const interceptedUrls = [
{regex: /\/loans$/, method: 'GET', filename: 'summary.json', returnStatusCode: 200},
{regex: /\/loans\/\d+$/, method: 'GET', filename: 'detail.json', returnStatusCode: 200}
]
@edvasqueza
edvasqueza / bigqueryUpload.gs
Created June 15, 2021 18:21
Example App script to load current google sheet data to Bigquery
// You must activate Bigquery in Services: https://developers.google.com/apps-script/advanced/bigquery
const startRow = 1;
const startCol = 1;
const projectId = "gcp-projectId";
const datasetId = "dataset";
const writeDispositionSetting = "WRITE_TRUNCATE";
const sheetName = 'sheetName';
const tableId = "bq_table";
@edvasqueza
edvasqueza / cloudbuild.yaml
Created June 14, 2021 22:06
Cloudbuild for running a test database or any service required to run in the cloudbuild network
# Thanks to: https://github.com/GoogleCloudPlatform/cloud-builders/issues/376#issuecomment-594094378
steps:
# Runs postgresql
- name: gcr.io/cloud-builders/docker
id: boot-postgres
args: [ 'run', '-d', '--publish=5432:5432', '--env=POSTGRES_PASSWORD=postgres', '--network=cloudbuild', '--name=postgres', 'postgres:9.6-alpine', '-N', '500' ]
waitFor: [ '-' ]
# Wait until postgresql is available
- name: jwilder/dockerize:0.6.1
id: await-postgres
@edvasqueza
edvasqueza / gcphandler.py
Last active June 14, 2021 16:54
Python Custom log handler for Cloud Run GCP
class GCPHandler(logging.StreamHandler):
def emit(self, record):
try:
msg = self.format(record)
stream = self.stream
trace = None
global_log_fields = {}
if request and 'X-Cloud-Trace-Context' in request.headers.keys() and GCP_PROJECT:
trace_header = request.headers.get("X-Cloud-Trace-Context")
trace = trace_header.split("/")[0]
@edvasqueza
edvasqueza / function.ts
Created August 13, 2020 03:04
Launch Dataflow job from cloud function
import {google} from 'googleapis';
const gcsPath = process.env.TEMPLATE_GCS_PATH;
const projectId = process.env.GCP_PROJECT;
const numWorkers = process.env.NUM_WORKERS || 1;
const location = 'us-central1';
const zone = 'us-central1-a';
const runner = 'DataflowRunner';
const dataflowApiVersion = 'v1b3';
@edvasqueza
edvasqueza / vpn.expect
Last active January 18, 2018 22:41
expect script for activate checkpoint vpn without writing your password every time. You need to install the snx tool for using it. The sh file is optional, used to keep trying to connect if your first try fails. sudo ln -s /full/path/to/your/file /usr/local/bin/name_of_new_command
#!/usr/bin/expect
set timeout 10
log_user 0
send_user "desconectando si es que hay alguna sesion abierta\n"
spawn snx -d
expect {
timeout { exit 2 }
eof {
sleep 1
@edvasqueza
edvasqueza / ChileLocale.java
Last active August 21, 2023 02:11
Clase con ejemplos para imprimir números y fechas en formato Chileno
import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.NumberFormat;
import java.text.ParseException;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
/**
* Clase con ejemplos para imprimir números y fechas en formato Chileno