vince
vince
Explore posts from servers
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
KPCKevin Powell - Community
Created by vince on 5/20/2024 in #front-end
How would you start this tricky section?
Hey guys been asking for a lot of help lately 😅 I am not as good at css as I thought haha I have the following hero (see images for desktop and phone mockups). I don't want a solution, I just want to know what's the best way to approach this to make it responsive / skeleton snippet. I'm able to do either the mobile OR desktop versions, but I'm not able to get them to transition cleanly. Another issue I'm having is that the "Come join our award winning..." is set in the CMS, so the text could be pretty much any length. If there is too much text, my current implementation ends up having it overlap the CTA button. So I'm thinking the best approach to keep everything responsive might just be to put it in a massive grid but not sure...
146 replies
KPCKevin Powell - Community
Created by vince on 5/17/2024 in #front-end
Stumped on typewriter effect
I have some JavaScript where I need to create a typewriter effect that types and then backspaces. I've gotten something to work on this codepen: https://codepen.io/vince1444/pen/xxNZKQE?editors=1111 The problem is, I need to do this for an array of words, and this is really stumping me. It seems like promises are key here, but I can't get my promises to work correctly. I have a work in progress codepen here: https://codepen.io/vince1444/pen/oNRbNGd?editors=1111 I'm able to print out the first letter in each word sequentially so far... Edit: I was able to get the all the words printing sequentially now, but I still need to implement backspacing...
10 replies
KPCKevin Powell - Community
Created by vince on 5/13/2024 in #front-end
How do I go about this design?
No description
16 replies
KPCKevin Powell - Community
Created by vince on 5/8/2024 in #front-end
Help creating a breakout section
No description
8 replies
KPCKevin Powell - Community
Created by vince on 5/2/2024 in #os-and-tools
Git squashing and duplicate commits
Hi guys, I'm a bit confused on how a proper workflow should look for squashing. I have the following issue: 1. I'll go and make commits on a feature / fix branch and squash & merge onto the main branch 2. I'll pull my changes from main into my local feature / fix branch to keep it up to date 3. I'll make some more commits on the local feature / fix branch and then do the same steps in 1 & 2 This duplicates the commits since the commits in my local are not squashed. What should I be doing to keep it in sync with main and not duplicate commits?
7 replies
KPCKevin Powell - Community
Created by vince on 4/11/2024 in #os-and-tools
/bin/cp: cannot create regular file: Permission denied
git@test.tld:~/repositories/cpanel-devops$ /bin/cp index.html /home/git/public_html/
/bin/cp: cannot create regular file '/home/git/public_html/index.html': Permission denied
git@test.tld:~/repositories/cpanel-devops$ /bin/cp index.html /home/git/public_html/
/bin/cp: cannot create regular file '/home/git/public_html/index.html': Permission denied
So I'm following a deployment config file for cPanel and I think I'm pretty close to getting it set up. Part of the deployment process is to run the command on line 4:
deployment:
tasks:
- export DEPLOYPATH=/home/git/public_html/
- /bin/cp index.html $DEPLOYPATH # This
deployment:
tasks:
- export DEPLOYPATH=/home/git/public_html/
- /bin/cp index.html $DEPLOYPATH # This
The deployment process wasn't completing, so I logged into my git user (the one that owns the home directory, not the root user). I tried running the command /bin/cp index.html $DEPLOYPATH and I get the following error:
git@test.tld:~/repositories/cpanel-devops$ /bin/cp index.html /home/git/public_html/
/bin/cp: cannot create regular file '/home/git/public_html/index.html': Permission denied
git@test.tld:~/repositories/cpanel-devops$ /bin/cp index.html /home/git/public_html/
/bin/cp: cannot create regular file '/home/git/public_html/index.html': Permission denied
I've poked around and this seems to be a permissions issue. On further inspection, it seems to be the /home directory. The git user isn't authorized to read the /home directory (though I am able to execute /bin/cp and cd into /home/git (git's ~ directory)). I believe it would fix the issue if I changed the permissions, but the thing is, I don't want to. It doesn't make sense for me to do that either -- I don't want my git user to have access to other users' folders / files. Am I missing something or is the only way to sudo or change the /home folder permissions?
64 replies
KPCKevin Powell - Community
Created by vince on 3/29/2024 in #os-and-tools
src refspec fix/careers-short-title does not match any
Pretty simple error right? I've been pushing to the same remote branch for a couple weeks now and all of a sudden it is giving me that error. I have verified that the branch still exists in GitHub and is accessible. I can even see it when using git branch -a. I'm using the command: git push origin fix/careers-short-title. I'm about to force push but want to make sure I'm not missing something.
7 replies
KPCKevin Powell - Community
Created by vince on 3/24/2024 in #os-and-tools
Installing WHM & cPanel on Digital Ocean Droplet Image
I'm a bit confused on the order for installing different images / programs on a server. I booted up a LAMP image on my droplet and I'm trying to install WHM & cPanel but when I run the manual install script for WHM & cPanel, it complains that there is already a database instance set up and that it needs to be installed on a clean server. Should I rebuild the droplet and install WHM & cPanel first and then the LAMP files? Typing it out the obvious answer would be "Yea, install WHM & cPanel first" but there's got to be an easier way, no? I don't want to have to manually install all of the LAMP stuff if I don't have to
9 replies
KPCKevin Powell - Community
Created by vince on 3/22/2024 in #os-and-tools
How to automate git -> production
Hi guys, I'm reading a lot about docker and some devops stuff since I want to improve some of our workflow processes at work. We have a ddev project (which uses docker) and GitHub. Everytime we make changes and merge into production, we have to manually ssh into the server and git pull. I was wondering how to automate it so that when a user pushes to a branch, that branch will automatically start building and deploying on the server. I know Netlify does this automatically, but I need to think of some platform-agnostic solution. Would appreciate some direction as I'm getting lost in the weeds of everything devops related.
78 replies
KPCKevin Powell - Community
Created by vince on 2/20/2024 in #back-end
Throwing Exceptions
Is this a totally valid / proper way of handling exceptions? For whatever reason I feel like this is improper
private String appendParametersToUrl(String url, String parameter, String string) throws IllegalArgumentException {
if (StringUtils.isBlank(parameter) || StringUtils.isBlank(string)) {
throw new IllegalArgumentException("Parameter or String arugments cannot be null.");
}

return ...;
}
private String appendParametersToUrl(String url, String parameter, String string) throws IllegalArgumentException {
if (StringUtils.isBlank(parameter) || StringUtils.isBlank(string)) {
throw new IllegalArgumentException("Parameter or String arugments cannot be null.");
}

return ...;
}
3 replies
KPCKevin Powell - Community
Created by vince on 2/19/2024 in #back-end
Architecture Question (not code specific)
I have this locations feature I'm working on implementing and I think I'm getting close to figuring it out but wondering on some architecture decisions. The way everything is set up now looks like this:
1) User enters their location (zip code) into an input field (custom web component) and hits enter
2) Custom web component makes a GET request to an endpoint and the endpoint does a SQL query and returns a URL with the correct page
3) Web component redirects to the URL returned from backend
1) User enters their location (zip code) into an input field (custom web component) and hits enter
2) Custom web component makes a GET request to an endpoint and the endpoint does a SQL query and returns a URL with the correct page
3) Web component redirects to the URL returned from backend
I need to retrofit this. Instead of returning a URL, I need the API to return JSON data of multiple offices AND redirect. Let's look at an easy example of data I could send back to the client:
{
"offices": {
"officeOne": { "location": "Philadelphia" },
"officeTwo": { "location": "Austin" },
}
}
{
"offices": {
"officeOne": { "location": "Philadelphia" },
"officeTwo": { "location": "Austin" },
}
}
My question is, what's the best way to accomplish sending JSON data to the client and redirecting? Should I include an object like this:
{
"offices": {
"officeOne": { "location": "Philadelphia" },
"officeTwo": { "location": "Austin" }
},
"redirectUrl": "https://redirectedpage.com"
}
{
"offices": {
"officeOne": { "location": "Philadelphia" },
"officeTwo": { "location": "Austin" }
},
"redirectUrl": "https://redirectedpage.com"
}
And then put the office data into something like local/sessionStorage or should I put the office data in query parameters? Or am I completely off track and thinking about this wrong?
32 replies
CDCloudflare Developers
Created by vince on 2/1/2024 in #general-help
CloudFlare Redirect Rule Not Redirecting
No description
6 replies
KPCKevin Powell - Community
Created by vince on 2/1/2024 in #front-end
Section header SEO
No description
31 replies