Skip to content

u/notian

In this archive from Dec 2008 to May 2023

4
posts
160
comments
1
media
609
score

The only correct answer is: benchmark it. If it takes a lot of compute to generate the JSON files, then absolutely, persist the json files. Are the json files stored locally? Is MySQL local? Are you doing 1 query? 10 queries? 1 json? 10 json files? Both solutions are valid, but only a benchmark is going to tell you which is optimal.

1 points

My company is also on Yii 1.1, though we haven't really discussed migrating. I would say that the main business case is that as the php version increases, there are going to be more and more BC breaks. I am not sure how actively Yii 1.1 is will be maintained, so you may end up being forced to effectively fork Yii and do your own compatibility modifications as time goes on. NTM that you're missing out on a lot of the benefits of more modern code.

3 points

IMO the difference between a "junior/intermediate" and "senior" developer is more about mindset and approach. A junior is more likely to be aware of/think less about the edge cases, and ramifications of a problem/solution. Seniors tend to need to look at things from a bigger picture perspective, and how any given change will affect the overall system.

The job of a senior dev is to build the foundational elements that the intermediates and juniors will extend upon. You don't need to know specific technologies, those change too frequently, what you need to know is how to identify what a system needs. Is it slow? Is it unreliable? Is it hard to develop in? And then, what kinds of things can fix that, caching? Better database design? A more developer-friendly framework? And so on.

54 points

array_reduce might work? Something like:

$final = array_reduce($json, function($carry, $input ){
  $key = $input['idcaracteristica'];
  if( isset($carry[$key])) {
   $carry[$key] .= ' AND '.$input['query'];
  } else {
   $carry[$key] = $input['query'];
  }
  return $carry;
},  []);

3v4l example. I changed the idcaracteristica of the 3rd and 4th elements so it would be 2 queries.

2 points

Easier how? And actually, the answer I determined while trying to find a "channel webhook" is there is no difference.

If you had to post to 15 different channels, with your library, I'd need to create 15 webooks, and then pass them all in the constructor with the channel name as the key. VS creating 1 hook, and being able to specify any channel.

So it's a bit of a matter of perspective. Also, being able to dynamically name the sender (and an icon) is very useful.

1 points

So this is using the Channel webhook/API? As opposed to the App API/Webhook? Internally we use the App one because you don't have the constraint of 1 hook/channel. Is there a benefit to using the channel hook over the app hook?

With the app hook it can specify display name, channel, icon, and attachments along with the text. I don't know the internals of the Guzzle client well enough, but if the array passed to 'json' in the post function contain non-utf-8 characters, does it handle them? Does it just blow up? Does it send out an empty json?

Anyway, cool library.

1 points

I'm visually impaired, so the main issues for me are text that is hard to read for reasons like contrast, size or text showing up and then going away before I have a chance to zoom in to read it.

When it comes to websites, "responsive" sites can be painful, because even on a large monitor, if I have to zoom 2-3x to embiggen the fonts, often the site will just rescale and hide elements instead of filling the window.

Apps/sites also not letting you highlight text is also a major annoyance.

2 points

You seem a little defensive, just trying to give you some constructive feedback.

So first, the verify methods, I didn't see your dev branch before I wrote the comment, so there was no caching. You are using the verify methods in query building methods. If you're allowing user input to determine column names without external validation, you've got other problems. If you're worried about injection, a simple string validation is going to be be much faster. Also, if you're in a multi-database environment, your SHOW TABLES method won't work. (select ... from db1.table1).

Calling the same "prepared query" 10x is much slower than calling 1 extended insert of 10 rows. And if you want to build an extended insert, it's better to build it out with quoted values.

​

the point of the multi method is to prepare the query once and execute each set of data using the same prepared query. This prevents an extra database call for each data set.

It doesn't work that way. It might save a "create template' cycle, but it's still running the query N times.

The multi method doesn't make a lot of sense to me, since it will only return the last result.

$pdo = new GrumpyPDO();
$sql = "SELECT id, name FROM people WHERE id = :id";
     $users = $pdp->all( $sql, [['id' => 1], ['id' => 2], ]);
print\_r($users);
// result
// Array(
//     'id' => 2,
//     'name' => 'John',
// );

Quoting is preferred (IMO) in larger queries. If you're sending >10 params to a prepared query, or if you're using non-named placeholders ( ? ) it can be hard to debug.

As for my last comment about an internal method I would catch the native PDO Exception, and then put some more verbose debugging like the query that was executed, and the data that was sent. And probably some environment checks for more or less debugging whether you are in a live or staging environment.

In my codebase I have a specific class that builds insert queries, the signature is:

$helper = new MyClass($pdo);
$helper->exec( 'db1.table1', [
  ['col1' => 'Value 1', 'col2' => 'Blah blah'],
  ['col1' => 'Value 2', 'col2' => 'halb halb'],
], ['col1']);

This builds and executes:

INSERT INTO db1.table1 ( col1, col2 )
VALUES
( 'Value 1', 'Blah blah' ),
( 'Value 2', 'halb habl' )
ON DUPLICATE KEY UPDATE col1 = VALUES ( col1 );

Doing that with a prepared statement for dozens or hundreds of rows would lead to some really ugly queries, and doing them 1 at a time would be very slow.

2 points

Quick thoughts:

  • Your insert method doesn't actually support multi-inserts, though I see it is detected, and then you only insert the first row.
  • You don't have support for the ON DUPLICATE KEY syntax. Or support for functions in inserts (time based functions, etc).
  • I honestly wouldn't bother with the whole "verify table" thing. Much better to just throw Exceptions on failed query attempts. You're doing at least 2 extra queries for every query you do. Better to run the query, and then try and give good debugging.
  • I am not sure I understand the logic behind the multi method? It will only return the last executed statement, and doing queries in a loop is generally not reccommended.
  • As much as I think prepared queries are great, there are situations where simply using pdo::quote is preferred, and since you extend pdo, it's still available, but I'd probably add a way to do a whole array at once.
  • And since in some cases you are building the query, it can be useful to put all the queries through a private method with extra exception handling and debugging.

Good luck!

1 points

As others have said, it's probably your queries. I'd probably build a logging class to see:

a) what queries are run
b) how long each query took
c) if the same query is run >1x.

Then figure out why the slower queries are slow, or if queries are run >1x if/how they can be cached.

Also, if queries can be consolidated, are you doing some kind of select query in a loop, could that be done with a join, etc.

3 points

Where OOP shines is being able to have shared behvaiours amongst a series of things.

So if you had a 5 page website, you could have a AbstractPage object with an abstract display function, and then Home, About, etc.. extend the Abstract class and implement the display function. So then when a request comes in you say "(new $pageClass()->display())" or in a more complex way

$page = $_GET['page'];
$pageClass = "\\Pages\\{$page}";
if( class_exists($pageClass) && $pageClass implements \\Pages\\AbstractPage )
{
  (new $pageClass())->display();
}
else
{
  (new \Pages\Error404())->display();
}

Looking into namespaces and autoloading (specifically PSR-4) means you can compartmentalize things a lot.

I would (in general) avoid using Traits as they sidestep the whole inheritance thing.

Also, PDO is a lot nicer to use (IMO) than mysqli.

2 points

I don't understand how people are so effusive about these logos...

mcdonalds looks like a Tennis brand.

apple is basically just there old logo, but not an apple.

Coca-Cola is so-so

The Netflix logo I like, except, it's too tall and the F should be up, not down

Chupa Chups looks like Thupa Thups

ADIDAS is ok, but might be too much emphasis on German colors for a brand that will be on international sports teams uniforms.

The Honda logo wouldn't work on a car, and the red rounded rectangle is too Nintendo.

Ikea looks like a knock-off Pan-Am logo, and looks like an airline, not a home decor shop.

And the Photoshop logo looks like a recolored version of an old Kodak logo.

IDK, they don't really feel very well thought out IMO.

99 points

I can't tell if this is the log in or sign up page. The lighter "Sign In" makes me think it's to sign in, but the inputs are clearly for sign up.

The button should be labelled with the action to reinforce the action that you are about to take.

Having the user and email icons is good for people who don't bother to read, but (I assume) the eye in the password is to show the password text, which is confusing, since the first 2 are hints, and the 3rd is an action.

I also don't know the purpose of your application, but is it necessary to have a username on top of an email address as a unique identiier?

1 points

integer xdebug.show_exception_trace = 0 #
When this setting is set to 1, Xdebug will show a stack trace whenever an Exception or Error is raised - even if this Exception or Error is actually caught.

So looks like xdebug will do that for you. Though I would suggest not having that on in production.

1 points

No. The simplest way I can think of would be something along the lines of having an exception handler class, like this:

Class ExceptionHandler
{
  public static function handle( Exception $exception, Closure $handlerFunction )
  {
    // Trace blah blah blah
    $handlerFunction( $exception );
  }
}

...

try{
  thingThatThrowsException();
}catch(Exception $e )
{
  ExceptionHandler::handle( $e, function($e){
    // Do stuff.
  });
}
1 points

I'm sorry, but this video is painful. It's almost 2020, there is a builtin function for getting the first key as of 7.3 and the documentation has a suggested polyfill. Get the key, reference the key in the normal way ($array[$key]). Or just write a polyfill for array_first_value( ) and do the same foreach..return $value. Most of the suggested methods modify either the array pointer or the array itself ( reset, array_shift ) or involved creating a modified copy ( array_values ).

Also the presentation of a music bed over a command line terminal, where 90% of the screen is just black) with no explanation as to when applying way x vs way y would be good, is unwatcheable. And probably is just going to confuse "beginners" more than a 30 second sound clip.

6 points

Keyboard shortcuts

Move and act

jork
Next / previous post or comment
Enteroro
Open the post
f
Open the media viewer
s
Save
h
Hide (the toast has Undo)
Tab
Right after an action: the toast's Undo
x
Collapse the comment
v
Next layout: cards, compact, grid

Go to

/
Search
gthenh
Home
gthena
All
gthens
Subreddits
gthenl
Library
?
This list
Esc
Close a menu or this list

In the viewer

←or→
Previous / next file
↑or↓
Previous / next post
korj
Previous / next post
Space
Play / pause
m
Mute
z
Zoom
s
Save
o
Open the post (on its own page: back to it)
Esc
Close

Keys do nothing while you type in a box.