Skip to content

Instantly share code, notes, and snippets.

View pdaug's full-sized avatar

Pedro Augusto pdaug

View GitHub Profile
@StevenMaude
StevenMaude / tfidf_features.py
Created July 21, 2014 13:35
Do TF-IDF with scikit-learn and print top features
#!/usr/bin/env python
# encoding: utf-8
import codecs
import os
import sys
import numpy as np
from sklearn.feature_extraction.text import TfidfVectorizer
@brokeyourbike
brokeyourbike / cloud-functions-static-outbound-ip.md
Last active April 21, 2024 00:50
Cloud functions static outbound IP address

Cloud functions static outbound IP address

The guide inspired by Static outbound IP address for Cloud Run.

1. Find the name of your VPC network:

gcloud compute networks list
const shorten_names = {
"deviceId": "did"
,"tid": "id"
,"in1": "in1"
,"in2": "in2"
,"in3": "in3"
,"out1": "out1"
,"blocked": "out1" // realocation
,"out2": "out2"
,"out3": "out3"
<html>
<head>
<script src='http://35.209.36.199:8080/client/js-yaml.min.js'></script>
<script type='module'>
import { getUpdates } from 'http://35.209.36.199:8080/client/getUpdates.mjs';
let now = new Date().getTime();
function print( obj ) {
console.log("Total elements: ", obj.length);
console.log("seconds processing: ",(new Date().getTime() - now)/1000);
/* UTILS AND CONSTANTS*/
const SPEED_MULTIPLIER = 1.852;
const DISTANCE_MULTIPLIER = 111.045;
const SETTINGS = {
"default_object_online_timeout": 5
,"valid_by_avg_speed": false
,"min_moving_speed": 6
,"addon.device_tracker_app_login": false
@tcha-tcho
tcha-tcho / gist:ee166789bd892970df9c5de440f4c832
Last active July 12, 2024 18:18
Real time fixando valor
let yamldata = {
t: newdata.t
,dt: newdata.dt
,ft: newdata.ft
,spd: newdata.spd
,lat: newdata.lat || 0
,lng: newdata.lng || 0
,ang: newdata.ang
,stp: newdata.stp
,ign: newdata.ign
@eoguvo
eoguvo / parseFirebaseSnapshot.ts
Last active June 5, 2024 14:38
transform the crazy firebase output in a generic type, the way it should be since the init
import { DocumentData, DocumentSnapshot, QuerySnapshot } from "firebase-admin/firestore";
type withDocId<T> = T & { docId: string }
type SingleDocument = DocumentSnapshot<DocumentData>;
type QueryDocuments = QuerySnapshot<DocumentData>;
type Snapshot = SingleDocument | QueryDocuments;
type SnapshotNullable = Snapshot | null;
const checkSingle = (snapshot: Snapshot): snapshot is SingleDocument => {
@eoguvo
eoguvo / getDateRangeFromPresets.ts
Last active August 9, 2024 18:02
transform preset date ranges (the morning of yesterday) into timestamp dates
import { subDays, format, parse, startOfWeek, addWeeks, startOfMonth, subMonths, subWeeks, addMonths, addDays } from "date-fns";
import { ReportFields } from "../WindowDeviceReport.asset";
const getDateRangeFromPresets = function ({ range, timeRange, startTime: customStartTime, endTime: customEndTime, customRange }: ReportFields) {
const rangeToOffset = {
today: [new Date(), new Date()],
yesterday: [subDays(new Date(), 1), subDays(new Date(), 1)],
two_days_ago: [subDays(new Date(), 2), subDays(new Date(), 2)],
three_days_ago: [subDays(new Date(), 3), subDays(new Date(), 3)],
import { isNumeric } from "@core/Utils/index";
const DateDuration = function (milliseconds?: number, hasSeconds = true, hasMinutes = true): string {
if (!milliseconds) {
return "0s";
}
if (milliseconds <= 0 || milliseconds === Infinity) {
return "0s";
}