#development

1 messages · Page 96 of 1

lyric mountain
#

wdym?

rustic nova
#

That you're able to add these to a list and use their interface methods

#

Only really used interfaces for instancing, such as being able to tell what type of data i am about to parse using instanceof

eternal osprey
#

oooowh so if you have an array of an interface, it can hold all types of classes IF the classes implement that interface? that makes more sense now

#

thank youu!

lyric mountain
#

yep, u can always put subclasses in the same collection in they implement the same interface/superclass

eternal osprey
#

ahaaa i see!

#

i could then for example loop over tit and use all methods on it that i defined.

rustic nova
#

Pog

eternal osprey
#

if i define a public int in the interface, it will be readable by all classes but not changeable right?

#

unless they make a copy?

rustic nova
#

You cant define scopes on interfaces iirc

#

Aka the public protected private i think

eternal osprey
#

owh i see but int price = 50; for example

#

it would be readable but not changeable right?

rustic nova
#

Not in the interface, the interface is essentially a "blueprint"

#

Theoretically a blueprint

eternal osprey
#

I see, thanks once again!

rustic nova
#

There's something called abstract interfaces too, but tbf have never worked with these myself

#

So ask the java god KuuHaKu about abstract interfaces

#

Since abstract classes are able to do what you were mentioning

lyric mountain
#

interfaces can only have static constants

eternal osprey
lyric mountain
#

that means all "variables" will be final

eternal osprey
#

uhuh yeah! Got it, thank you!

rustic nova
#

Was i right with the abstract classes tho?

eternal osprey
#

Honestly you made all puzzle pieces fall within 10 minutes, something my teacher couldn't in 2 hours

earnest phoenix
#

web frontend development and rust
they both dont go together

radiant kraken
#

especially wasm

#

if they dont for u then you do you

earnest phoenix
#

wasm is slower than js

radiant kraken
#

so what?

#

it's not like they don't have any reason to exist

earnest phoenix
lament rock
#

Made a state validator which passes state assignments and previous values to the next do/go call.
param 0 is code
param 1 is expected value
param 2 is error value [status code, text]
param 3 is key to assign to state

#

Helpful for things like POST form validation and protecting against Cross Site Request Forgery

sudden geyser
#

so like a more pieced together assert

lament rock
#

Essentially. Although this to me is way more easy to digest and each stage depends on each other stage prior succeeding

dusky idol
#

https://prnt.sc/aAqOlMOWckMG
I'm filling the form for my discord bot verification, how do I answer this question?
The only message content that my discord bot stores is the AFK reason & it's stored as long as the user doesn't send a message in chat. There's no point in deleting it after 30 days.

Lightshot

Captured with Lightshot

rustic nova
#

discord wants you to delete that after 30 days then

quartz kindle
#

afk reason is specifically an option for a command, initiated by the user

#

what they are worried about is storing message content from people's conversations and stuff, like message backups and stuff like snipe commands

dusky idol
quartz kindle
#

yeah i would count that as setting options for the bot, not as storing message content

dusky idol
#

Alright, thanks

#

the rest of the form is about filling the intents part

sturdy vale
#

i want a help with interactions in discord.py can any helps me?

rustic nova
#

ask your question

eternal osprey
#

In java, i am creating a interface geometric and 2 classes that implement this geometric interface

#

i want to push these 2 created objects from the classes into a geometric array

#

where's the best place to have that array stored?

#

in the interface itself would be a nono, but where else?

#

I have a iohandler, must i put it in there then?

wheat mesa
#

Just Geometric[] would be fine would it not?

#

Maybe I don’t understand the question

eternal osprey
#

Oowh i can explain it a bit more thorough

#

I have 2 classes, triangle and circle.

#

I also have an interface Geometric that has several methods to be defined.

#

I want to create an array that holds all triangles and circles i want

#

but for that i must create an array of geometric right. Where should i put this array? Inside the gemoetric interface? Because i want to be able to access it from all classes, and modify it within the classes.

#

hope that i made it a bit more clear

lyric mountain
#

are u trying to retrieve all classes that implement Geometric?

#

because, like, I don't get what ur trying to do, but I think u have the wrong idea of what an interface is

rustic nova
#

interface: is essentially a blueprint

#

you cant pass values to other classes that implement that interface

#

you'd need an abstract interface and a static variable

#

not java

#

do python

#

funny snake language

#

do php

#

funny elephant language

#

crab language

#

do elephant

#

or gopher

sudden geyser
#

swift if you use a mac

lyric mountain
#

u could try groovy

rustic nova
#

no fuckin clue what astro is

wheat mesa
#

Learn C++ or Rust tbh

#

Having a low level lang is useful

lyric mountain
#

c++ for oauth holy

#

ya crazy

rustic nova
#

do assembly

wheat mesa
#

Oh god no not for oauth

#

I just meant in general

#

Rust has some good crates for oauth afaik though

rustic nova
lyric mountain
#

for sites I'd just use the basic html kit

#

that's backend, not front

#

they can be done separately, it's all api in the end

#

idk, for backend I just use java

#

an endpoint

#

oauth is nothing more than a 2-step api flow

#

you redirect the user to oauth
user authorizes
you receive the key
you trade the key with the server
you receive the data
you redirect the user to whatever u want

#

storing is just to be able to retrieve the data again without needing to ask for authorization

#

any language will suffice, oauth ain't as complicated as it seems

#

store what?

#

if they aren't logged in there's nothing to store

solemn latch
#

Oauth should handle redirects anyway.

lyric mountain
#

simply redirect

#

like, idk how to explain, all u need to do to control user flow is redirecting the request

#

oauth will send u whatever u need, just do your work from inside the backend

#

u can just redirect the user as soon as the payload arrives then finish the processing in the rest of the function

#

in some sense it ain't too different from handling message events in discord

eternal osprey
#

Beware this is just a class, not the main. I had a design question. Would it be okay to have one big helper function, or do yall recommend me to part it down? Like one for input, the other to extract parameters etc?

#

i always was told to make small helper functions, so i could do that here but it seems pretty useless to do that.

lyric mountain
#

yes you can (and should) make a helper class to keep all the commonly used methods

#

do note tho, u don't need to use \n in println

#

because println already include a linebreak

earnest phoenix
#

Well sometimes a double new line looks better..

sharp geyser
#
int a;         // no initializer (default initialization)
int b = 5;     // initializer after equals sign (copy initialization)
int c( 6 );    // initializer in parenthesis (direct initialization)

// List initialization methods (C++11)
int d { 7 };   // initializer in braces (direct list initialization)
int e = { 8 }; // initializer in braces after equals sign (copy list initialization)
int f {};      // initializer is empty braces (value initialization)

according to learncpp.com the first 3 are not "modern" C++ and are not really recommended under most situations, so what are the downsides compared to those 3 to the last 3?

#

I also don't really understand the difference between copy and direct initialization

wheat mesa
#

It doesn’t matter very much in the grand scheme of things

#

These are just different ways to initialize things

sharp geyser
#

So there is no downside?

lyric mountain
#

maybe direct allocates with the value inside while copy allocates then insert the value

#

regardless, compiler will use the optimal way anyway

wheat mesa
#

^

sharp geyser
#

so in grand scheme of things there is no big difference between them it just comes to a matter of preference?

#

@wheat mesa There is a benefit to list initilizations tho

#

int x {4.5} actually gives a compiler error rather then just a warning in the IDE

#

So if it can't safely hold the value in the type specified it will error rather than try and implicitly convert it

wheat mesa
#

Most people still use the generic = initializer

sharp geyser
#

ima use the list variant

wheat mesa
#

The different types of initialization become more important when working with classes and structs

lyric mountain
#

= has the advantage of allowing ctrl + F

sharp geyser
#

ctrl + F?

lyric mountain
#

yes, to find places where a variable is declared

sharp geyser
#

Ah

lyric mountain
#

without = there's nothing u can use to search

sharp geyser
#

I can just search the variable name

lyric mountain
#

well, yes, but what if u need to find all variable declarations?

sharp geyser
#

ctrl variableName { ez

#

takes me directly to the list initilization

sharp geyser
#

initialization*

lyric mountain
#

if u search for { it'll return scope braces too

sharp geyser
#

Im talking about looking for a specific variable declaration

spark flint
#

@whole knot

#

in all channels

rigid maple
#

There are many objects in an array and I want to calculate the number of "author" values ​​in these objects.
an example array;

let array = [
{ user: "TuranGe", balance: 25, author: "User1" },
{ user: "popoasd", balance: 255, author: "User1" },
{ user: "Prowdy", balance: 31, author: "User1" },
{ user: "Asd", balance: 1, author: "User2" },
{ user: "Asda", balance: 12, author: "User2" },
{ user: "Asdasd", balance: 11, author: "User3" }
]

The output I want is:

User1: 3
User2: 2
User3: 1
lyric mountain
#

occurrences, u mean

#

idk if js has, but u could use a bag

rigid maple
#

it will cause some problems ://

#

i did thanks

alpine swallow
# rigid maple There are many objects in an array and I want to calculate the number of "author...
let array = [
  { user: "TuranGe", balance: 25, author: "User1" },
  { user: "popoasd", balance: 255, author: "User1" },
  { user: "Prowdy", balance: 31, author: "User1" },
  { user: "Asd", balance: 1, author: "User2" },
  { user: "Asda", balance: 12, author: "User2" },
  { user: "Asdasd", balance: 11, author: "User3" }
]
let ObjArray = []
let obj = {}

array.forEach(ele => {
  if(ObjArray.includes(ele.author)){
    obj[ele.author] += 1
  }else {
    ObjArray.push(ele.author)
    obj[ele.author] = 1
  }
})
console.log(obj) // { User1: 3, User2: 2, User3: 1 }
#

let me know if anything went wrong

rigid maple
#

I did it but then I need to separate them with join by putting , I can't call join function on objects

alpine swallow
rigid maple
#
[
  { user: "User1", length: 3 },
  { user: "User2", length: 2 },
  { user: "User3", length: 1 }
]
alpine swallow
#

alr let me try

rigid maple
#
let array = [
{ user: "TuranGe", balance: 25, author: "User1" },
{ user: "popoasd", balance: 255, author: "User1" },
{ user: "Prowdy", balance: 31, author: "User1" },
{ user: "Asd", balance: 1, author: "User2" },
{ user: "Asda", balance: 12, author: "User2" },
{ user: "Asdasd", balance: 11, author: "User3" },
]
let sira = array.reduce(function(sums,entry){
   sums[entry.author] = (sums[entry.author] || 0) + 1;
   return sums;
},{});
let sorted = Object.entries(sira)
    .sort(([,a],[,b]) => b-a)
    .reduce((r, [k, v]) => ({ ...r, [k]: v }), {});
#

I can sort it like this

sharp geyser
#

Even I don't really understand what's happening there

#

Although that should do what you want

sudden geyser
#

sira counts how many times an author appears

sharp geyser
#

Oh wait you don't want it like that you want it like above nvm

sudden geyser
#

and sorted just sorts by most to least

rigid maple
alpine swallow
sudden geyser
#

then instead of your second reduce reducing it to a sorted map reduce it to an array

rigid maple
#

ok thanks

sudden geyser
#

you could accomplish it with just .map(([author, count]) => ...) where ... is a map following the user length map example

#

since map creates an array of items you'd have it in your wanted form

queen sorrel
#

Hi guys

#

Please I have troubles with my ENRA bot

sudden geyser
#

did you create it or is it someone else's bot

queen sorrel
#

Where can I get their diacord

solemn latch
#

-wrongserver

shell echoBOT
#

topggDotRed Hey! We think you have our server mistaken. We do not provide support, help, or advice for any bot. You need to click on the "Discord Support Server" button on the bot's page of the bot you need support for. If there isn't a button that says "Discord Support Server" or nothing else mentioned about a support server, the server invite is invalid or you were banned from the bot's support server, then we can't help you. Sorry :(

deft wolf
#

Your btw XD

sharp geyser
#

am I dumb or did I forget how map works

solemn latch
#

we all forget how map works

#

I wonder if reduce with an array accumulator is easier?

sharp geyser
#
let array = [
{ user: "TuranGe", balance: 25, author: "User1" },
{ user: "popoasd", balance: 255, author: "User1" },
{ user: "Prowdy", balance: 31, author: "User1" },
{ user: "Asd", balance: 1, author: "User2" },
{ user: "Asda", balance: 12, author: "User2" },
{ user: "Asdasd", balance: 11, author: "User3" },
]
let sira = array.reduce(function(sums,entry){
   sums[entry.author] = (sums[entry.author] || 0) + 1;
   return sums;
},{});
let sorted = Object.entries(sira)
    .sort(([,a],[,b]) => b-a)
    .map(([author, count]) => {
        return { user: author, length: count }
    })

Is this how it works?

#

idfk

sudden geyser
#

map takes a collection and returns a new collection by applying a function to each item

#

so yes

sharp geyser
#

I actually have not used js in months

solemn latch
#
  return array.reduce((acc, cur) => {
    let index = acc.findIndex(obj => obj.author === cur.author);
    if (index !== -1) {
      acc[index].count++;
    } else {
      acc.push({user: cur.author, count: 1});
    }
#

👀 ?

sudden geyser
#

even shorter would be .map(([author, count]) => ({ user: author, length: count }))

#

or just to keep the variables the same name to get rid of the colons

alpine swallow
#

@rigid maple

let array = [
  { user: "TuranGe", balance: 25, author: "User1" },
  { user: "popoasd", balance: 255, author: "User1" },
  { user: "Prowdy", balance: 31, author: "User1" },
  { user: "Asd", balance: 1, author: "User2" },
  { user: "Asda", balance: 12, author: "User2" },
  { user: "Asdasd", balance: 11, author: "User3" }
]

let ObjArray = []
let obj = {}

array.forEach(ele => {
  if(ObjArray.includes(ele.author)){
    obj[ele.author] += 1
  }else {
    ObjArray.push(ele.author)
    obj[ele.author] = 1
  }
})
let sorted = ObjArray.map(x => ({user: x, length: obj[x]}))
console.log(sorted)

sudden geyser
#

please don't do that

rigid maple
sudden geyser
#

map returns an array, so I don't see how that'd be the output

rigid maple
#

thanks

alpine swallow
alpine swallow
rigid maple
#

ok thanks for your help

alpine swallow
sharp geyser
#

Ofc that works

rigid maple
#

yes

#

thanks

alpine swallow
sharp geyser
#

All you are doing is looping over the array of objects and any point that it finds a author with the same name it increments

#

its not rocket science

alpine swallow
#

i was asking to see if it fits his needs

sharp geyser
#

I disagree with your method tho

#

I don't like the idea of using forEach over what was originally being used

alpine swallow
sharp geyser
#
let array = [
{ user: "TuranGe", balance: 25, author: "User1" },
{ user: "popoasd", balance: 255, author: "User1" },
{ user: "Prowdy", balance: 31, author: "User1" },
{ user: "Asd", balance: 1, author: "User2" },
{ user: "Asda", balance: 12, author: "User2" },
{ user: "Asdasd", balance: 11, author: "User3" },
]
let sira = array.reduce(function(sums,entry){
   sums[entry.author] = (sums[entry.author] || 0) + 1;
   return sums;
},{});
let sorted = Object.entries(sira)
    .sort(([,a],[,b]) => b-a)
    .map(([user, length]) => ({user, length})

How klay said it would be how i'd do it

alpine swallow
sharp geyser
#

idk if its better but its how i'd do it

sudden geyser
#

it's much better

#

more composable for example

sharp geyser
#

although i've never seen sort used like that

#

no idea what [,a],[,b] is

alpine swallow
alpine swallow
frozen dagger
#

poggythumbsup waiting since a week for bot verification on top.gg

deft wolf
#

Good to know

sudden geyser
#

it can take over a week to get verified

alpine swallow
solemn latch
#

its closer to two weeks right now

alpine swallow
sudden geyser
lament rock
#

Trying to upgrade fans and ram and the case the server came in is proving to be very difficult to work in :/

#

each cpu has 4GB of DDR3

lyric mountain
#

Did u ever think "Maybe I have too many coolers"?

sharp geyser
lyric mountain
#

Besides, won't the top left cooler be blocked by the top right?

solemn latch
#

I would guess its a high airflow server case so it probably wouldn't matter too much? 🤷

lament rock
#

Not super high airflow. I plan on replacing the 2 fans directly on the heat sinks with 2 blowey-ma-trons that blow air towards the back of the case

#

but the fans are soldered to the heat sinks

#

waiting on some 120mm fans to show up at my door

#

the case in question

wheat mesa
#

You can go to thrift stores and pick up old pc cases for pretty cheap, would definitely be interesting to mod it to fit your board and might have better airflow

rustic nova
#

question for python devs who have done web-apps

#

is it possible to just use flask to run a prod website

#

cuz fuck that error message

lyric mountain
#

Sure

#

Same goes for any other webserver framework

boreal iron
eternal osprey
#

I have made a html file, to show a small dashboard. Is it actually possible to also have a discord bot running in the same file?

#

Like, i never tried it, to combine multiple purposes and languages in a singular file

lyric mountain
#

sure

#

not in the html file tho obviously

eternal osprey
#

yeah ofc, thanks for all the help!

lament rock
#

tbh idk if that motherboard even has an rgb controller header

#

likely not because it's a really old platform

boreal iron
#

I highly doubt tbh

#

Got a not that old dual socket system myself but there aren't any rgb pins on the mainboard

#

Which would be really weird imo

#

😅

#

But I'm using certified hardware only anyways and I have never heard of certified server rgb lightning

eternal osprey
#

is the djs v13 channel.messages.fetch max still 200?

lament rock
eternal osprey
#

thanks papi

sharp geyser
#

@earnest phoenix does this look fine?

#

this is what it defaulted to when I made the new build tool config

earnest phoenix
#

That should be good, though the debugger should be LLDB since you're using LLVM

sharp geyser
#

Well apparently not

#

the C Compiler is not correct

sharp geyser
earnest phoenix
#

Clang-CL is both a C and C++ compiler, what do you mean it's not correct?

wheat mesa
#

I should probably switch to clang

#

msvc template errors are absolute hell

sharp geyser
earnest phoenix
#

What's the error?

sharp geyser
#

but yea after changing to use clang this happened

earnest phoenix
sharp geyser
#

a lot of exe and dll files

earnest phoenix
#

Show screenshot

sharp geyser
#

I cant fit it all

earnest phoenix
#

Maybe screenshot once or twice

sharp geyser
#

nvm I can

earnest phoenix
#

Interesting, open a terminal and run clang-cl --version, what does it output?

sharp geyser
#
PS C:\Dev\cpp\LearnCPP> clang-cl --version
clang version 15.0.7
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\LLVM\bin
earnest phoenix
sharp geyser
#

I dont even know how to write C

earnest phoenix
#
#include <stdio.h>

int main() {
  printf("Hello World\n");
}
sharp geyser
#

it turns into an exe file

earnest phoenix
#

So it does work, looking at that CMake error again I think you don't have rc.exe in your PATH

#

What happens when you try to run rc (or rc.exe) in your terminal?

sharp geyser
#

not a recognized cmd

sharp geyser
earnest phoenix
#

Go to C:\Program Files (x86)\Windows Kits, what do you see?

sharp geyser
earnest phoenix
#

Go to 10, and open the directory with the highest version

sharp geyser
#

what version

lyric mountain
#

Love it when finding a compiler is harder than writing the code

sharp geyser
#

lol

#

nvm figured it out

#

I assume its 10/bin/Version/x64

earnest phoenix
#

Yeah

sharp geyser
#

I also see rc.exe in it

#

do I just add that to path?

earnest phoenix
#

Yes, it's strange that it's not in PATH for you

sharp geyser
#

do I add the entire dir to path or only the rc.exe

earnest phoenix
#

The entire directory should be at the PATH

sharp geyser
#

CMake gives 0 errors now

#

ty

earnest phoenix
#

You're welcome

spark flint
#

how do i convert a file object to a buffer?

#

I'm trying to POST a file, but form-data doesn't accept files as objects

#

the object is in the format json { "fieldname": "file", "originalname": "211107600-1e04ba3c-68a4-423c-bc09-ae5ea4fec1ba.mp4", "encoding": "7bit", "mimetype": "video/mp4", "buffer": { "type": "Buffer", "data": [] // very very big array }, "size": 123245 }

#

obvious answer would be to POST file.buffer, but I need the filename, mimetype and size as well

lyric mountain
#

The very big array is your buffer

radiant kraken
#

cmd for life 😎

compact pier
#

Just to install a fucking simple gcc took me like 1 hours

neon leaf
#

is there any noticable difference between a Intel Xeon 26XXv2 CPU and a AMD EPYC 7443p for Minecraft, Databases, Websites, Nodejs & Python?

sharp geyser
#

Probably the worst server to ask /s

earnest phoenix
#

lmao

#
  • has bot dev badge CH_Dead
#

Ctrlc ctrlv bot

neon leaf
earnest phoenix
#

21/20 - using ${} makes your database super secure

#

Also Type ORM is a thing in 2023

neon leaf
#

I do use injection secure statements, just not for the table, where and update are secure

neon leaf
#

I couldnt find a ORM that supports mapping nested json values to database columns

#

so I just made this myself, works fine enough

slender wagon
#

Best lang to make a desktop program?

surreal sage
#

I want to run a bash command which exists for 60 seconds long
It outputs 1 line around every second
I want to save those lines
I want to do this in node with child process
I tried using child_process.spawn but I doesn't give me anything when I listen for messages

#

I want to get the Watts on each line

#

yup all g

cloud agate
#

general question, am i doing this right?
im running a Sanic site (sanic -> uvicorn), its forwarded ufw allow 80and shows up on the domain, everything seems fine.
But i have to run it with sudo sudo python3 main.py or else it fails to bind to port 80 (which from what i understand, is where you run HTTP webservers)

#

never done web/network stuff

#

just wanna know if thats the correct way to be doing it

#

im also getting this "GET /static/js/scroll.js HTTP/1.1" 304 Not Modified

#

no clue what that means

rustic nova
#

The reason why you're getting an error with binding it to port 80 is because sudo executes it with root

#

Anything below 1024 is a privileged port and needs root access

cloud agate
rustic nova
#

Yeah, especially with sudo, thats correct and normal

cloud agate
#

ive never ran a website before so i dont really know if i should be putting it directly on port 80

rustic nova
#

Port 80 is the default http port yeah

cloud agate
#

alr alr, so im right with forwarding 80?

rustic nova
#

Yup with allowing 80 through your firewall

cloud agate
#

also never really messed with that, all i know is you open a port up so you can access smth on a local pc

rustic nova
#

A port is essentially a door on which an application can talk to another application, so when your browser tries to visit yourwebsite.com, it tries to go through that door

cloud agate
#

yeye, thats basically all i know about it

#

ive been told running sanic/flask alone without wsgi or something isnt safe, uvicorn is asgi, so thats performs the same task right?

rustic nova
#

No clue tbf

cloud agate
#

again, all i know is youre supposed to run something over flask/sanic and i saw uvicorn was one of the options

rustic nova
#

Never worked with prod based wsgi lol

cloud agate
#

or something along those lines, not running a web server barebones on a domain

#

ah, ive just straight up never worked in any of this

#

super new to me, ive only done local stuff

#

got a friend that hosts all my stuff and gave me a subdomain so i figured i'd dip my toes in

#

ty for the help, from what ive gathered i think im good to call this 'production' level and leave it running so the sites accessible to everyone

rustic nova
#

I have like 5-6 apps running on barebone flask, never had issues

#

Of course it might have an impact on performance somewhat

#

Though never experienced it

cloud agate
#

im not really worried too much about performance, sanic is async + way faster than flask from what ive heard, so i should be good performance wise

#

sites super simple anyways

rustic nova
#

theres also flask async

frosty gale
#

sonic

rustic nova
#

fast sonic

eternal osprey
#

like, for each single option i created a seperate method.

#

or can i break it down even more?

lyric mountain
#

Eh, pastebin

lyric mountain
#

For example, let's say u had a method to await user input that was repeated 1:1 in many places

#

Instead of writing it everywhere, simply make an awaitInput() method

#

Also, for helper methods always make them static

#

And the enclosing class abstract

#

That way you don't need to instantiate it everytime and you hint to the runtime that it'll never be instantiated

#

@eternal osprey

#

Btw u can use string format instead of concatenation

#

And please, make a helper method for printing

eternal osprey
#

owh i see, thank you!

#

Yup i will try to check if i have lots of functions i keep re-using and create a helper function for it

#

is the code okay tho, or is it fucking astrocious?

#

apart from the above notices

eternal osprey
lyric mountain
#
public static void println(String str) {
    System.out.println(str);
} 
#

That way u can import static your.package.Helper and use println() instead of sout

eternal osprey
#

owh i see, thanks! I haven't covered that in the course yet but it will definitely look better!

#

The code right now is already a bit more broken down into smaller parts, however some methods/functions don't really get used a lot so i cannot break it down further then right?

#

I mean, it would be strange to have a whole method for only 1x use

earnest phoenix
#

plz help 🙂

#

Z9WK-F47D-F6SH-5LPY-HBYX

deft wolf
#

What is Structures.js?

earnest phoenix
sudden geyser
#

looks like some gift code

earnest phoenix
earnest phoenix
jovial nimbus
#

this.parentNode.querySelector('input[type=number]').stepUp()
Why not read parentNode in react

earnest phoenix
#
TypeError: Class extends value #<Object> is not a constructor or null
    at Object.<anonymous> (/home/runner/all-in-one-discord-bot/node_modules/discord.js/src/structures/TextChannel.js:15:27)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (/home/runner/all-in-one-discord-bot/node_modules/discord.js/src/util/Structures.js:96:16)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
sudden geyser
#

you're trying to extend something that isn't extendable

earnest phoenix
lyric mountain
#

Bad idea

earnest phoenix
sudden geyser
#

what version of node.js are you using

earnest phoenix
lyric mountain
#

No idea without seeing the code

#

Or knowing the node version

#

U should really try to learn how to make a bot, instead of copying from somewhere

#

If it ever breaks (and it will) you'll be left hopeless with a non-working code that u don't know how to fix

lyric mountain
#

For instance, what kind of bot is it?

earnest phoenix
#

btw how to know node version? i m on replit

lyric mountain
#

node -v

earnest phoenix
#

moderation & utility

#

k

lyric mountain
#

Doesn't seem too hard to make from scratch, but you need knowledge on how js works

earnest phoenix
#

ReferenceError: node is not defined

lyric mountain
#

U should run in on the console

#

Not on the code

earnest phoenix
#

its on console only

#

v12.22.10

lyric mountain
#

U were inside node, that's why it errored

#

v12 is...old

earnest phoenix
#

how to update?

lyric mountain
#

Well, for replit it's a bit tricky, I'll need @sudden geyser here

earnest phoenix
#

ok

sudden geyser
#

search google

#

they should let you set the node version

#

though using repl.it as a host is generally a bad idea

earnest phoenix
#

whats the latest version of node.js?

#

16?

lyric mountain
#

19, but it's probably not LTS

earnest phoenix
#

ohk

lyric mountain
#

Anyway, isn't there any bot on topgg that does what u need already?

earnest phoenix
#

yeah but....uk a feeling of self hosted bot hehehe

lyric mountain
#

Well, I do know what u mean, but you're up to a lot of work keeping it alive

earnest phoenix
#

yeah

earnest phoenix
# earnest phoenix 16?

The current latest LTS (known as the stable release) is v18, the latest non-LTS release is v19

earnest phoenix
#

running apps only made in js

neon leaf
#

Performance 📉

earnest phoenix
#

no

#

v8 is very fast

granite remnant
lament rock
#

I bought myself a kvm and didn't even bother to check if I had enough display port cables

lament rock
#

keyboard, video, mouse

#

a switcher where you have inputs that can change between PCs

#

instead of peripherals per PC

earnest phoenix
#

At first thought someone finally also uses KVMs but apparently not

#

Disappointed disappoint

lament rock
#

now which KVMs are you talking about

#

the linux VMs?

quartz kindle
#

imagine having a central pc with multiple screens in different places in the house

#

and each screen be its own desktop

#

but sharing the same pc

#

lmao

lament rock
#

would be cool

quartz kindle
#

and make it voice activated

#

"computer, move to the kitchen"

#

turns on kitchen tv and shows main desktop

compact pier
#

It is kinda cool tho, but I think you need a lots of pc to do that

#

or maybe rasberypie

#

I tried to make a smart home with some wifi controler module

#

and it works :)))

#

cutting some wires, connect it to the boards and then control it with your phones, kinda cool tho

lament rock
#

could definitely do something akin with home assistant

quartz kindle
#

and be able to move the pc from screen to screen without having to plug/unplug cables

eternal osprey
#

is typcasting a bad thing to do?

#

typecasting* in java

#

i want to convert doubles to an integer

lament rock
eternal osprey
#

yeah indeed, i just created one seperate hlper function for doubles and one for integers

#

that way i could work around it, thanks papi!

eternal osprey
#

why would an interface extend another interface?

#

Like it doesn't make sense, why don[t the classes just implement that focking interface directly instead of first extending it and hen implementing it

lyric mountain
#

the same reason a class extends a class

#

sometimes you want to add an additional methods to the interface, and usually u cant modify the original code

#

so waddya do? you extend it

eternal osprey
#

i see, so if in one interface i got the void checkoption(string x) method, and i extend that interface to another interface, in that supertype i have to put the checkoption(string x) again right?

#

or should i already define it in the subinterface?

#

and what about the classes? Should they implement the new interface as well? Or only the old (sub) interface?

lyric mountain
#

no

eternal osprey
#

sorry for all the questions, but i can't find good sources online about these questions

lyric mountain
#

interfaces don't (and can't) need to implement the super-interface's methods

#

it'll just inherit the contract

#

think of it like a sum

#

so ```java
public interface ContractA {
void doShit();
}

with ```java
public interface ContractB extends ContractA {
  void doSmth();
  // void doShit(); <-- inherited
}

will result in a sum of ContractA + ContractB

#

meaning any class that implements ContractB will automatically be implementing ContractA

eternal osprey
#

Ooowh i see!

#

We basically import all the methods from one interface to another?

sudden geyser
#

inherited interfaces looks suspect

lyric mountain
#

it's the only way to add additional clauses to interfaces if u can't modify the original code

eternal osprey
#

so any class implementing contractA will also be implementing the methods of contractB !

lyric mountain
#

no

#

inheritance only works one way

#

a class that implements ContractA doesn't implement ContractB

#

only the other way around

eternal osprey
#

oowh yeah i know i read it wrong

#

it's the other way around indeed, my bad

lyric mountain
#

so ContractB = (ContractA) theObject; will work, ContractA = (ContractB) theObject; will error

sudden geyser
#

why would you want to add additional clauses to existing interfaces as opposed to creating a new one

lyric mountain
#

for compatibility reasons, instead of changing the old interface they chose to extend it into Graphics2D

#

which works with every Graphics application, but contains additional methods

#

plus every java2d classes were changed to always use Graphics2D, but they still return as Graphics

#

simply because it'd break existing applications

eternal osprey
sudden geyser
#

you still don't need an extended interface for that when you can just implement both interfaces separately

lyric mountain
#

which by instance also have ContractA

#

so SomeClass { ContractB { ContractA } }

eternal osprey
#

Ahh yeah indeed!

eternal osprey
#

Okay i understand it now, honestly inheritance is pretty cool

lyric mountain
#

you'd need to have twice as many methods just because you're using two separate interfaces

#

and that'd mean twice as much work using said framework

#

when extending would solve any and every compatibility issue

#

for example, to get a graphics2d instance u do var g2d = someImage.createGraphics()

sudden geyser
#

no, you'd create interface 2 while leaving interface 1 alone

#

so you aren't duplicating methods

lyric mountain
#

don't think u get the real reasoning

#

like, they needed to add more (and useful) methods to the Graphics interface

#

but doing so might break existing code (for example, implementing classes that happened to have identical method signatures)

#

if u implement 2 interfaces u still can't use the two at once

#

because one would not be translatable to the other

#
public class Stuff implements ContractA, ContractB {
  ...
}

I cannot reasonably know that every ContractA will have the methods from ContractB

#

meaning I'd need to check for which interfaces said class include

#

plus, when extending interfaces u don't need to re-type every single method, u just write the new ones

#

say it Hohse, no need to wait for us

#

create an array of that sequence and print it

quartz kindle
#

or use process.stdout.write (nodejs only)

opaque solar
#

howdy ❤️

eternal osprey
#

kuu, you are awesome btw

sudden geyser
#

Take this for example:

public interface Organism {
  public void create();
}

public interface Animal {
  public void trick();
}

You aren't duplicating create in Animal, nor are you using extends. This leaves an interface alone to be concerned truly about itself. If you want create and trick, you say so at the signature level (at least, it should be that simple).

Breaking existing code isn't done here (nor is a concern here), plus that's more a limitation of all interface methods being required, as opposed to opt-in.

eternal osprey
#

honestly, just wanted to let ya know. Thanks for all the help! You saved a few hours (and fucking brain meltdown) by answering my questions

lyric mountain
#

for example

#

you'd not be able to do this if you're using 2 interfaces (and don't which class will be supplied)

#

this is exactly why Graphics2D extends Graphics

#

you need the methods from Graphics, but also the methods from Graphics2D, and you have no idea what class will be coming from the caller

#

the only way that'd work (without extending) is if you replicated the methods from A to B, which would break the "single responsibility" rule

sudden geyser
#

oh, so java doesn't support multiple interfaces on a thing

lyric mountain
#

it does allow multiple interfaces

#

but not extending

#
public class Stuff implements InterfaceA, InterfaceB, InterfaceC, InterfaceD {
  ...
}
#

but it can only have a single superclass

#

for generics, it can have <T extends InterfaceA & InterfaceB>

#

it's just looked down upon because u can't cast T to either interface

#

so u can't also pass it as an argument unless the function allows that exact ancestry

#

no wait, might've confused this part

#

anyway, there're reasons stated on the net, too tired to think abt it now

lament rock
lyric mountain
#

that'd mean implements this or that

#

which isn't a thing that exists

errant flax
#

why am i getting this error

TypeError: crypto.createHash is not a function
#

afaik it is a function angeryBOYE

scenic kelp
#

nodejs? what version

errant flax
#

how do i check again

scenic kelp
#

node --version

errant flax
#

v19.2.0

scenic kelp
#

i mean that's valid so

#

and that's with v16

errant flax
#

how do i fix it MegaThonk

scenic kelp
#

idk 💀 could you share some more of the file that is causing the error?

errant flax
#

like what

scenic kelp
#

as much as you feel comfortable sharing, it'd be nice to see where you're defining crypto etc

errant flax
#
const json = JSON.stringify(options.data)
        const md5 = await crypto.createHash("md5").update(json).digest("base64")
#

this is the whole function

async setEntry(options,universe_id){
        const id = universe_id || this.client.data.global_universeId

        if (!id) {throw "DATASTORE: universe_id is not available nor gloval_universeId!"}
        if (!options) {throw "DATASTORE: options is a reqired parameter!"}

        options.datastoreName = this.name

        if (!options.datastoreName) {throw "DATASTORE: There is no datastoreName set for this class!"}
        if (!options.key) {throw "DATASTORE: Please provide a key to get the data from!"}
        if (!options.data) {throw "DATASTORE: Please provide a data in order to update the entry!"}

        const json = JSON.stringify(options.data)
        const md5 = await crypto.createHash("md5").update(json).digest("base64")

        const res = await axios.post(url+`/universes/${id}/standard-datastores/datastore/entries/entry`,options.data,{
            params: {
                'datastoreName': options.datastoreName,
                'entryKey': options.key
            },
            headers: {
                'x-api-key': this.client.data.api_key,
                'content-md5': md5,
                'content-type': 'application/json'
            }
        }).catch(err=>{
            console.log(err.response.data)
        })
        if (res) {
            return res.data
        }
    }
scenic kelp
#

and i'm assuming crypto is defined properly with a require/import? that's the only thing i could think of

#

cause in console that line works fine

errant flax
#

oh wait i have to define it

#

i thought its built in

scenic kelp
#

it is built in but you have to import it

errant flax
#

oh

scenic kelp
#

and if it wasn't being imported you should get a ReferenceError

errant flax
#

now its working

scenic kelp
#

oh wack

errant flax
scenic kelp
#

and it also works for me without importing it so idk

#

but hey at least it works /shrug

#

i'm not a js dev anymore so the wonders of this language are beyond me

errant flax
#

if it works it works

#

dont question the logic

hushed robin
#

how i make my bots status mobile

hallow shell
#

can i use the top.gg logo to link to my bot's vote page?

#

i noticed this in the terms of service which seems related

lyric mountain
#

Dbots?

#

Anyway, don't think "redirect to vote page" counts as commercial usage, so ur fine

#

Especially since it'll be redirecting to the original site

sudden geyser
lyric mountain
#

Eh, so it used to be called dbots?

hallow shell
#

here's how i'm going to use it by the way

lyric mountain
#

It's not commercial usage, it's fine

earnest phoenix
#

How do you make it say "[bot] is thinking..." with slash commands with discord.js

#

Like not make the bot respond with that but to just change the text after it says "Sending command"

deft wolf
#

Do you mean to edit the response?

earnest phoenix
#

With some bots it changes to "[bot] is thinking..."

wheat mesa
deft wolf
#

Yea

#

But then you have to replace any interaction.reply() with interaction.editReply()

lament rock
#

If you can respond immediately, do that instead of deferring the reply

#

You'd only end up hitting rate limits faster if you were adamant on showing thinking

quartz kindle
#

at least deferring has no limits, followups might have

lament rock
quartz kindle
#

that makes no sense because interactions are initiated by discord, they have to expect a response for the thing they themselves initiated

lament rock
eternal osprey
#
public void findMatches(String option, double[] toRevert) {
        if (option.equals("x")) {
            for (int i = 0; i < allObjects.length; i++) {
                if(!alreadyNull(i)) {
                double toFind = allObjects[i].getXCoordinate();
                for (int j = 0; j < toRevert.length; j++) {
                        if (toFind == toRevert[j]) {
                            allObjects[j] = allObjects[i];
                        }
                    }
                }
            }
        }```could someone tell me why this returns me 2x the normal amount?
#

Allbojects only contains 2 elements, but it returns me a duplicate

lyric mountain
#

?

sturdy vale
#

how can i make one

lyric mountain
#

it's kinda like a contract where you state what, why and when you'll be doing

#

it's basically a legal document

sturdy vale
#

and after a write one that need a link

lyric mountain
#

there's no "right one", you write what fits to your app

#

after writing it just put it somewhere publicly available and grab the link

sturdy vale
#

its write not right sorry

lyric mountain
#

if u have a public github repository u can write one there and use the url

#

otherwise any text host will suffice really

#

even some endpoint in your own server

sturdy vale
#

okay

hushed robin
lyric mountain
hushed robin
lyric mountain
#

that path doesn't look correct

#

show how ur file structure is

hushed robin
#

what's wrong with it

hushed robin
lyric mountain
#

and where is that code located?

hushed robin
lyric mountain
#

try ../database.db

hushed robin
#

same error

#

(yes the table exists)

lyric mountain
#

try executing SELECT name FROM sqlite_schema WHERE type = 'table' AND NOT LIKE 'sqlite_%'

sudden geyser
#

try just database.db

lyric mountain
#

show what it outputs

#

ah yeah, try what klay said first, to be sure

hushed robin
#

ah

#

thank you

#

worked

sudden geyser
#

ah my theory is correct

#

it runs at the project root

lyric mountain
#

hm, then better-sqlite3 uses the project root instead of relative path

hushed robin
#

ty both of you ‼️

carmine summit
#

Discord outdated command won't disappear..

lament rock
#

always use absolute paths for everything even if you don't think you need it. You need it

#

modules that accept relative paths should have require like module resolution and it's dead easy to do

earnest phoenix
deft wolf
#

I would never have thought of doing a database in .yaml files

earnest phoenix
#

Pretty original indeed

#

Even slower than JSON 3HC_Stonks

#

You should open an issue on the repository you cloned, maybe they'll help you @earnest phoenix CatJAM

deft wolf
#

Ah, those YouTube tutorials

#

They don't explain anything and then people don't know what to do

sturdy briar
#

@gilded plank

neon leaf
#

does anyone know how to fix it? my gitlab & runner are containerized and I want to connect to my registry from my workflow

#

the thing is, I am using my public registry url

#

i have no clue where ist getting docker: from

neon leaf
#

I just got preogress though by changing the executor

tulip ledge
#

I'm trying to embed calendly into my react site but it gives me html which i cant use in jsx as it contains the script tag any idea how to solve? I'm trying to add this to my react app:

<link href="https://assets.calendly.com/assets/external/widget.css" rel="stylesheet">
<script src="https://assets.calendly.com/assets/external/widget.js" type="text/javascript" async></script>
<script type="text/javascript">window.onload = function() { Calendly.initBadgeWidget({ url: 'https://calendly.com/vigintillion/consultation', text: 'Book a call', color: '#0069ff', textColor: '#ffffff', branding: undefined }); }</script>
#

nvm found an npm package

low orbit
#

how can i add a delay before rerunning the animation?

lyric mountain
#

I think u can use seconds instead of percent

low orbit
hushed robin
#

⁉️⁉️

#

what does this mean

quartz kindle
#

you tried to set a choice value to that string, but it was expecting a number, not a string

quartz kindle
flat copper
#

helloo
i have a number
p = 47

if(p => 0 && p <= 10) {
 console.log("rare")
}

why its console.log rare?

sudden geyser
#

=> is an anonymous function

#

which presumably takes an arg p and returns 0, which will just always be true in the condition since functions are truthly

#

what you meant is 0 <= p && p <= 10

lament rock
#

(I have nothing better to do)

sudden geyser
#

go away

#

please js gods add x <= y <= z

rustic nova
#

if p > 10 && p < 10

tulip ledge
rustic nova
#

if (!true)

carmine summit
#

Can webhooks have buttons?

earnest phoenix
tulip ledge
rustic nova
#

if (true-true)

wheat mesa
#

if(true ^ true)

tulip ledge
#

if (1 >> 1)

lyric mountain
#

if (--true)

quartz kindle
#

@_@

#

Tim is a user, it cannot be equal to a channel

#

:^)

compact pier
#

well then ==

eternal osprey
#

does anyone know what the super keyword means?

lyric mountain
#

this = this class
super = parent of this class

dusky fog
quartz kindle
dusky fog
#

Ohh, thanks :)

wicked pivot
#

Hello, I have a little problem about a file. At the time of launching I look at the content but if I modify this file with another program that if is not updated.

const file = fs.readFileSync(".......", 'utf-8')


setInterval(() => {
    console.log(file)
}, (1000));```

Is there an alternative to FS.readFile for this?
dusky fog
wicked pivot
# dusky fog tu veux faire quoi?

plus simple en français, en d'autre mot.

Check le ficher tous les X temps et voir le changement car il est modifier par un autre programme mais avec fs.readFileSync il prend le changement en compte

dusky fog
#

tu veux vérifier chaque 1s si y'a un changement ?

wicked pivot
#

c'est un exemple ouais (il n'est pas modifié par l'application qui check important a précisé)

dusky fog
#

tu stocks le contenu du fichier en chaine de caractère

const content = JSON.stingify("LE CONTENU DE TON FICHIER")

//et tu fais une nouvelle vérification de contenu
setInterval(() => {
  const newContent = JSON.stringify("LE CONTENU DE TON FICHIER")
  if(content === newContent) return false; //Aucune modification faite
}
, 1000)
quartz kindle
#

then you are just logging the saved variable again and again

wicked pivot
quartz kindle
#

the value will always be the same

half prawn
#

I need help

#
TypeError [ClientMissingIntents]: Valid intents must be provided for the Client.
    at Client._validateOptions (/home/runner/Aguapanela-con-queso/node_modules/discord.js/src/client/Client.js:489:13)
    at new Client (/home/runner/Aguapanela-con-queso/node_modules/discord.js/src/client/Client.js:78:10)
    at Object.<anonymous> (/home/runner/Aguapanela-con-queso/index.js:2:16)
    at Module._compile (node:internal/modules/cjs/loader:1159:14
#

I don't understan, what is my mistake?

wheat mesa
#

You didn’t give any gateway intents when logging in

#

Aka you need to pass in the intents parameter when instantiating your client

#

It’s in the djs guide if you’re struggling

low orbit
vale notch
#

what is the code for reaction role (python 2023) ?

wheat mesa
#

I mean, we’re not YouTube

#

Probably a question better suited for google than us

#

(Unless you get more specific)

lyric mountain
#

"(python 2023)" is literally a typical quickhacks youtube video

wheat mesa
#

Yeah lol

lyric mountain
#

(working | verified 2023 | no code | check desc)

wheat mesa
#

(github repo in desc | quick and easy | no experience needed | copy paste | certified by dev)

quartz kindle
#

(works like magic | sorcery | wizardry | for dummies | literally click and run)

sudden geyser
#

(works | thanks mom)

sharp geyser
#

I shall end the joke here before it runs for too long

wheat mesa
#

(rework 2023.2 | patch bypassed | can’t stop us)

harsh nova
quartz kindle
#

(family friendly | PG13 | safe | clean | no virus | on topic)

harsh nova
#

Pain and suffering

hushed robin
#

🤯🤔‼️

wheat mesa
#

What

hushed robin
#

i need help

#

please help if you can

#

🙏

wheat mesa
#

I don’t understand the question

hushed robin
#

ok

#

so

#

what don't you understand

wheat mesa
#

The question

#

In its entirety

hushed robin
#

bruh

#

its returning wrong thing

wheat mesa
#

And what is it supposed to return

#

Because I don’t see any returning here

hushed robin
#

for example, if it's members, it should return Members: as the typeTitle, but it's returning Playing:

quartz kindle
#

he's saying the variable typeTitle is not being set

#

by the switch cases

#

its always setting it with the first switch case value

hushed robin
#

but it's returning the data from the API correctly

#

which i don't get

wheat mesa
#

Can I see where you declare typeTitle

hushed robin
#

right there

#

look up

wheat mesa
#

There is no declaration there

hushed robin
#

👆

wheat mesa
#

Just assignment

quartz kindle
#

declaration means var/let/const

hushed robin
#

I have to declare it?

wheat mesa
#

Yes

hushed robin
#

🤨

#

ok but

quartz kindle
#

otherwise its implicitly a global

sharp geyser
hushed robin
#

why is it working with one but not the other

#

is my real question

wheat mesa
hushed robin
#

typeData is returning what it should

sharp geyser
#

type could also only just be returning playing

hushed robin
#

it’s not

#

I checked

#

I’m not that dumb

sharp geyser
#

well

quartz kindle
#

are you running that switch case more than once?

hushed robin
#

no

quartz kindle
#

show more code pls

hushed robin
#

what code

sharp geyser
#

💀

quartz kindle
#

whatever comes before and after that switch

wheat mesa
#

Do you happen to have another variable called “typeName” somewhere else in your code

#

Anywhere in your code

hushed robin
#

well one second let me check

#

I’m cooking food 🥘

wheat mesa
#

let him cook

hushed robin
quartz kindle
#

??

hushed robin
#

there’s nothing before it

quartz kindle
hushed robin
quartz kindle
#

and after?

hushed robin
#

nothing

quartz kindle
#

no return?

hushed robin
#

wym?

quartz kindle
#

its a function that does not return anything?

hushed robin
#

it does

#

at the end

quartz kindle
#

then show

hushed robin
quartz kindle
#

ok, so dont use globals

#

use let

wheat mesa
#

^^

hushed robin
#

is that the issue

quartz kindle
#

yes

wheat mesa
#

Probably

#

If not then it’s a damn cosmic ray hitting your pc

hushed robin
#

well

#

we will see soon

wheat mesa
#

Or there’s something else you’re not showing

hushed robin
#

bruh

#

there's not

#

⁉️

quartz kindle
#
let typeTitle;
let typeData;
switch(...) { ... }
return { typeTitle, typeData }
hushed robin
#

thats it besides the part where i convert the typeData into a locale string

wheat mesa
quartz kindle
#

the thing is, global variables are bad unless you know what you're doing

hushed robin
#

well

wheat mesa
#

Aka they’re bad unless you’re Tim

quartz kindle
#

in your case your function is setting 2 global variables, one of them is sync, the other isnt

hushed robin
#

is that why only one is working

quartz kindle
#

so every time you call the function, it immediately sets the sync variable, but the async variable not yet

#

by the time the async variable finishes setting, the sync variable may have been overwritten by the next time the function is called, because its global

sharp geyser
#

makes sense

hushed robin
#

good news

#

that was the issue ⁉️

#

Ty guys

wheat mesa
#

If you don’t do variable declarations anywhere else in your code I’d highly recommend changing that now

#

Since it can lead to mysterious bugs such as this

hushed robin
#

I do

#

for some reason I’m slow though

#

🤷

lyric mountain
#

I unironically didn't notice there was a switch-case until yall mentioned it

#

Please add an indent level inside cases

hushed robin
#

ok

#

why tho

wheat mesa
#

Readability

lyric mountain
#

Because no indentation makes it hard to spot where the cases are

#

Sometimes I wonder why didn't js get the enhanced switches yet

#

Usually it gets qol features before other langs

hushed robin
#

where should i indent

lyric mountain
#

After the case

quartz kindle
#

i like doing mine like this

switch(a) {
  case b: {
    doC();
    break;
  }
}
wheat mesa
#

Same

lyric mountain
#

It's been ages since I wrote switches like that, but I also used braces

quartz kindle
#

or like this if its a one liner:

switch(a) {
  case b: doC(); break;
}
wheat mesa
#

Or even better return doC() if you’re returning

#

That’s always satisfying

quartz kindle
#

ye

wheat mesa
#

No need for a break statement

#

But it’s rare

quartz kindle
#

and for multi-case cases:

switch(a) {
  case b: case c: {
    doBorC();
    break;
  }
}
wheat mesa
#

It’s interesting that even with such a simple control flow concept as a switch case there’s so many tricks with it

lyric mountain
wheat mesa
quartz kindle
wheat mesa
#

But yeah that’s the idea

hushed robin
#

ok

sharp geyser
#

damn late message

quartz kindle
sharp geyser
#

discord laggedfor me

lyric mountain
#

And doesn't lock your variable names

#

Which sucks

quartz kindle
#
switch(true) {
  case a > 10: {
    ...
  }
}
sharp geyser
#

interesting

#

makes sense that'd work but I have never used em like that

hushed robin
#

this ?

wheat mesa
#

Much better

hushed robin
#

ok

sharp geyser
#

Want to experience some fun? remove those breaks trollface

quartz kindle
#

:^)

hushed robin
#

what would happen

wheat mesa
#

They would all run

#

Sequentially

hushed robin
#

bruh

sharp geyser
#

it would go through every case if it evaluates properly

lyric mountain
#

I like groovy switches

return switch (value) {
    case { it > 10 } -> "Bigger than 10"
    case String -> "Isn't even a number"
    case 5 -> "Is five"
} 
quartz kindle
#

i believe default ts and eslint disallow switch fallthrough lmao

hushed robin
#

why

wheat mesa
#

Really?

#

I hate when langs do that

#

Switch fall through is genuinely useful

sharp geyser
#

pretty sure I could do switch fallthrough with ts

wheat mesa
#

Well yeah but ts is nothing more than a suggestion tbh

sharp geyser
#

yea

wheat mesa
#

You can always tell the compiler to shut up and it’ll listen

#

I believe up until recently (or maybe even still) C# treated falling through as a compile error

sharp geyser
#

Can you use switches to determine the type of something like what haku did

quartz kindle
wheat mesa
#

There’s some tricks but I don’t believe there’s a solid way to do like switch(typeof someObj)

hushed robin
#

guys

lyric mountain
#

In java it'll be possible next version

hushed robin
#

what does break do outside of switch

lyric mountain
#

Plus auto-casting

sharp geyser
#

nothing I dont think

wheat mesa
#

Stops a loop body

sharp geyser
#

unless you are in a loop

wheat mesa
#

Probably some other stuff too but not sure about those use cases

sharp geyser
#

tho your IDE will probably warn you if you use break outside of the appropriate use cases

lyric mountain
#

The only other usage is breaking out of named loops

wheat mesa
#

Oh yeah

sharp geyser
#

named loops?

wheat mesa
#

Very niche

hushed robin
#

so break in loop = loop end

#

?

quartz kindle
#

switch(typeof) is a thing in js, idk about other langs

quartz kindle
#

yeah?

wheat mesa
#

Oh well i guess typeof is just an operator that returns a string

quartz kindle
#

yup

wheat mesa
#

I forgor

quartz kindle
wheat mesa
#

Was thinking more like Java where there isn’t a solid way to do it

hushed robin
#

oh

#

nice

#

i wwas wondering how to do that

#

so is switch just a loop 🤨

lyric mountain
wheat mesa
#

No

quartz kindle
#

no

lyric mountain
#

Shitty example, but it'll do

quartz kindle
#

switch is like if-else

wheat mesa
#

It’s based on context

#

Switch statements are just syntactic sugar for if else essentially

quartz kindle
hushed robin
#

what is a

#

"""syntactic sugar"""

lyric mountain
#

Most langs have it, can also name blocks in java

wheat mesa
#

Basically just means a more friendly way to write something

sharp geyser
hushed robin
#

i see

quartz kindle
#

thinks that make code easier to understand, but under the hood does the same thing as you would do with more complicated code

lyric mountain
hushed robin
#

so like .some?

wheat mesa
#

“Syntactic sugar” usually means you can write something in one way, but the “sugar” is that you can do it in a nicer way

lyric mountain
#
block: {
    ...
}
sharp geyser
#

I wonder if C++ has named loops

lyric mountain
#

Probably

wheat mesa
#

Basically every language feature over machine code could be considered syntactic sugar though by that definition I suppose 😆

lyric mountain
#

It's pretty useful, especially if ur doing image ops

hushed robin
#

my bot is now fully using sqlite no more discord messages database 😵‍💫

lyric mountain
#

Excuse me?

sharp geyser
#

Wtf

hushed robin
quartz kindle
#

wait wrong reply

quartz kindle
hushed robin
#

should i use for of will it really make a difference

sharp geyser
#

Are we just going to ignore that this guy used discord messages as a database?

hushed robin
#

yes

quartz kindle
#

yes

sharp geyser
#

thats more unreliable than json

hushed robin
#

no longer though it's now sqlite

#

kuuhaku recommended me better sqlite so after a day of some hard brain thoughts i switched

quartz kindle
sharp geyser
#

sqlite is by far the easiest of them

hushed robin
#

it looks prettier

sharp geyser
#

I dislike the way forEach looks

#

I rather use the conventional for loop

hushed robin
#

also guys

sharp geyser
#

Im also pretty sure forEach is slower compared to a conventional for of loop

hushed robin
#

my bot is in 75 guilds but i can't verify it

#

whyyyyy

quartz kindle
#

actually, for(const item of array) itself is a syntatic sugar for for(let i = 0; i < array.length; i++) { const item = array[i] }. unlike array.forEach, those two for loops do exactly the same thing under the hood

#

well not actually exactly, but semantically the same thing

#

for(... of) will always be a bit slower

sharp geyser
#

in the bigger scope of things is for of faster then forEach?

quartz kindle
#

for..of should be roughly the same performance as array.forEach