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 | |
| def log(base: float, n: float): | |
| x = 1.0 | |
| best_loss = 1_000_000.0 | |
| for _ in range(100_000): | |
| random_adj = np.random.normal() | |
| x += random_adj | |
| new_loss = ((base ** x) - n) ** 2 |
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 plotly.express as px | |
| # Factorials multiply consecutive descending integers down to 1 | |
| # EXAMPLE: 5! = 5 * 4 * 3 * 2 * 1 | |
| def factorial(n: int): | |
| f = 1 | |
| for i in range(n): | |
| f *= (i + 1) | |
| return f |
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 sympy import integrate, Symbol | |
| x = Symbol('x') | |
| # Calculate the integral function | |
| integral = integrate(2 * x, x) | |
| print(integral) # prints x**2 | |
| # Calculate the area under 2x between 0 and 2 | |
| area = integrate(2 * x, (x, 0, 2)) |
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
| # Got this from https://www.kkhaydarov.com/approximate-integration-with-python/ | |
| def approximate_integral(a, b, n, f, rule="midpoint"): | |
| delta_x = (b - a) / n | |
| total_sum = 0 | |
| if rule == "midpoint": | |
| for i in range(1, n + 1): | |
| midpoint = 0.5 * (2 * a + delta_x * (2 * i - 1)) | |
| total_sum += f(midpoint) |
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 random | |
| import plotly.express as px | |
| # Got this from https://www.kkhaydarov.com/approximate-integration-with-python/ | |
| def approximate_integral(a, b, n, f, rule="midpoint"): | |
| delta_x = (b - a) / n | |
| total_sum = 0 | |
| if rule == "midpoint": |
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
| # | |
| # Tello Python3 Control Demo | |
| # | |
| # http://www.ryzerobotics.com/ | |
| # | |
| # Commands: https://dl-cdn.ryzerobotics.com/downloads/tello/0228/Tello+SDK+Readme.pdf | |
| # 1/1/2018 | |
| import threading | |
| import socket |
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
| fun toCamelCase(s: String): String { | |
| val parts = s.split("_".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() | |
| var camelCaseString = "" | |
| for ((i,part) in parts.withIndex()) { | |
| camelCaseString += part.substring(0, 1).let { if (i == 0) it.toLowerCase() else it.toUpperCase() } + part.substring(1).toLowerCase() | |
| } | |
| return camelCaseString | |
| } |
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
| fun String.smartLocalDateTimeParse(): LocalDateTime { | |
| val dtmStr = replace("/", "-") | |
| val (dt,tm) = dtmStr.split(" ") | |
| return dt.smartLocalDateParse().atTime(tm.smartLocalTimeParse()) | |
| } | |
| fun String.smartLocalDateParse(): LocalDate { |
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
| package com.swa.np.common.util | |
| import org.apache.commons.csv.CSVFormat | |
| import org.apache.commons.csv.CSVRecord | |
| import java.io.FileReader | |
| object CSVHelper { | |
| // Helpful docs: https://commons.apache.org/proper/commons-csv/user-guide.html |
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
| <head> | |
| <!-- Plotly.js --> | |
| <script src="https://cdn.plot.ly/plotly-latest.min.js"></script> | |
| </head> | |
| <body> | |
| <div id="myDiv"><!-- Plotly chart will be drawn inside this DIV --></div> |