Skip to content

Instantly share code, notes, and snippets.

View irgmedeiros's full-sized avatar

Igor Medeiros irgmedeiros

View GitHub Profile
@irgmedeiros
irgmedeiros / workdays_delta.rb
Last active August 29, 2015 13:57
Finds the date shifted by 'days' workdays. (Accept negative numbers too)
def self.workdays_delta(days)
# Finds the date shifted by 'days' workdays.
current_day = Date.today
weekend = [6, 7]
counter = days.abs
while counter > 0
if days > 0
current_day += 1.day else current_day -= 1.day end
if not weekend.include? current_day.cwday and not Holiday.where(holiday_date: current_day).first
@irgmedeiros
irgmedeiros / Mechanize Login example
Created September 24, 2013 14:23
Exemplo de login em uma página com o a lib mechanize de Python.
import mechanize
import cookielib
br = mechanize.Browser()
browser = br
# Cookie Jar
cj = cookielib.LWPCookieJar()
br.set_cookiejar(cj)
@irgmedeiros
irgmedeiros / pairwise.py
Last active October 2, 2023 22:03
Implementation of adjusted cosine similarity
#-*- coding:utf-8 -*-
"""Utilities to evaluate pairwise distances or metrics between 2
sets of points.
Distance metrics are a function d(a, b) such that d(a, b) < d(a, c) if objects
a and b are considered "more similar" to objects a and c. Two objects exactly
alike would have a distance of zero.
One of the most popular examples is Euclidean distance.
To be a 'true' metric, it must obey the following four conditions::