Skip to content

Instantly share code, notes, and snippets.

@ShaneLee
ShaneLee / gist:5b5f3625274ef89438539432f30c2661
Created September 8, 2026 06:30
Github Dark iterm theme
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Background Color</key>
<dict>
<key>Blue Component</key>
<real>0.0901960784</real>
<key>Green Component</key>
<real>0.0666666667</real>
@ShaneLee
ShaneLee / gist:92846fe9b71d0a6a35f2653ee7b133c8
Created July 15, 2026 19:41
goodreads-bulk-shelf-deleter.py
"""
Bulk-delete custom Goodreads shelves.
HOW THIS WORKS
Goodreads' real shelf-management page lives at a fixed URL:
https://www.goodreads.com/shelf/edit
(paginated: ?page=2, ?page=3, ...)
Each deletable (non-default) shelf row on that page has a delete "x"
whose onclick handler fires a plain AJAX DELETE request:
@ShaneLee
ShaneLee / pom.xml
Last active March 5, 2022 16:13
Maven checkstyle
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>${checkstyle-maven-plugin.version}</version>
<configuration>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>${checkstyle.version}</version>
</dependency>
import subprocess, urllib, random
class NoBlocks(Exception): pass
def getblocks():
r = urllib.urlopen("http://{?REDACTED?}/grab").read()
if '<html' in r.lower(): raise NoBlocks
return r.split()
import sys
if len(sys.argv) > 1:
def get_expected_portfolio_return(porfolio):
return np.sum(portfolio['weight'] * porfolio['returns'])
expected_portfolio_return = get_expected_portfolio_return(portfolio)
final_value = expected_portfolio_return * PORTFOLIO_VALUE
print('Estimated value of Portfolio in {} : £{:,.2f} \nExpected Portfolio Return: {:,.2f}%').format(datetime.now().year + YEARS, final_value, expected_portfolio_return)
print('Estimated Income £{:,.2f}').format(final_value * 0.04)
def get_simulation(data):
# Get the logarithmic returns of the % change of prices from one trading day to the next.
log_returns = np.log(1 + data.pct_change())
# Get the mean of these returns
u = log_returns.mean()
# Get the variance of these returns
var = log_returns.var()
# Get the change in the average value of these values
drift = u - (0.5 * var)
# Get the standard deviation
def get_data(stock):
data = pd.DataFrame()
if stock['type'] == 'index':
data = wb.DataReader(stock['ticker'], 'stooq', start=START_DATE)['Close']
return get_simulation(data)
data = wb.DataReader(stock['ticker'], 'yahoo', start=START_DATE)['Adj Close']
return get_simulation(data)
def get_portfolio():
with open('portfolio.json', 'r') as portfolio_file:
portfolio_json = portfolio_file.read()
return json.loads(portfolio_json)['portfolio']
portfolio_data = get_portfolio()
portfolio = pd.DataFrame(portfolio_data).assign(returns = [get_data(stock) for stock in portfolio_data])
START_DATE = '2007-1-1' # Date from which we want to get the financial year.
YEARS = 40 # Years until retirement
DAYS_IN_YEAR = 253 # Average number of trading days in the year
PORTFOLIO_VALUE = 1000
# -*- coding: utf-8 -*-
from datetime import datetime
import json
import numpy as np
import pandas as pd
from pandas_datareader import data as wb
from scipy.stats import norm, gmean