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 sympy as sp | |
x = sp.Symbol("x") | |
def gs(vecs, scalar_product): | |
new_base = [ | |
None for _ in range(len(vecs)) | |
] | |
new_base[0] = vecs[0] / norm(vecs[0], scalar_product = scalar_product) |
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
let csv = ` | |
year,amount,n | |
2016,123,1 | |
2017,124,2 | |
2018,125,3 | |
2019,126,4 | |
2020,127,5 | |
2021,128,6 | |
`; |
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
/// Prints and returns the value of a given expression for quick and dirty code | |
/// profiling. | |
/// | |
/// Example usage: | |
/// | |
/// ```rust | |
/// let s = "hello world"; | |
/// let all_caps = profile!(s.repeat(2).to_uppercase()); | |
/// ^-- prints: [src/main.rs:2] execution time: 2μs | |
/// |
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 argparse | |
import turtle | |
parser = argparse.ArgumentParser(description='Draw the fibonacci spiral') | |
parser.add_argument('n', type=int, help='Length of fibonacci sequence') | |
parser.add_argument('-s', '--scale', type=int, default=1) | |
parser.add_argument('--speed', type=int, default=6, help='Turtle speed') | |
args = parser.parse_args() | |
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
# Example usage | |
from time import sleep | |
@timer(repeat=10) | |
def my_function(): | |
sleep(1) | |
return True |
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 turtle | |
turtle.speed(0) | |
def spiralling_shape(sides: int = 4, iterations: int = 200, scale: int = 1): | |
for i in range(iterations): | |
turtle.forward(i*scale) | |
turtle.left(360//sides + 1) | |
# Make a spiralling square |
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
fn main() { | |
for x in 1..101 { | |
let mut out = String::new(); | |
if x % 3 == 0 { | |
out += "fizz"; | |
} | |
if x % 5 == 0 { | |
out += "buzz"; |
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
pub struct Fib { | |
a: u32, | |
b: u32, | |
count: i32, | |
} | |
impl Fib { | |
pub fn new(count: i32) -> Fib { | |
Fib { a: 1, b: 1, count } | |
} |
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
// Adapted from https://stackoverflow.com/questions/34848505/how-to-make-a-loading-animation-in-console-application-written-in-javascript-or | |
/** | |
* Create and display a loader in the console. | |
* | |
* @param {string} [text=""] Text to display after loader | |
* @param {array.<string>} [chars=["⠙", "⠘", "⠰", "⠴", "⠤", "⠦", "⠆", "⠃", "⠋", "⠉"]] | |
* Array of characters representing loader steps | |
* @param {number} [delay=100] Delay in ms between loader steps | |
* @example |
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
/** | |
* Generate the fibonaccie sequence recursively | |
* @param {number} num amount of recursion | |
* @returns {array} fibonacci sequence | |
*/ | |
let fib = num => { | |
if (num == 1) return [1]; | |
else { | |
let prev = fib(num - 1); | |
return prev.concat((prev[prev.length - 2] || 0) + prev[prev.length - 1]) |
NewerOlder