Instantly share code, notes, and snippets.

Focusing

# David Boland debpu06

Focusing
Created October 1, 2023 00:03
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
 def q6(): #Starting point eps = .000001 #specify the convergence criteria #Step 1: initial guess x0 x0=0 #Step 2: compute x1 by applying the function def BR(q): #this is our function of interest return 1+0.1*q
Created October 1, 2023 00:02
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 matplotlib.backends.backend_pdf import PdfPages %matplotlib inline def inverse_supply(quantity): '''Inverse supply function $p_s = {\sqrt{q_s} }$, where quantity is inputed and price is output''' return (math.sqrt(quantity)) def inverse_supply_with_tax(quantity): '''Inverse supply function with the tax added $p_s = {\sqrt{q_s} } + 2$, where quantity is inputed and price is output''' return inverse_supply(quantity) + 2
Created September 26, 2023 00:24
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 pandas as pd import os # Sample code to calculate the Beta coefficient; Assume we have the following 9 weeks prices for a stock and the market index Stock_WeeklyPrice = [20,35,40,37,22,34,55,35,42] Market_WeeklyPrice = [300, 340, 400, 320, 200, 300, 500, 380, 400] def calculate_beta(stock_weekly_price, market_weekly_price): # A useful code to calculate the percentage change within a series is called np.Series.pct_change() # It returns the percentage change between the current and a prior element, which can be seen as (P_t / P_(t-1))-100%
Created September 17, 2023 22:59
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
 # Starting point class State: def __init__(self, name, pop,s_intercept=0,d_intercept=100): self.name = name self.population = pop #supply function parameters self.supply_intercept=s_intercept self.supply_slope=1
Last active September 17, 2023 22:05
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
 pp = PdfPages(outputfolder + 'my_pdf_name.pdf') # create a new instance of PdfPages specifying the file location figs = [fig1, fig2, fig3] # all of the figures to add to the file in a list for fig in figs: # loop through each figure fig.savefig(pp, format='pdf') # save that figure to the file, specifying pdf format pp.close() # close the file
Created August 3, 2023 14:38
Example of adding schema markup to blog post.
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 { SITE_OWNER_GITHUB, SITE_OWNER_LINKEDIN, SITE_OWNER_TWITTER, SITE_OWNER, SITE_URL } from '../../lib/constants' export default function PostSchema({ post }) { const url = post.canonicalUrl !== undefined && post.canonicalUrl !== null ? post.canonicalUrl : ${SITE_URL}/blog/${post.slug}; return (
Created October 18, 2021 18:44
Rich Text Block Contentful & Gatsby
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 React from 'react' import { BLOCKS, MARKS } from '@contentful/rich-text-types'; import { documentToReactComponents } from '@contentful/rich-text-react-renderer'; import { GatsbyImage, getImage } from "gatsby-plugin-image" const Bold = ({ children }) => {children}; const Text = ({ children }) =>

{children}

; const richTextImages = {};
Created August 31, 2020 20:42
TextBlock Gatsby-Contentful Fragment
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 { graphql } from "gatsby" export const TextQuery = graphql fragment TextBlock on ContentfulTextBlock { id bodyContent { json } sys { contentType {
Last active August 31, 2020 20:41
FiftyFiftyContent Gatsby-Contentful Fragment
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 { graphql } from "gatsby" export const FiftyFiftyContentQuery = graphql fragment FiftyFiftyContent on ContentfulFiftyFifty { id sys { contentType { sys { id }
Created August 10, 2020 22:22