Skip to content

Instantly share code, notes, and snippets.

View JarnaChao09's full-sized avatar

WukongRework.exe BROKE JarnaChao09

View GitHub Profile
@JarnaChao09
JarnaChao09 / convolutionpy.py
Last active February 26, 2024 04:45
convolution.py
from ulab import numpy as np
def meshgrid(input_rows, input_cols):
output_shape = (input_rows.shape[0], input_cols.shape[0])
ret_rows = np.zeros(output_shape, dtype=np.int64)
ret_cols = np.zeros(output_shape, dtype=np.int64)
r, c = output_shape
for i in range(0, r):
func asciiToString(code: Integer): String {
val digits = "0123456789";
val lowerAlphabet = "abcdefghijklmnopqrstuvwxyz";
val upperAlphabet = lowerAlphabet.uppercase();
match {
code == 32: return " ";
code == 33: return "!";
code - 48 >= 0 && code - 48 < 10: return digits[code - 48];
code - 65 >= 0 && code - 65 < 26: return upperAlphabet[code - 65];
// missing `}` before catch leads to error saying the code is a macro (???)
// unable to pass in dummy Unit struct as the argument list
// still errors as empty (???)
// unable to get around `Dynamic` use in first arg since it expects
// a Tuple and tuple literals do not work currently
// struct Unit {}
// func test(fun: Lambda<Dynamic, Dynamic, Dynamic>) {
// try {
@JarnaChao09
JarnaChao09 / eulers_method.py
Last active March 23, 2022 06:04
my_project
from math import ceil
from input_handler import __input_eval as enput
def __euler_step(dy_dx, initial_x, initial_y, steps, delta_x=0.00001, silent=False):
"""
Performs `steps` steps of Euler's Method, starting at (`initial_x`,
`initial_y`). `dy_dx` is a function that takes 2 arguments, `x` and `y`.
`delta_x` is the step size for x. `silent` controls whether the intermediate
steps are printed. The final value of `y` is returned.

kotlin fixes many of the issues a lot of people had with java and adds a lot of extra cool features that be utilized to reduce codebase size:

type inference: in java, u have to constantly type out the type of the variable, with type inference, the type of the variable is inferred by the compiler, this cuts down on the verbosity

null safety: null pointer errors are a common thing in java, u constantly have to do if (somevariable != null) checks to make sure things arent null. Kotlins way around this is, to integrate the null safety into the type hierarchy. Every type has 2 technical types, a guaranteed null safe type ie Int, and a nullable type ie Int? this makes null checking really seamless with the type system, getting rid of the nested if null checks with ?. (safe calling) or with !! (double bang) operator

data class: when u need to just hold data in a class, data classes are really nice since they do many of the common methods that u would create normally. a copy method, equals, hashcode, and getters a