Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View bjpcjp's full-sized avatar
💭
Fully caffeinated for your safety

brian piercy bjpcjp

💭
Fully caffeinated for your safety
View GitHub Profile
@bjpcjp
bjpcjp / gist:73c9f2048fe174ec335c891815731778
Created July 30, 2020 12:10
Rails 6.0.2.3 - test failure out-of-the-box
# Rails 6.0.2.3
# 'Behavior' = std Rails scaffold with one name:string attribute.
# rails db:migrate = no problem.
# rails test = 2 fails below. other controllers (~60, identical except for object name) pass.
Error:
BehaviorsControllerTest#test_should_destroy_behavior:
NoMethodError: undefined method `count' for ActionDispatch::IntegrationTest::Behavior:Module
test/controllers/behaviors_controller_test.rb:42:in `block in <class:BehaviorsControllerTest>'
test/controllers/behaviors_controller_test.rb:42:in `block in <class:BehaviorsControllerTest>'
@bjpcjp
bjpcjp / approximate_nearest_neighbors.py
Created April 1, 2021 19:38
https://scikit-learn.org example - approximate_nearest_neighbors.py
# Author: Tom Dupre la Tour
#
# License: BSD 3 clause
import time
import sys
try:
import annoy
except ImportError:
print("The package 'annoy' is required to run this example.")
@bjpcjp
bjpcjp / metrics.py
Created January 15, 2022 18:06 — forked from bfan1256/metrics.py
5 Performance Metrics for Trading Algorithms and Investment Portfolios
from blankly import Alpaca, CoinbasePro # supports stocks, crypto, and forex
import numpy as np
from math import sqrt
def cagr(start_value: float, end_value: float, years: int):
return (end_value / start_value) ** (1.0 / years) - 1
def sharpe(account_values: np.array, risk_free_rate, annualize_coefficient):
diff = np.diff(account_values, 1) / account_values[1:] # this gets our pct_return in the array
@bjpcjp
bjpcjp / example.sh
Created October 29, 2022 01:00
shell script best practices template
#!/usr/bin/env bash
# source: https://sharats.me/posts/shell-script-best-practices/
set -o errexit
set -o nounset
set -o pipefail
if [[ "${TRACE-0}" == "1" ]]; then
set -o xtrace
fi