r/StackoverReddit • u/[deleted] • Jun 21 '24
Question question
can anyone tell me what are the ways to earn as a web developers except full time job and freelanceing
r/StackoverReddit • u/[deleted] • Jun 21 '24
can anyone tell me what are the ways to earn as a web developers except full time job and freelanceing
r/StackoverReddit • u/[deleted] • Jul 15 '24
r/StackoverReddit • u/NoArgument3206 • Jul 18 '24
Can a GET request have more than one link? I’m using an api that pulls one item per link but I need multiple links from the api for a single function.
Ex.
Xhttp.open(“GET”, “url”, true);
Can I add multiple links to “open” and apply them to the function?
Function ex. Function form results(event) {
If { radioOptionOne.checked && .radioOptionTwo.checked == true) { Response = JSON.parse(xhttp.response); Document.getElementById(“”).innerHTML = response.Title; }
Xhttp.open(“GET”, “url”, true); Xhttp.setRequestHeader (‘api key’, ‘key’);
Xhttp.setRequestHeader (‘api host’, ‘api url’);
Any help would truly be appreciated.
r/StackoverReddit • u/[deleted] • Sep 06 '24
r/StackoverReddit • u/No_Trick705 • Jul 19 '24
Hello there,
I was trying to convert my .py file to an .apk file and was getting into some errors. The code below is the code I ran before converting the file. I was doing this from Google Colab
!pip install buildozer
!pip install --upgrade Cython
!sudo apt-get install -y \
python3-pip \
build-essential \
git \
python3 \
python3-dev \
ffmpeg \
libsdl2-dev \
libsdl2-image-dev \
libsdl2-mixer-dev \
libsdl2-ttf-dev \
libportmidi-dev \
libswscale-dev \
libavformat-dev \
libavcodec-dev \
zlib1g-dev
!sudo apt-get install -y \
libgstreamer1.0 \
gstreamer1.0-plugins-base \
gstreamer1.0-plugins-good
!sudo apt-get install build-essential libsqlite3-dev sqlite3 bzip2 libbz2-dev zlib1g-dev libssl-dev openssl libgdbm-dev libgdbm-compat-dev liblzma-dev libreadline-dev libncursesw5-dev libffi-dev uuid-dev libffi6
!sudo apt-get install libffi-dev
!apt-get update
!sudo apt-get install libtool
!sudo apt-get install intltool
!sudo apt-get install gtkdoc
!sudo apt-get install gettext
!sudo apt-get install python3.10
!buildozer initAfter I was done running these commands, I edited the buildozer.spec file.
So, now when I ran !buildozer -v android debug, this was the log below with the error at the bottom.
[INFO]: Downloading freetype
[INFO]: -> directory context /content/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/packages/freetype
[DEBUG]: -> running basename https://download.savannah.gnu.org/releases/freetype/freetype-2.10.1.tar.gz
[DEBUG]: freetype-2.10.1.tar.gz
[DEBUG]: Downloading freetype from https://download.savannah.gnu.org/releases/freetype/freetype-2.10.1.tar.gz
[DEBUG]: -> running rm -f .mark-freetype-2.10.1.tar.gz
[INFO]: Downloading freetype from https://download.savannah.gnu.org/releases/freetype/freetype-2.10.1.tar.gz
Traceback (most recent call last):
File "/usr/lib/python3.10/urllib/request.py", line 1348, in do_open
h.request(req.get_method(), req.selector, req.data, headers,
File "/usr/lib/python3.10/http/client.py", line 1283, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/lib/python3.10/http/client.py", line 1329, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/usr/lib/python3.10/http/client.py", line 1278, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/lib/python3.10/http/client.py", line 1038, in _send_output
self.send(msg)
File "/usr/lib/python3.10/http/client.py", line 976, in send
self.connect()
File "/usr/lib/python3.10/http/client.py", line 1448, in connect
super().connect()
File "/usr/lib/python3.10/http/client.py", line 942, in connect
self.sock = self._create_connection(
File "/usr/lib/python3.10/socket.py", line 845, in create_connection
raise err
File "/usr/lib/python3.10/socket.py", line 833, in create_connection
sock.connect(sa)
OSError: [Errno 99] Cannot assign requested address
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
exec(code, run_globals)
File "/content/.buildozer/android/platform/python-for-android/pythonforandroid/toolchain.py", line 1256, in <module>
main()
File "/content/.buildozer/android/platform/python-for-android/pythonforandroid/entrypoints.py", line 18, in main
ToolchainCL()
File "/content/.buildozer/android/platform/python-for-android/pythonforandroid/toolchain.py", line 685, in __init__
getattr(self, command)(args)
File "/content/.buildozer/android/platform/python-for-android/pythonforandroid/toolchain.py", line 104, in wrapper_func
build_dist_from_args(ctx, dist, args)
File "/content/.buildozer/android/platform/python-for-android/pythonforandroid/toolchain.py", line 163, in build_dist_from_args
build_recipes(build_order, python_modules, ctx,
File "/content/.buildozer/android/platform/python-for-android/pythonforandroid/build.py", line 482, in build_recipes
recipe.download_if_necessary()
File "/content/.buildozer/android/platform/python-for-android/pythonforandroid/recipe.py", line 352, in download_if_necessary
self.download()
File "/content/.buildozer/android/platform/python-for-android/pythonforandroid/recipe.py", line 402, in download
self.download_file(self.versioned_url, filename)
File "/content/.buildozer/android/platform/python-for-android/pythonforandroid/recipe.py", line 206, in download_file
urlretrieve(url, target, report_hook)
File "/usr/lib/python3.10/urllib/request.py", line 241, in urlretrieve
with contextlib.closing(urlopen(url, data)) as fp:
File "/usr/lib/python3.10/urllib/request.py", line 216, in urlopen
return opener.open(url, data, timeout)
File "/usr/lib/python3.10/urllib/request.py", line 519, in open
response = self._open(req, data)
File "/usr/lib/python3.10/urllib/request.py", line 536, in _open
result = self._call_chain(self.handle_open, protocol, protocol +
File "/usr/lib/python3.10/urllib/request.py", line 496, in _call_chain
result = func(*args)
File "/usr/lib/python3.10/urllib/request.py", line 1391, in https_open
return self.do_open(http.client.HTTPSConnection, req,
File "/usr/lib/python3.10/urllib/request.py", line 1351, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [Errno 99] Cannot assign requested address>
Download failed: <urlopen error [Errno 99] Cannot assign requested address>; retrying in 1 second(s)...Download failed: <urlopen error [Errno 99] Cannot assign requested address>; retrying in 2 second(s)...Download failed: <urlopen error [Errno 99] Cannot assign requested address>; retrying in 4 second(s)...Download failed: <urlopen error [Errno 99] Cannot assign requested address>; retrying in 8 second(s)...# Command failed: ['/usr/bin/python3', '-m', 'pythonforandroid.toolchain', 'create', '--dist_name=myapp', '--bootstrap=sdl2', '--requirements=python3,kivy,kivymd,pillow', '--arch=arm64-v8a', '--arch=armeabi-v7a', '--copy-libs', '--color=always', '--storage-dir=/content/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a', '--ndk-api=21', '--ignore-setup-py', '--debug']
# ENVIRONMENT:
# SHELL = '/bin/bash'
# NV_LIBCUBLAS_VERSION = '12.2.5.6-1'
# NVIDIA_VISIBLE_DEVICES = 'all'
# COLAB_JUPYTER_TRANSPORT = 'ipc'
# NV_NVML_DEV_VERSION = '12.2.140-1'
# NV_CUDNN_PACKAGE_NAME = 'libcudnn8'
# CGROUP_MEMORY_EVENTS = '/sys/fs/cgroup/memory.events /var/colab/cgroup/jupyter-children/memory.events'
# NV_LIBNCCL_DEV_PACKAGE = 'libnccl-dev=2.19.3-1+cuda12.2'
# NV_LIBNCCL_DEV_PACKAGE_VERSION = '2.19.3-1'
# VM_GCE_METADATA_HOST = '169.254.169.253'
# HOSTNAME = 'c1bd99cb2287'
# LANGUAGE = 'en_US'
# TBE_RUNTIME_ADDR = '172.28.0.1:8011'
# COLAB_TPU_1VM = ''
# GCE_METADATA_TIMEOUT = '3'
# NVIDIA_REQUIRE_CUDA = ('cuda>=12.2 brand=tesla,driver>=470,driver<471 '
'brand=unknown,driver>=470,driver<471 brand=nvidia,driver>=470,driver<471 '
'brand=nvidiartx,driver>=470,driver<471 brand=geforce,driver>=470,driver<471 '
'brand=geforcertx,driver>=470,driver<471 brand=quadro,driver>=470,driver<471 '
'brand=quadrortx,driver>=470,driver<471 brand=titan,driver>=470,driver<471 '
'brand=titanrtx,driver>=470,driver<471 brand=tesla,driver>=525,driver<526 '
'brand=unknown,driver>=525,driver<526 brand=nvidia,driver>=525,driver<526 '
'brand=nvidiartx,driver>=525,driver<526 brand=geforce,driver>=525,driver<526 '
'brand=geforcertx,driver>=525,driver<526 brand=quadro,driver>=525,driver<526 '
'brand=quadrortx,driver>=525,driver<526 brand=titan,driver>=525,driver<526 '
'brand=titanrtx,driver>=525,driver<526')
# NV_LIBCUBLAS_DEV_PACKAGE = 'libcublas-dev-12-2=12.2.5.6-1'
# NV_NVTX_VERSION = '12.2.140-1'
# COLAB_JUPYTER_IP = '172.28.0.12'
# NV_CUDA_CUDART_DEV_VERSION = '12.2.140-1'
# NV_LIBCUSPARSE_VERSION = '12.1.2.141-1'
# COLAB_LANGUAGE_SERVER_PROXY_ROOT_URL = 'http://172.28.0.1:8013/'
# NV_LIBNPP_VERSION = '12.2.1.4-1'
# NCCL_VERSION = '2.19.3-1'
# KMP_LISTEN_PORT = '6000'
# TF_FORCE_GPU_ALLOW_GROWTH = 'true'
# ENV = '/root/.bashrc'
# PWD = '/content'
# COLAB_LANGUAGE_SERVER_PROXY_REQUEST_TIMEOUT = '30s'
# TBE_EPHEM_CREDS_ADDR = '172.28.0.1:8009'
# TBE_CREDS_ADDR = '172.28.0.1:8008'
# NV_CUDNN_PACKAGE = 'libcudnn8=8.9.6.50-1+cuda12.2'
# NVIDIA_DRIVER_CAPABILITIES = 'compute,utility'
# COLAB_JUPYTER_TOKEN = ''
# LAST_FORCED_REBUILD = '20240627'
# NV_NVPROF_DEV_PACKAGE = 'cuda-nvprof-12-2=12.2.142-1'
# NV_LIBNPP_PACKAGE = 'libnpp-12-2=12.2.1.4-1'
# NV_LIBNCCL_DEV_PACKAGE_NAME = 'libnccl-dev'
# TCLLIBPATH = '/usr/share/tcltk/tcllib1.20'
# NV_LIBCUBLAS_DEV_VERSION = '12.2.5.6-1'
# COLAB_KERNEL_MANAGER_PROXY_HOST = '172.28.0.12'
# NVIDIA_PRODUCT_NAME = 'CUDA'
# NV_LIBCUBLAS_DEV_PACKAGE_NAME = 'libcublas-dev-12-2'
# USE_AUTH_EPHEM = '1'
# NV_CUDA_CUDART_VERSION = '12.2.140-1'
# COLAB_WARMUP_DEFAULTS = '1'
# HOME = '/root'
# LANG = 'en_US.UTF-8'
# COLUMNS = '100'
# CUDA_VERSION = '12.2.2'
# CLOUDSDK_CONFIG = '/content/.config'
# NV_LIBCUBLAS_PACKAGE = 'libcublas-12-2=12.2.5.6-1'
# NV_CUDA_NSIGHT_COMPUTE_DEV_PACKAGE = 'cuda-nsight-compute-12-2=12.2.2-1'
# COLAB_RELEASE_TAG = 'release-colab_20240717-060213_RC00'
# PYDEVD_USE_FRAME_EVAL = 'NO'
# KMP_TARGET_PORT = '9000'
# CLICOLOR = '1'
# KMP_EXTRA_ARGS = ('--logtostderr --listen_host=172.28.0.12 --target_host=172.28.0.12 '
'--tunnel_background_save_url=https://colab.research.google.com/tun/m/cc48301118ce562b961b3c22d803539adc1e0c19/m-s-18r1r6d9ifck7 '
'--tunnel_background_save_delay=10s '
'--tunnel_periodic_background_save_frequency=30m0s '
'--enable_output_coalescing=true --output_coalescing_required=true')
# NV_LIBNPP_DEV_PACKAGE = 'libnpp-dev-12-2=12.2.1.4-1'
# COLAB_LANGUAGE_SERVER_PROXY_LSP_DIRS = '/datalab/web/pyright/typeshed-fallback/stdlib,/usr/local/lib/python3.10/dist-packages'
# NV_LIBCUBLAS_PACKAGE_NAME = 'libcublas-12-2'
# COLAB_KERNEL_MANAGER_PROXY_PORT = '6000'
# CLOUDSDK_PYTHON = 'python3'
# NV_LIBNPP_DEV_VERSION = '12.2.1.4-1'
# ENABLE_DIRECTORYPREFETCHER = '1'
# NO_GCE_CHECK = 'False'
# JPY_PARENT_PID = '90'
# PYTHONPATH = '/env/python'
# TERM = 'xterm-color'
# NV_LIBCUSPARSE_DEV_VERSION = '12.1.2.141-1'
# GIT_PAGER = 'cat'
# LIBRARY_PATH = '/usr/local/cuda/lib64/stubs'
# NV_CUDNN_VERSION = '8.9.6.50'
# SHLVL = '0'
# PAGER = 'cat'
# COLAB_LANGUAGE_SERVER_PROXY = '/usr/colab/bin/language_service'
# NV_CUDA_LIB_VERSION = '12.2.2-1'
# NVARCH = 'x86_64'
# NV_CUDNN_PACKAGE_DEV = 'libcudnn8-dev=8.9.6.50-1+cuda12.2'
# NV_CUDA_COMPAT_PACKAGE = 'cuda-compat-12-2'
# MPLBACKEND = 'module://ipykernel.pylab.backend_inline'
# NV_LIBNCCL_PACKAGE = 'libnccl2=2.19.3-1+cuda12.2'
# LD_LIBRARY_PATH = '/usr/local/nvidia/lib:/usr/local/nvidia/lib64'
# COLAB_GPU = ''
# GCS_READ_CACHE_BLOCK_SIZE_MB = '16'
# NV_CUDA_NSIGHT_COMPUTE_VERSION = '12.2.2-1'
# NV_NVPROF_VERSION = '12.2.142-1'
# LC_ALL = 'en_US.UTF-8'
# COLAB_FILE_HANDLER_ADDR = 'localhost:3453'
# PATH = '/root/.buildozer/android/platform/apache-ant-1.9.4/bin:/opt/bin:/usr/local/nvidia/bin:/usr/local/cuda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/tools/node/bin:/tools/google-cloud-sdk/bin'
# NV_LIBNCCL_PACKAGE_NAME = 'libnccl2'
# COLAB_DEBUG_ADAPTER_MUX_PATH = '/usr/local/bin/dap_multiplexer'
# NV_LIBNCCL_PACKAGE_VERSION = '2.19.3-1'
# PYTHONWARNINGS = 'ignore:::pip._internal.cli.base_command'
# DEBIAN_FRONTEND = 'noninteractive'
# COLAB_BACKEND_VERSION = 'next'
# COLAB_CUSTOMIZE_FOR_VM_TYPE = '1'
# OLDPWD = '/'
# _ = '/usr/local/bin/buildozer'
# PACKAGES_PATH = '/root/.buildozer/android/packages'
# ANDROIDSDK = '/root/.buildozer/android/platform/android-sdk'
# ANDROIDNDK = '/root/.buildozer/android/platform/android-ndk-r25b'
# ANDROIDAPI = '31'
# ANDROIDMINAPI = '21'
#
# Buildozer failed to execute the last command
# The error might be hidden in the log above this error
# Please read the full log, and search for it before
# raising an issue with buildozer itself.
# In case of a bug report, please add a full log with log_level = 2If anybody has a solution please let me know.
Thanks in advance,
No_Trick705
r/StackoverReddit • u/MysteriousShadow__ • Aug 05 '24
"Please edit your question to be more clear"
"This question is not on topic"
"Your question has been closed because it didn't meet the requirements of a good question"
"I don't understand why you'd do things like that. Method B is much easier"
Surely we're not gonna get those type of shit in this sub right? Almost every question I ask on stackexchange has comments complaining about the question itself instead of answering it.
r/StackoverReddit • u/[deleted] • Oct 18 '24
r/StackoverReddit • u/[deleted] • Jul 03 '24
I am trying to learn webdev but I always get stuck at css selectors
r/StackoverReddit • u/Firm_Medicine_9462 • Jul 27 '24
Please suggest other possibilities.
r/StackoverReddit • u/slittyslit • Jun 27 '24
r/StackoverReddit • u/[deleted] • Jul 08 '24
r/StackoverReddit • u/[deleted] • Jan 03 '25
I am very confused
r/StackoverReddit • u/guest271314 • Jul 21 '24
I'm trying to figure out how to connect to my TCP server from within d8.
V8's d8 has a commandline option --read-from-tcp-port=PORT. See https://github.com/v8/v8/blob/9b9d02b07c231de5046a87ac80d4bbe24a737097/src/d8/d8-posix.cc#L654-L745.
Here's some Python that uses adb in the code. https://github.com/v8/v8/blob/9b9d02b07c231de5046a87ac80d4bbe24a737097/tools/adb-d8.py#L7-L18.
Anybody have experience with using d8's --read-from-tcp-port=PORT from within d8 to connect to the TCP server?
r/StackoverReddit • u/Livid-Salamander-949 • Jun 13 '24
When pondering a project thinking about the structure of a core Linux utility like script (utility that records the output of the terminal to a file) it occurred to me , after some digging , what is actually going on when you write code that emulates or copies these core Linux utilities .
It just gave me a kinda of aha! Moment and ohhh okay response . Maybe it will help someone else as well so Here is a summary of the insight :
——————————————————
System calls are the way user-space programs request services from the operating system kernel. They simplify the interaction between higher-level languages (like C and Python) and the low-level operations of the OS.
A system call allows a user program to ask the operating system to perform a task that requires kernel-level privileges, such as reading a file or creating a process.
Here's a simple C program that uses the read() system call:
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
int main() {
int fd;
char buffer[128];
ssize_t bytesRead;
fd = open("example.txt", O_RDONLY);
if (fd == -1) {
perror("open");
return 1;
}
bytesRead = read(fd, buffer, sizeof(buffer) - 1);
if (bytesRead == -1) {
perror("read");
close(fd);
return 1;
}
buffer[bytesRead] = '\0';
printf("Read %zd bytes: %s\n", bytesRead, buffer);
close(fd);
return 0;
}Python simplifies system calls further with the os module:
import os
fd = os.open("example.txt", os.O_RDONLY)
buffer = os.read(fd, 128)
print(f"Read {len(buffer)} bytes: {buffer.decode()}")
os.close(fd)User Space Invocation:
The program calls a function (read() in C or os.read() in Python).
Transition to Kernel Space:
The function uses a special CPU instruction to switch to kernel mode.
Kernel Mode Execution:
The kernel performs the requested operation, like reading data from a file.
Return to User Space:
The kernel returns the result to the user program.
System calls make it easier to perform complex operations by:
Abstracting hardware interactions.
Controlling access to resources.
Standardizing operations across different systems.
System calls provide a secure, standardized way for higher-level languages to interact with the kernel, making complex tasks like file I/O straightforward and safe. They bridge the gap between user-friendly programming languages and the critical, low-level functions of the operating system.
r/StackoverReddit • u/[deleted] • Jul 11 '24
I want to create automation softwares and web apps
r/StackoverReddit • u/hi_i_m_here • Jul 20 '24
r/StackoverReddit • u/AmadeusSalieri97 • Jul 09 '24
I have a system with 3M equations and 3M + 3 variables such as:
Assuming all coefficients a, b, c, d, e, f and g are known.
With the boundary conditions I add the 3 equations needed to have as many equations as variables, so I should be able to write a code on python that solves this, but I don't quite get how to do it... I would know how do it if one of the boundary conditions was tau_0 = 0 as then we just march in k, but I struggle a little bit with the boundary condition of u_k=M = 0...
I get that I have to put it in matrix notation I guess, so I should linearize it and have Ax = B where A is a matrix of 3Mx3M, x is a vector 3M, right? But even if I'm understanding the theory correctly I have no idea how to write it in python.
r/StackoverReddit • u/KrystalineAlchemy • Jul 25 '24
Alright, so im teaching myself to code, and to do so im working on building out a small text based game following along with tutorials and other resources to learn things as i go. That being said i learn best by doing but that obviously comes with it's own issues. Ive run myself into a problem. Below is my code for my main menu, everything seems to be working, i can type in one of the three options, (Tho they go no where yet, i havnt got that far lol.) and VSC isn't giving me any errors of anykind, when i run the code i don't get any kind of error either. The issue im having is that its returning the main menu 3 times instead of just a single time.
Example:
What i want
***********************
* Welcome To The *
* World of Caldera *
***********************
***********************
* <~Play~> *
* <~Help~> *
* <~Quit~> *
***********************
* Copyright 2024 *
* KrystalAlchemist *
***********************
What im getting
***********************
* Welcome To The *
* World of Caldera *
***********************
***********************
* <~Play~> *
* <~Help~> *
* <~Quit~> *
***********************
* Copyright 2024 *
* KrystalAlchemist *
***********************
***********************
* Welcome To The *
* World of Caldera *
***********************
***********************
* <~Play~> *
* <~Help~> *
* <~Quit~> *
***********************
* Copyright 2024 *
* KrystalAlchemist *
***********************
***********************
* Welcome To The *
* World of Caldera *
***********************
***********************
* <~Play~> *
* <~Help~> *
* <~Quit~> *
***********************
* Copyright 2024 *
* KrystalAlchemist *
***********************
Code below for refrence:
def
displaymainmenu():
print('Legends of Caldera')
for option in MAIN_MENU_OPTIONS:
print()
print('***********************')
print('* Welcome To The *')
print('* World of Caldera *')
print('***********************')
print('')
print('***********************')
print('* <~Play~> *')
print('* <~Help~> *')
print('* <~Quit~> *')
print('***********************')
print('* Copyright 2024 *')
print('* KrystalAlchemist *')
print('***********************')
# print()
# print("Main menu\n")
# print("Play")
# print("Quit")
def
getinput():
playerInput = input("> ").upper()
return playerInput
def
Clearscreen():
print(
os
.name)
print(
sys
.platform)
if
sys
.platform == "win32":
os
.system('cls')
if __name__ == "__main__":
GAME_OVER = False
MAIN_MENU_OPTIONS = ['PLAY', 'QUIT', 'HELP']
Clearscreen()
while GAME_OVER is False:
displaymainmenu()
mainmenuoptionselected = getinput()
if mainmenuoptionselected in MAIN_MENU_OPTIONS:
break
else:
print("Sorry, invalid option.")
Clearscreenr/StackoverReddit • u/[deleted] • Jun 12 '24
So I'm using LeetCode to prepare for an exams on Algorithms and Datastructures. The course was based on CLRS and the problems from previous exams are in fact problems that I found also on LeetCode, such as EditDistance or Merging two Binary Search Trees.
The main difference is that the problems they give us are slightly more focused on implementing the algorithm and less on dealing with C. Don't get me wrong, I don't mind quickly coding up a little HashTable so I can solve a problem that takes O(n^2) time complexity in O(n) time by sacrificing O(n) spae but it gets annoying when I feel like some problems are clearly easier to solve in another language than C...
So yeah, I was wondering if there is a site that features a lot of problems, has tests to verify your solution and gives you template, i.e., the function you have to provide, which is slightly more C-friendly and doesn't force you figure out more C-related stuff, forcing you more to think about the algorithm and less about the specific implementation.
EDIT:
I ended up sticking with LeetCode because I realized implementing my own stack/queues/heaps helped me to review pointers and algorithm parts such as heapify from heapSort which I can implement from my head although I never actively tried to learn it by heart, I just kind had to get used to it since I needed heaps for some problems and had to make my own quickly. I also made my own hashMap which was a massive pain to do but it was satisfying to see it work and pass all the LeetCode tests like on first try.
r/StackoverReddit • u/[deleted] • Jul 02 '24
How is my code, and what further suggestions should I use to improve it?
public class Calculator {
public double sum(double x, double y) {
return x + y;
}
public double difference(double x, double y) {
return x - y;
}
public double product(double x, double y) {
return x * y;
}
public double quotient(double x, double y) {
if(y == 0) {
throw new IllegalArgumentException("You cannot divide by zero");
}
return x / y;
}
public double exponent(double x, double y) {
return Math.pow(x, y);
}
public double squareRoot(double x) {
if(x < 0) {
throw new IllegalArgumentException("You cannot square root a negative number");
}
return Math.sqrt(x);
}
public double modulator(double x , double y) {
if(y == 0) {
throw new IllegalArgumentException("You cannot modulate by zero.");
}
return x % y;
}
}
import java.util.Scanner;
public class CalculatorTest {
public static void main(String[] args) {
runCalc();
}
public static void runCalc() {
Calculator c = new Calculator();
Scanner input = new Scanner(System.in);
while(true) {
System.out.println("Which operation would you like to do? add, subtract, multiply, divide, exponent, square root, modulate, or exit");
String operation = input.nextLine().trim().toLowerCase();
if(operation.equals("exit")) {
System.out.println("Bye");
break;
}
double first = 0.0;
double second = 0.0;
if (!operation.equals("square root")) {
System.out.println("Enter First Number: ");
first = input.nextDouble();
System.out.println("Enter Second Number: ");
second = input.nextDouble();
input.nextLine();
}
else {
System.out.println("Enter the number to find the square root: ");
first = input.nextDouble();
input.nextLine();
}
try {
switch(operation){
case "add":
System.out.println("The answer is: " + String.format("%.2f", c.sum(first, second)));
break;
case "subtract":
System.out.println("The answer is: " + String.format("%.2f", c.difference(first, second)));
break;
case "multiply":
System.out.println("The answer is: " + String.format("%.2f", c.product(first, second)));
break;
case "divide":
if(second != 0) {
System.out.println("The answer is: " + String.format("%.2f", c.quotient(first, second)));
}
else {
System.out.println("Division by 0 is not allowed");
}
break;
case "exponent":
System.out.println("The answer is: " + String.format("%.2f", c.exponent(first, second)));
break;
case "square root":
if(first >= 0) {
System.out.println("The answer is: " + String.format("%.2f", c.squareRoot(first)));
}
else {
System.out.println("Square root of a negative number cannot happen");
}
break;
case "modulate":
if(second != 0) {
System.out.println("The answer is: " + String.format("%.2f", c.modulator(first, second)));
}
else {
System.out.println("Modulation by zero is not allowed");
}
break;
default:
System.out.println("This is not a valid operation. Try Again!");
break;
}
}
catch (IllegalArgumentException e) {
System.out.println(e.getMessage());
}
}
input.close();
}
}r/StackoverReddit • u/[deleted] • Sep 05 '24
r/StackoverReddit • u/Bitter-Hope6731 • Jul 29 '24
I am using python 3.12.4 on macOS, and am typing in on the first line "pip.install (fastf1)" if I don't type it like that (excluding the speech marks) I get a syntax error, but now I am getting a name error, where pip isn't defined, people have talked about command lines and virtual environments but I have no idea on how I should be typing this out, any help would be greatly appreciated.
r/StackoverReddit • u/Efficient_Gift_7758 • Jul 13 '24
I'm gonna write some application (python+Vuejs) aimed to ease creating small pieces of logic and constructing flow of process (like user case) with it.
How I see workflow:
Define context (models, their fields and relations between them) (using chatGPT) as a prompt
... Generating and saving models, migrating to db
2. Explain behaviour of each model by as less complex of logic separate pieces as possible (atomic logic piece). Save it as blocks of logic
... Writing pieces into appropriate models
3. Use UI to compose flow of pieces and run them
I'm aware of many issues like where to store db, how to define schema and migrate it to db and so on... But now I want to try at least something
So, are there already some existing tries of it, or maybe patterns ?
PS The idea is borrowed from processors arch - how they work on commands as pieces of logic and use a bigger ones (that consist of smaller pieces)