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 cache_disk(seconds = 900, cache_folder="/tmp"): | |
def doCache(f): | |
def inner_function(*args, **kwargs): | |
# calculate a cache key based on the decorated method signature | |
key = sha1(str(f.__module__) + str(f.__name__) + str(args) + str(kwargs)).hexdigest() | |
filepath = os.path.join(cache_folder, key) | |
# verify that the cached object exists and is less than $seconds old | |
if os.path.exists(filepath): |
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 com.fasterxml.jackson.core.JsonParser; | |
import com.fasterxml.jackson.databind.DeserializationContext; | |
import com.fasterxml.jackson.databind.JsonDeserializer; | |
import com.fasterxml.jackson.databind.module.SimpleModule; | |
import java.io.IOException; | |
public class EmptyStringToNullDeserializer extends JsonDeserializer<String> { | |
@Override | |
public String deserialize(JsonParser jsonParser, DeserializationContext context) throws IOException { | |
String value = jsonParser.getValueAsString(); |
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 org.apache.commons.math3.stat.regression.SimpleRegression; | |
import java.util.List; | |
public class LinearRegressionCalculator { | |
/** | |
* Calculates the slope and intercept of the line of best fit using simple linear regression. | |
* | |
* @param data A List<Double> object that represents the 'y' values of the data points. | |
* @return A double array of size 2 where the first element is the slope and the second element is the intercept. | |
*/ |
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.util.AbstractList; | |
import java.util.Deque; | |
import java.util.LinkedList; | |
public class DequeList<T> extends AbstractList<T> { | |
private final Deque<T> deque; | |
public DequeList(Deque<T> deque) { | |
this.deque = deque; | |
} |
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 org.apache.commons.math3.stat.regression.OLSMultipleLinearRegression; | |
public class PolynomialRegressionExample { | |
public static void main(String[] args) { | |
// Define your input data (x and y values) | |
double[][] data = { | |
{1.0, 2.3}, | |
{2.0, 4.5}, | |
{3.0, 6.7}, | |
// Add more data points as needed |
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
export default function flattenArray(arr) { | |
return arr.reduce(function (flatArray, element) { | |
if (Array.isArray(element)) { | |
return flatArray.concat(flattenArray(element)); | |
} else { | |
return flatArray.concat(element); | |
} | |
}, []); | |
} |
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
<?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>Label</key> | |
<string>org.custom.keyboard-remap</string> | |
<key>ProgramArguments</key> | |
<array> | |
<string>/usr/bin/hidutil</string> | |
<string>property</string> |
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 typing import List, Union | |
from bs4 import BeautifulSoup | |
from bs4.element import Tag | |
class TableExtract: | |
def __init__(self, headers: List[str], keep_html=False) -> None: | |
self._headers = headers | |
self._keep_html = keep_html |
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
{ | |
"env": { | |
"es6": true, | |
"node": true, | |
"browser": true | |
}, | |
"parser": "@babel/eslint-parser", | |
"extends": "eslint:recommended", | |
"parserOptions": { | |
"requireConfigFile": 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
from scipy.stats import norm | |
import numpy as np | |
N = norm.cdf | |
def d1_d2(S: float, K: float, T: float, r: float, sigma: float): | |
d1 = (np.log(S / K) + (r + sigma ** 2 / 2) * T) / (sigma * np.sqrt(T)) | |
d2 = d1 - sigma * np.sqrt(T) |