Skip to content

Instantly share code, notes, and snippets.

View alexandremcosta's full-sized avatar

Alexandre Marangoni Costa alexandremcosta

View GitHub Profile
@alexandremcosta
alexandremcosta / LICENSE
Last active June 1, 2024 19:41
Dollar cost average stocks based on Yahoo Finance API
MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all

Design Document

How to read this?

  • Merged
  • Review Required

For additional information, check this presentation.

Summary of Pull Requests

Reward system

A company is planning a way to reward customers for inviting their friends.
They're planning a reward system that will give a customer points for each confirmed invitation they played a part into.
The definition of a confirmed invitation is one where another invitation's invitee invited someone.

The inviter gets (1/2)^k points for each confirmed invitation, where k is the level of the invitation:

  • level 0 (people directly invited) yields 1 point
  • level 1 (people invited by someone invited by the original customer) gives 1/2 points
  • level 2 invitations (people invited by someone on level 1) awards 1/4 points and so on
@alexandremcosta
alexandremcosta / test.md
Last active May 4, 2021 22:33
export to html
@alexandremcosta
alexandremcosta / downloader.ex
Last active October 23, 2023 13:05
Stream HTTP body with Elixir Mint
defmodule Downloader do
@moduledoc"""
Download streams of bytes from URLs.
Useful to transfer large files with low RAM usage.
## Example with `ExAWS.S3.upload/3`
```elixir
url
|> Downloader.stream_body!()
@alexandremcosta
alexandremcosta / migrate_redis.ex
Created August 15, 2019 08:34
Elixir Redis Migration Script (dump/restore)
defmodule MigrateRedis do
require Logger
@from [host: "127.0.0.1", port: 6379]
@to [host: "127.0.0.1", port: 6379]
def migrate(from \\ @from, to \\ @to) do
{:ok, from} = Redix.start_link(from)
{:ok, to} = Redix.start_link(to)
@alexandremcosta
alexandremcosta / earth_interpolation.rb
Created May 8, 2018 19:53
Inverse Distance Weighted (IDW) Interpolation on Earth Surface in Ruby
class Weather::Interpolation
def initialize(x, y, z, xi, yi)
@x, @y, @z, @xi, @yi = x, y, z, xi, yi
end
def calc
# if any location closer than 10km, return this location
close_location = distances.index {|d| d < 10}
close_location ? @z[close_location] : interpolation
end
######################################################
# Tree Variables #####################################
# number of edges 4
# edge flows [0, 0, 0, 0, 10.0, 5.0, -0.0, -0.0]
# node potentials [10752.0, -5376.0, -5376.0, -5376.0]
# parent nodes [0, 1, 2, 3]
# edges to parents [4, 5, 6, 7]
# subtree sizes [1, 1, 1, 1]
# next nodes in dfs thread [0, 1, 2, 3]
# previous nodes in dfs thread [0, 1, 2, 3]
@alexandremcosta
alexandremcosta / component.js
Created September 25, 2017 14:50
component.vue
<script>
import YieldService from '@/services/yieldService'
export default {
name: 'portfolio-summary',
props: ['farms'],
methods: {
totalArea: function () {
return this.farms.reduce((a, b) => a + b.areaUsed, 0)
},
import pandas as pd
import scipy.stats as st
import pylab as pl
import math
# Download dataframe
url = "https://archive.ics.uci.edu/ml/machine-learning-databases/statlog/shuttle/shuttle.tst"
df = pd.read_csv(url, header=None, delimiter=' ')
# From http://odds.cs.stonybrook.edu/shuttle-dataset/