Skip to content

Instantly share code, notes, and snippets.

@gallir
gallir / related.py
Created September 2, 2021 22:46
Look at
@gallir
gallir / base.py
Created April 3, 2021 22:10
base covid
import pandas as pd
import time
from datetime import date
import pathlib
class Series(object):
def __init__(self, name, schema, start, end, freq, top=0, use_cache=False, flag=False):
self.df = None
self.name = name
@gallir
gallir / covid.py
Created April 3, 2021 22:08
covid prediction with fbprophet
#! /usr/bin/env python3
import pandas as pd
import pycountry
from datetime import date, timedelta
from fbprophet import Prophet
from concurrent.futures import ProcessPoolExecutor
from .base import Series
@gallir
gallir / forecast.py
Last active December 25, 2021 21:02
A basic pipeline for AWS Forecast
from botocore.hooks import _PrefixTrie
import util
import boto3
from .s3utils import upload_csv
import time
import pprint
class Pipeline:
def __init__(self, name, target, freq, horizon, s3_bucket, related=None, domain="RETAIL",
@gallir
gallir / text.py
Last active June 19, 2024 20:03
Very fast function to get cosine similarity between 2 short texts, where counting the number of words is no needed (i.e. binary bag of words) but it works pretty well with non-ascii weird characters.
from unidecode import unidecode
import re
import sys
import inflection
import numpy as np
import math
from collections import defaultdict
# Using cosine_similarity, own faster implementation, inspired by
# https://towardsdatascience.com/calculating-string-similarity-in-python-276e18a7d33a
@gallir
gallir / actor.go
Created August 20, 2016 21:48
an actor in go
package main
import "fmt"
var (
requestToActor chan int
responseFromActor chan int
)
const (
@gallir
gallir / cpuidle.go
Last active August 2, 2016 22:59
cpu idle updaters
func (broker *Broker) updateCPUIdle() {
select {
case broker.cpuUpdateChannel <- true:
default:
}
}
func (broker *Broker) cpuIdleUpdater() {
// Initial values required to get stats
minPeriod := 20 * time.Millisecond
@gallir
gallir / cache.go
Created August 2, 2016 22:21
A time serie cache
package main
import (
"sync"
"time"
)
type SerieElement struct {
ts time.Time
data *BookingData
@gallir
gallir / gist:05be611db38c6beec310
Created January 24, 2016 12:22
zmq_sendmessage.go
func (soc *Socket) sendMessage(dontwait Flag, parts ...interface{}) (total int, err error) {
// TODO: make this faster
// Done, ;)
var partial int
// Pop the last empty slices
popempty:
for i := len(parts) - 1; i >= 0; i-- {
switch tLast := parts[i].(type) {
case []string:
@gallir
gallir / ties3.py
Created December 28, 2015 17:49
Como https://gist.github.com/gallir/ca8d6cb958bd7767938f pero el sesgo de cada persona cambia con cada elección
#! /usr/bin/env python
import numpy.random as npr
SIZE=3030
LOOP=1000000
TIE=SIZE/2
ties=0