This file contains 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 collections import defaultdict | |
from dataclasses import dataclass | |
inf = float("inf") | |
# Married filing jointly standard deduction | |
# https://apps.irs.gov/app/vita/content/00/00_13_005.jsp?level=basic | |
standard_deduction = 30_000 | |
# NJ joint filing tax brackets |
This file contains 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
pv_export_long_history = '~/Downloads/pv_export_long_history.csv' | |
overrides = { | |
'RSBY': 'LCSIX', | |
'LCDS': 'DFSVX', | |
'MCDS': 'VOE', | |
'SCDS': 'SPYV', | |
'NIXT': 'SPY', | |
'EZBC': cash, | |
'SPYU': 'UPRO', | |
'MFUT': 'ASFYX', |
This file contains 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
#!/usr/bin/env node | |
import { Configuration as OpenAIConfig, OpenAIApi, ChatCompletionRequestMessageRoleEnum as Role } from 'openai' | |
const OPENAI_API_KEY = '?????' | |
const openai = new OpenAIApi(new OpenAIConfig({apiKey: OPENAI_API_KEY})) | |
const task = openai.createChatCompletion({ | |
model: 'gpt-3.5-turbo-0613', | |
max_tokens: 2048, |
This file contains 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 {ChatCompletionRequestMessageRoleEnum as Role, OpenAIApi} from "openai"; | |
import {Configuration as OpenAIConfig} from "openai/dist/configuration.js"; | |
const OPENAI_API_KEY = 'XXXXXXXXXXXXXX' | |
const openai = new OpenAIApi(new OpenAIConfig({apiKey: OPENAI_API_KEY})) | |
const ask = (query) => { | |
return openai.createChatCompletion({ | |
model: 'gpt-3.5-turbo', | |
max_tokens: 2048, |
This file contains 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
// A simply port of Google Task's recurring task scheduler to Scala 3 ADT: | |
// https://tasks.google.com/embed/?origin=https://calendar.google.com&fullWidth=1 | |
import java.time._ | |
enum Cadence: | |
case Daily | |
case Weekly(on: Set[DayOfWeek] = Set(DayOfWeek.SUNDAY)) | |
case Monthly(on: Set[DayOfMonth] = Set(DayOfMonth.Day(1))) | |
case Yearly(on: Set[MonthDay] = Set(MonthDay.of(1, 1))) |
This file contains 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 squants.Dimensionless | |
import squants.DimensionlessConversions._ | |
import squants.market._, MoneyConversions._ | |
case class CreditCard(name: String, points: Dimensionless, checkingAPR: Dimensionless) { | |
def charge(amount: Money, fee: Dimensionless = 0 percent, flatFee: Money = 0 dollars): String = { | |
val fees = amount*fee + flatFee | |
val interestEarned = amount * checkingAPR/12 | |
val cashBack = (amount + fees)*points | |
val saved = cashBack - interestEarned - fees |
This file contains 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 shapeless._, syntax.singleton._, record._, ops.hlist._ | |
/** | |
* Given an instance A and it's generic representation AR and function f from AR => BR | |
* we can covert A to B if we also have the generic representation of BR as B | |
* We also handle misalignments using shapeless's align typeclass (https://stackoverflow.com/questions/29242873/shapeless-turn-a-case-class-into-another-with-fields-in-different-order) | |
*/ | |
case class Morph[A, AR](a: A)(implicit reprA: LabelledGeneric.Aux[A, AR]) { | |
// Why this DSL you say? Hack to get around scalac idiocy: https://stackoverflow.com/a/46614684/471136 | |
def to[B] = new { |
This file contains 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 java.io.InputStream | |
import better.files._ | |
import squants.information._, InformationConversions._ | |
object GzipSplitter { | |
/** Splits the $inputstream into approximately equal chunks of $splitSize gzip files under $outputDirectory */ | |
def split( | |
inputStream : InputStream, | |
outputDirectory : File = File.newTemporaryDirectory(), |
This file contains 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 java.nio.charset.{ Charset, StandardCharsets } | |
import org.apache.spark.sql._ | |
import org.apache.spark.sql.types._ | |
object SparkDataLoad { | |
def fromCsv[A : Encoder]( | |
path: Set[String], | |
encoding: Charset = StandardCharsets.UTF_8, | |
useHeader: Boolean = false, |
This file contains 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
/** Distance between 2 coordinates (in degrees) */ | |
def dist( | |
p1: (Double, Double), // Coordinate 1 (in degrees) | |
p2: (Double, Double), // Coordinate 2 (in degrees) | |
manhattanDist: Boolean = false, // If true, calculate Manhattan distance on the sphere :) | |
diameter: Double = 7917.5 // Diameter of Earth in miles; set this to whatever planet/units you want | |
): Double = { | |
import Math._ | |
def haversine(theta: Double) = (1 - cos(theta))/2 |
NewerOlder