SSH tunneling and port forwarding snippets and utils
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from scipy.optimize import minimize | |
def no_sell_reallocate(x, t, desired_spend=None, names=None): | |
""" | |
Optimally (I hope so) realign the current values of investments x to some | |
portfolio target allocation t, with the limitation that you cannot reduce the | |
amount of any current investment (i.e. you can't sell). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1. pip show pandas | |
# 2. nano <Location path>/pandas/__init__.py | |
# Paste the following at the bottom of the file | |
set_option("display.max_columns", None) | |
set_option("display.width", 100000) | |
set_option("display.min_rows", 20) | |
set_option("display.max_rows", 20) | |
# Loads better pandas defaults everytime |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Insane Django operation I had to do | |
# Inspired by: https://stackoverflow.com/a/70552577/8927098 | |
# Need to filter for a date, but source table date is in UTC and it's separated into date and time fields | |
# Example: | |
# Date to find (America/New_York): 2005-09-08 | |
# Date in table (UTC): 2005-09-09 | |
# Time in table (UTC): 01:07:00 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import PyPDF2 | |
from PyPDF2 import PdfFileReader, PdfFileWriter | |
from PyPDF2.generic import StreamObject, DecodedStreamObject | |
from PyPDF2 import filters | |
# You change the phrases/text you want redacted and the file paths: | |
phrases = ["123-45-6789", "YOUR_SECRET_PASSWORD", "YOUR_SECRET_ID"] | |
read_path = "/path/to/yourpdf.pdf" | |
write_path = "/path/to/yourpdf-redacted.pdf" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Keras Sequence | |
import os | |
import tempfile | |
from itertools import product | |
import numpy as np | |
from random import shuffle | |
import time | |
import sys | |
f_rows = 30000 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ssh [email protected] -t 'tmux new-session -d "sleep 20"' | |
# or change "sleep 20" --> "python my_time_consuming_python_script.py" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
def pt(x): | |
x = int(x) | |
for i in range(2, math.floor(math.sqrt(x))): | |
if x % i == 0: | |
return False | |
return True | |
def checker(left=None, res=None): |
From terminal run jupyter qtconsole &
# Start ipython terminal
In python: %matplotlib qt5
Then when using cerebro.plot
make sure iplot kwarg is False (i.e. cerebro.plot(iplot=False)
).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from io import BytesIO | |
import matplotlib.pyplot as plt | |
import base64 | |
b = BytesIO() | |
plt.plot([1,2,3]) | |
plt.savefig(b) | |
b64_img_str = base64.encodebytes(b.getvalue()).decode() | |
# In js | |
# $("#graph1").attr("src", "data:image/png;base64, ".concat(b64_img_str)); |
NewerOlder