Skip to content

Instantly share code, notes, and snippets.

View base.py
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 Apr 3, 2021
covid prediction with fbprophet
View covid.py
#! /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 Apr 3, 2021
A basic pipeline for AWS Forecast
View forecast.py
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 Apr 12, 2020
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.
View text.py
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 Aug 20, 2016
an actor in go
View actor.go
package main
import "fmt"
var (
requestToActor chan int
responseFromActor chan int
)
const (
@gallir
gallir / cpuidle.go
Last active Aug 2, 2016
cpu idle updaters
View cpuidle.go
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 Aug 2, 2016
A time serie cache
View cache.go
package main
import (
"sync"
"time"
)
type SerieElement struct {
ts time.Time
data *BookingData
View gist:05be611db38c6beec310
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 Dec 28, 2015
Como https://gist.github.com/gallir/ca8d6cb958bd7767938f pero el sesgo de cada persona cambia con cada elección
View ties3.py
#! /usr/bin/env python
import numpy.random as npr
SIZE=3030
LOOP=1000000
TIE=SIZE/2
ties=0
@gallir
gallir / ties2.py
Created Dec 28, 2015
Como https://gist.github.com/gallir/18f1adea5bd5c628813d pero cada persona tiene un sesgo que afecta a su elección
View ties2.py
#! /usr/bin/env python
""" Execute it several times to vary the biases,
which can be biased too
"""
import numpy.random as npr
SIZE=3030
LOOP=1000000