vince
vince
Explore posts from servers
KPCKevin Powell - Community
Created by vince on 11/1/2024 in #front-end
Sass Mixin vs Extends
I had a quick question I wanted to ask regarding this. I have some files in a shared directory that I want to namespace.
>scss
->shared/
-->_forms.scss
>scss
->shared/
-->_forms.scss
I want _forms.scss to have reusable styling that I can use in other classes around the codebase. I don't need any argument features that mixin supports - I really just need it to work like extends. The problem is, I can't namespace extends. So if I try to do:
@use "@shared/forms" as f;

.form {
@extend f.%form; // error!
@use "@shared/forms" as f;

.form {
@extend f.%form; // error!
This doesn't work. I can however do this with mixins:
@use "@shared/forms" as f;

.form {
@include f.form; // success!
@use "@shared/forms" as f;

.form {
@include f.form; // success!
The problem is, this is leading to single line mixins:
@mixin commerce-layout-padding() {
padding: t.$sp-xs;
}
@mixin commerce-layout-padding() {
padding: t.$sp-xs;
}
My question is, is this a totally valid use case, or am I in the complete wrong direction and I should quit as a webdev? 😂
110 replies
KPCKevin Powell - Community
Created by vince on 10/31/2024 in #os-and-tools
How to use Webpack as a way to compile Sass -> Css?
This is probably a stupid question, but I have been trying this for the past 2 hours and can't figure it out. I just need a way to compile my regular .scss files (in every directory) into 1 .css file. I'm aware I can just use sass --watch, but I'd like to have some other features webpack leverages (like minifying, and again I know sass ootb can do this). We use Laravel Mix, which is just a library on top of Webpack that can do this using mix.sass('entry.scss', 'output.scss'), but I can't get it to work on default Webpack. The reason why I want to go from Mix -> Webpack is because I need to watch all files in my project and output it as 1 css file and Mix can't do this
16 replies
KPCKevin Powell - Community
Created by vince on 10/30/2024 in #front-end
Variable font-weight shenanigans
No description
2 replies
KPCKevin Powell - Community
Created by vince on 10/29/2024 in #os-and-tools
How do I install npm & composer on cPanel?
Having trouble finding a clear tutorial on how to do this, and whether this should be installed globally as the root or per cPanel user. Running Linux and I have access to the Yum package manager, so should I just install per-user using yum?
50 replies
DIAdiscord.js - Imagine an app
Created by vince on 10/26/2024 in #djs-questions
Quick question on managers
I just wanted to ask a quick question on managers (specifically a GuildMessageManager): how do I use this? Is it a class I need to instantiate or what?
7 replies
KPCKevin Powell - Community
Created by vince on 10/24/2024 in #front-end
Should I future-proof this component or leave as designer intended?
No description
8 replies
KPCKevin Powell - Community
Created by vince on 10/21/2024 in #back-end
How to build this db model
Working on a NoSQL implementation of this discord bot me and my friend are setting up. What it'll do is iterate through all messages and get the amount of emojis each user has across all their messages. I was wondering what a good model for this would be? Should we build a model for each User, and then iterate through all their emojis? I have this so far:
type Emoji = {
emoji: string;
count: number;
};

export default class User {
constructor(
public server: string,
public username: string,
public emojis: Emoji[],
) {}
}
type Emoji = {
emoji: string;
count: number;
};

export default class User {
constructor(
public server: string,
public username: string,
public emojis: Emoji[],
) {}
}
This way, we can just do something like:
// psuedocode
const serverUsers = users.filter((user) => {
return user.server === server;
});

users.sort((a, b) => {
const userACount = a.emojis.find((emoji) => {
return (emoji.emoji === 'chart').count;
});

const userBCount = b.emojis.find((emoji) => {
return (emoji.emoji === 'chart').count;
});

return userACount > userBCount; // I know this won't work lol gotta think about it
});
// psuedocode
const serverUsers = users.filter((user) => {
return user.server === server;
});

users.sort((a, b) => {
const userACount = a.emojis.find((emoji) => {
return (emoji.emoji === 'chart').count;
});

const userBCount = b.emojis.find((emoji) => {
return (emoji.emoji === 'chart').count;
});

return userACount > userBCount; // I know this won't work lol gotta think about it
});
17 replies
KPCKevin Powell - Community
Created by vince on 10/9/2024 in #front-end
Does it make sense to use the title attribute for this?
No description
10 replies
KPCKevin Powell - Community
Created by vince on 10/7/2024 in #back-end
[Twig] Is there a way to clean up this dynamic string?
I'm trying to build a dynamic class string:
{% set classes = 'custom-image ' ~ alignment ?? '' ~ ' ' ~ decoration ?? '' %}

<div class="{{ classes|trim }}">
{% include "_components/image.twig" with { image: image.asset } %}
</div>
{% set classes = 'custom-image ' ~ alignment ?? '' ~ ' ' ~ decoration ?? '' %}

<div class="{{ classes|trim }}">
{% include "_components/image.twig" with { image: image.asset } %}
</div>
This works, but it's kind of messy. I'd also like to eventually be able to have 'alignment' be something like alignment-<alignment> rather than the value. So for example, if alignment = left, right now it just adds left to the class list because it's easiest. But I'd like it to add alignment-left to the class list instead. I know how I can do this but not without making it messy. And even this current iteration, it's not perfect because if alignment is null, then it'll add 2 spaces instead of just one.
15 replies
KPCKevin Powell - Community
Created by vince on 10/3/2024 in #front-end
Does `aria-labelledby` work if the id is on a parent element?
No description
5 replies
KPCKevin Powell - Community
Created by vince on 9/25/2024 in #front-end
`@font-face` variable font issue
Quick question, my font-face declaration with a variable font file isn't changing the font weight when I change it via css:
@font-face {
font-family: "Open Sans";
src:
local("Open Sans"),
url("/assets/fonts/open-sans.woff2") format("woff2");
font-weight: 100 900;
font-style: normal;
}
@font-face {
font-family: "Open Sans";
src:
local("Open Sans"),
url("/assets/fonts/open-sans.woff2") format("woff2");
font-weight: 100 900;
font-style: normal;
}
When I go in dev tools and change the font-weight, it doesn't actually change it. It's not a styling conflict. This is a variable font downloaded from Google Fonts
53 replies
KPCKevin Powell - Community
Created by vince on 9/11/2024 in #back-end
Is there a quick way in vanilla PHP to log things?
I have only the basic PHP extensions available in the default PHP installation. Just wondering if there was a quick and easy way to log data in the backend? I'm using error_log but that's stopping the application it seems when I use it so need something that won't stop the app and log the data to a file
72 replies
KPCKevin Powell - Community
Created by vince on 7/17/2024 in #os-and-tools
ELI5 Gradle and Docker
Hey guys, I think I just have a fundamental misunderstanding of gradle and docker. I have this codebase at work that builds with gradle and sets up a docker container locally. I was having trouble with the gradle build and it was failing the build. I reached out to another developer and they mentioned that I need to build the project with Java 11 (I had Java 22). I was able to build successfully then by doing ./gradlew -D org.gradle.java.home='<path-to-jdk-11>' I'm confused though because shouldn't docker be handling the dependencies (separate from a package manager, I know) and help build the project regardless of what version certain dependencies like Java are on my system? I tried explaining my question to them and they basically said that gradle is separate from docker which I kind of understand but it just doesn't make sense to me why I have to have specific depencency versions on my machine when it builds a docker container? Hopefully that makes sense
18 replies
KPCKevin Powell - Community
Created by vince on 6/25/2024 in #back-end
Does this make sense to be a subclass?
I'm trying to create a subclass to implement some custom functionality to a parent class. I'm making a discord bot that has a class Discord. This Discord class has a constructor that takes a token. I've created a subclass Bot that has a constructor that calls the parent function. I've done this so I can implement environment variables.
class Bot extends Discord
{

...

public function __construct()
{
$dotenv = Dotenv::createImmutable(dirname(__DIR__, 1));
$dotenv->load();
$dotenv->required('UMPIRE_TOKEN')->notEmpty();

parent::__construct([
'token' => $_ENV['UMPIRE_TOKEN'],
'intents' => Intents::getDefaultIntents(),
]);
}

...

}
class Bot extends Discord
{

...

public function __construct()
{
$dotenv = Dotenv::createImmutable(dirname(__DIR__, 1));
$dotenv->load();
$dotenv->required('UMPIRE_TOKEN')->notEmpty();

parent::__construct([
'token' => $_ENV['UMPIRE_TOKEN'],
'intents' => Intents::getDefaultIntents(),
]);
}

...

}
Everything runs fine but for some reason, this just looks really off to me. I'm not sure if I'm overcomplicating it or creating an antipattern.
65 replies
KPCKevin Powell - Community
Created by vince on 6/24/2024 in #back-end
How should I architecture an api?
Hey guys, bit of an abstract question. I'm writing a discord bot in php so I can better understand php. This will be a terminal application. I'll also have a portion of the app in python to do sentiment analysis. I was wondering what the heck are the logistics behind writing a way to communicate between the php (bot) portion of the app and the python (sentiment analysis) portion of the app? I'm assuming I can write an api between the 2, but then my question is how do I even host that? I know how apis work but I've never actually set one up myself. I'd be using a digital ocean droplet with cpanel installed, and cpanel comes with apache ootb so I'm assuming i'd need to configure it in apache
30 replies
KPCKevin Powell - Community
Created by vince on 6/17/2024 in #front-end
How to match border height of element
No description
27 replies
KPCKevin Powell - Community
Created by vince on 6/10/2024 in #front-end
Promises question
I have the following code:
function geocode(location) {
geocoder = new google.maps.Geocoder();

if (!location) {
console.error("Location argument is null.");
return;
}

return new Promise((resolve, reject) => {
geocoder.geocode({ address: location })
.then((result) => {
const { results } = result;

if (results) {
const coordinates = results[0].geometry.location;
const lat = coordinates.lat(); // These are functions
const lng = coordinates.lng();

resolve({ lat: lat, lng: lng });
}
})
.catch((error) => {
console.error("Geocode was not successful: " + error);
reject(error);
});
});
}
function geocode(location) {
geocoder = new google.maps.Geocoder();

if (!location) {
console.error("Location argument is null.");
return;
}

return new Promise((resolve, reject) => {
geocoder.geocode({ address: location })
.then((result) => {
const { results } = result;

if (results) {
const coordinates = results[0].geometry.location;
const lat = coordinates.lat(); // These are functions
const lng = coordinates.lng();

resolve({ lat: lat, lng: lng });
}
})
.catch((error) => {
console.error("Geocode was not successful: " + error);
reject(error);
});
});
}
This geocode() function is from the Google Maps API. I'm calling it here:
// Create new markers
locations.forEach(async (location) => {
const coordinates = await geocode(location);

if (coordinates) {
const marker = new AdvancedMarkerElement({
map: map,
position: coordinates,
title: "Uluru",
});
}
});
// Create new markers
locations.forEach(async (location) => {
const coordinates = await geocode(location);

if (coordinates) {
const marker = new AdvancedMarkerElement({
map: map,
position: coordinates,
title: "Uluru",
});
}
});
My question is, do I really need to wrap the geocode function in a Promise constructor? Admittedly, I got this answer from chatGPT after having difficulties with calling the data from geocode func inside the forEach. Whenever I tried to make a new marker, it wouldn't wait for the geocode func to return. My understanding of Promises is really limited -- but I did try to use the await syntax on the geocoder.geocode() line but my IDE complained that 'await' has no effect on the type of this expression -- so I'm assuming the way it's set up in the Google library doesn't allow you to use await?
6 replies
KPCKevin Powell - Community
Created by vince on 6/7/2024 in #os-and-tools
Quick git question
No description
2 replies
KPCKevin Powell - Community
Created by vince on 6/5/2024 in #os-and-tools
cPanel User Domain
Is there a way to access a user's public_html files without setting an actual domain? I have a temporary, not real domain name set up for my user kanboard called kanboard.tld. I want to be able to access this using my server's ipv4 address. I've found ways to do this online but I'm just not sure if that's the only way: something like <ipv4>/~kanboard/index.html. Hard to formulate my question if that doesn't make sense but in essence I just want an easy way to store my files and access them publicly using cPanel.
3 replies
KPCKevin Powell - Community
Created by vince on 5/24/2024 in #front-end
What's a good way of handling specific styling for components?
Let's say I have a basic slider component that displays a slider. Let's say on page A I want the slider to have some type of margin-bottom because there're other components underneath of it. Page B I don't want it to have any margin because it's isolated on its own. What's a good way of handling this? I have a page builder module within a CMS where I'm adding these generic components to but some of them need padding / margin / some other css property while others don't. I don't think it makes sense to add variants to these components as realistically, the properties needed could be anything based off what other components are on the page layout or based off a specific need for that page layout. I would also like to avoid setting page overrides as that doesn't seem to make a whole lot of sense either to me in a component-based page building system. Am I overthinking it or is there a better way? I've always struggled with this
17 replies