Skip to content

Instantly share code, notes, and snippets.

View leobessa's full-sized avatar

Leonardo Bessa leobessa

View GitHub Profile
@anthonytxie
anthonytxie / hodl20.py
Created March 24, 2018 21:01
Hodl 20 Rebalancing Algorithm
def calc_allocations(self, date, quantity, cap):
"""Figure out ideal allocations for a given date"""
# {
# coin_name: (percent_allocation, data)
# }
top_market = self.get_top_market(date, quantity)
total_cap = sum([coin.market_cap for coin in top_market])
allocations = [{
@agarrharr
agarrharr / index.md
Last active August 25, 2024 01:19
Common Ledger CLI Commands

Common Ledger CLI Commands

  • Income vs expenses this month?

    $ ledger balance income expenses --period "this month"
  • What did my budget look like at a certain date?

@mmcc
mmcc / authed_conn_case.ex
Last active October 26, 2023 00:05
Elixir test macros
defmodule AppWeb.AuthConnCase do
alias AppWeb.Router
use ExUnit.CaseTemplate
import Phoenix.ConnTest, only: [dispatch: 5, json_response: 2]
@doc """
Allows you to call the same set of tests with the same describe block
Setups is an array of named setups, i.e. [first_setup: [:setup_conn, :thing], second_setup: [:different_setup, :neato_setup]]
## Examples
@slapers
slapers / workflow_graph.exs
Created November 18, 2017 18:19
Build a direct acyclic graph to run a simple workflow in elixir
defmodule WorkStep do
defstruct [:name, :in, :out, :mod, :fun, :arg]
require Logger
def add_to_graph(%Graph{} = graph, %__MODULE__{} = step) do
graph
|> Graph.add_vertex(step)
|> Graph.add_edges(step |> edges_in)
|> Graph.add_edges(step |> edges_out)
end
@egaleme
egaleme / gist:7b4d35334bb1f926422f8210b5b85fab
Last active September 2, 2021 21:47
How to create a user authentication systems with email verification in phoenix framework
# How to create a user authentication systems with email verification in phoenix framework.
Phoenix Framework is built with the powerful and resilient programming language called Elixir Lang. It is gaining momentunm by the day thanks to it's expressive sytanx which makes you productive and it's built upon the shoulders of the Erlang vm called BEAM which makes your code performant.
Here will build a user registration with Email verification and a login systems. Phoenix framework can be used to build normal html 5 crud apps, json api and real time backends. We'll be building a real time backend using Phoenix channels and an Elixir library Guardian jwt.
You can find installation instructions on the [Elixir site](http://elixir-lang.org) and [Phoenix framework](http://phoenixframework.org) .
We be using Phoenix 1.3 which is the current version.
@danielberkompas
danielberkompas / scheduler.ex
Created October 26, 2016 17:59
A simple mix task scheduler for Elixir apps
defmodule MyApp.Scheduler do
@moduledoc """
Schedules a Mix task to be run at a given interval in milliseconds.
## Options
- `:task`: The name of the Mix task to run.
- `:args`: A list of arguments to pass to the Mix task's `run/1` function.
- `:interval`: The time interval in millisconds to rerun the task.
@renatomefi
renatomefi / gen-jwt-rsa-keys.sh
Last active May 28, 2019 08:29
Generate RS256 JWT keys to use at jwt.io
#!/bin/bash
# This will write private.pem and public.pem in the current directory
# The default key strenght is 2048 bits
# usage:
# # ./gen-jwt-rsa-keys.sh mykey
# # ls
# gen-jwt-rsa-keys.sh mykey-private.key mykey-public.pem
# first time you have to give execution permission or use bash and the filename
# # chmod +x gen-jwt-rsa-keys.sh
KEYNAME=${1:-jwtrsa}
@jorgedavila25
jorgedavila25 / elastic_search_connection.rb
Last active March 11, 2020 14:03
Using Ruby's ElasticSearch gem that uses Kaminari for pagination and the Ruby GraphQL gem, this is a custom connection to bypass additional pagination. This assumes that you've already queried the correct paginated records from ElasticSearch and you're returning an `Elasticsearch::Model::Response` object.
class ElasticSearchConnection < GraphQL::Relay::BaseConnection
def has_next_page
!nodes.last_page?
end
def has_previous_page
!nodes.first_page?
end
def cursor_from_node(node)
@aborruso
aborruso / updatefile.sh
Last active November 27, 2024 22:03
How to update a file in github via cURL
#!/bin/bash
cartella="/var/myfolder"
# update the file
curl -i -X PUT -H 'Authorization: token 4d013330xxxxxxxxxxxxxx' -d "{\"path\": \"mattei.csv\", \
\"message\": \"update\", \"content\": \"$(openssl base64 -A -in $cartella/mattei.csv)\", \"branch\": \"master\",\
\"sha\": $(curl -X GET https://api.github.com/repos/username/repo/contents/mattei.csv | jq .sha)}" \
https://api.github.com/repos/username/repo/contents/mattei.csv