New Guardians of the Galaxy Vol. 3 Trailer Tugs Those Heartstrings

https://i.kinja-img.com/gawker-media/image/upload/c_fill,f_auto,fl_progressive,g_center,h_675,pg_1,q_80,w_1200/69985689167fce995d454b348e06d60e.jpg

It’s the last ride for the Guardians of the Galaxy.
Image: Marvel Studios

Can he actually do it? Can James Gunn complete a cohesive, emotional trilogy of superhero films within the restraints of the Marvel Cinematic Universe? He’s two-thirds of the way there and, with this latest look at Guardians of the Galaxy Vol. 3, it looks like he may just achieve that.

Written and directed by Gunn in what’ll be his last Marvel movie, Guardians of the Galaxy Vol. 3 is set for release May 5. It once again follows the adventures of Guardians Star-Lord (Chris Pratt), Drax (Dave Bautista), Rocket (Bradley Cooper), and Groot (Vin Diesel), but now they’ve also got Nebula (Karen Gillan), Mantis (Pom Klementieff), Kraglin (Sean Gunn), and Cosmo (Maria Bakalova), in a story that involves Adam Warlock (Will Poulter) and Rocket’s past. Oh, and there’s that whole alternate Gamora (Zoe Saldana) thing too since she died and came back and… just check out the latest look here.

Certainly, there’s a lot this film has to do, not to mention that for some of the cast (like Dave Bautista for instance), it could be their final film in the Marvel Cinematic Universe. Is it because their characters die? Or are Kevin Feige and the Marvel Studios team going to be done with Guardians projects in the post-Gunn era? There’s certainly plenty of other Marvel heroes to go around.

Nevertheless, we’re anxiously awaiting to see what Guardians of the Galaxy Vol. 3 has to offer and we’ll be seeing it very, very soon. The movie is out May 5.

G/O Media may get a commission

12 Giant Lego Sets for the Giant Child Within You

Lego sets for anyone of all ages to enjoy
Anyone who says Lego is for kids has never seen the price tag on these kits. And even if that were true, what are adults if not really big kids? The truth of the matter is Lego is for everyone.


Want more io9 news? Check out when to expect the latest Marvel, Star Wars, and Star Trek releases, what’s next for the DC Universe on film and TV, and everything you need to know about the future of Doctor Who.

Gizmodo

Production Methods: Examples of What State-of-the-Art Sheet Metal Brakes Can Do

https://s3files.core77.com/blog/images/1346136_81_119318_qNBIquYIP.jpg

Industrial Design students: With any luck your programs occasionally tear you away from the 3D printers to educate you on traditional production methods. One thing I don’t see a lot of in ID student projects, and I look through a fair amount, is the use of sheet metal. So I thought it might be helpful to show you what some state-of-the-art sheet metal fabrication tools can do, to give you an idea for possibilities you can spec in your designs.

Companies like Germany-based UKB specialize in making all manner of press brake tools. To help designers and fabricators understand the capabilities, they’ve got a YouTube channel filled with 45-second clips featuring different brakes and results. Here’s a sample:

Radius Tool

Radius Embossing Tool

Adjustable Unibending Tool

U-Bending Tool with Overbending Function

Trapezoidal Tool

Z-Bending Tool

Fold and Flatten Tool

Louvre Tool

U-Bending Tool for Extra Thick (8mm / 5/16") Material

Assymmetrical U-Bending Tool

If you’d rather not sit through videos, they’ve also got 2D representations that you can browse to see the different profiles possible:

The firm also makes custom tools, like the one you see in the GIF atop this entry.

You can learn more here.

Core77

To Raw SQL

https://repository-images.githubusercontent.com/597449262/33ee3d62-704b-4602-9d5e-f87aefc18f17

GitHub Workflow Status

To Raw SQL

Get raw SQL from Laravel Query Builder

Installation

composer require pyaesoneaung/to-raw-sql

Usage

User::where('votes', '>', 100)
    ->orWhere(function ($query) {
        $query->where('name', 'Abigail')
            ->where('votes', '>', 50);
    })
    ->toRawSql();

// "select * from `users` where `votes` > 100 or (`name` = 'Abigail' and `votes` > 50)"

Why?

toSql() doesn’t bind values to it. Instead, it returns the raw SQL representation of the query as a string, including placeholders for any bound values.

In some cases, you might want to inspect the actual SQL, with the values already bound to the placeholders.

Testing

License

The MIT License (MIT). Please see License File for more information.

Laravel News Links

Link rides a huge hoverboard in the new Zelda ‘Tears of the Kingdom’ trailer

http://img.youtube.com/vi/fYZuiFDQwQw/0.jpg

Nintendo closed out today’s Direct showcase with a new trailer for The Legend of Zelda: Tears of the Kingdom, showing off the game’s traversal mechanics and dramatic cinematics. Link takes to the skies above Hyrule on a huge, four-engine drone and in the bucket of a small hot-air balloon, and he drives across the grass on a massive motorized chariot. In one shot, he slides down one rail of a cliffside metal track, Jet Set Radio style.

Tears of the Kingdom is scheduled to hit Switch on May 12th, 2023, and pre-orders are open right now. 

Tears of the Kingdom is the follow-up to Breath of the Wild, which was a wildly successful launch title for the Switch. Nintendo promises the new game will be as vertically expansive as its predecessor, taking Link to the mysterious islands floating above Hyrule.

Engadget

Man With Daughters Dons Full Hazmat Suit Before Cleaning Shower Drain

https://media.babylonbee.com/articles/63e2b398e6ab963e2b398e6aba.jpg

LINCOLN, NE — J.D. Beutler, local patent lawyer and father of daughters, was seen returning home from Battalion Bazaar Army Surplus with a full hazmat suit, a titanium-lined drain auger, and an unwavering gleam in his eye as he prepared to clean the shower drain.

Witnesses reported Beutler sending his tearful family to the safety of his in-laws’ before entering the noxious wasteland known to locals as “The Kids’ Bathroom.”

“Come on you filthy, crinigerous interloper, be gone with you!” Yelled Beutler through the full-body personal protective equipment as he battled to pull the fetid ball of slime, hair, and little elastic bands from its mildew-strewn lair. “Is that all you’ve got?”

After what seemed like days wrestling the putrid clog, Beutler paused and backed away, having felt the hair clog budge. To his alarm, the slurping, pungent obstruction rose from the drain on its own, towering over him in a sickening, monstrous form, and spoke.

AT LONG LAST, I, THE DRAIN-O-GORGON, AM SET FREE…

Bolstered by an unbreakable love for his daughters as well as a desire for them to not have to use his shower, Beutler charged, dodging tentacles interwoven with fingernail clippings and hair clips in a fight to contain the swampy form.

Battle-worn, bruised, and having filled his hazmat suit with sweat and only a little bit of pee, J.D. Beutler overtook the Drain-o-gorgon and, with an intense feeling of triumph, forced the monster out of the tub and into his Paranormal Elimination Proton Pack (50% off at Battalion Bazaar).

But as the creature disappeared into permanent confinement, the Drain-o-gorgon issued a final warning:

YOU WILL NEVER FULLY RID OF ME, FATHER OF DAUGHTERS…WE SHALL MEET AGAIN IN ABOUT THREE MONTHS’ TIME, SOONER IF YOU HOST A SLEEPOVER…


Watch as a fired Twitter employee applies for her first *actual* job:

Subscribe to our YouTube channel for more guffaw-inducing chucklefests!

Babylon Bee

The original ‘Legend of Zelda’ has been remade in Minecraft, without using mods

http://img.youtube.com/vi/Mw4j62Y4oW4/0.jpg

A Minecraft mad scientist has recreated The Legend of Zelda inside the blocky sandbox game without any third-party mods or resource packs. Fan and YouTuber C1OUS3R, who has also made Sonic the Hedgehog and Super Mario Bros. inside Minecraft, took nearly a month to craft the Zelda tribute.

The developer used command blocks, custom textures and other in-game features to recreate the 1986 NES classic. “I use Blockbench to create a flat version of Link from all sides so I can rotate it to make it look like he’s facing every direction,” C1OUS3R explained in a making-of video. “I would make a Voxel model like I did in the previous video games, however, it’s pretty much unnoticeable and takes 30 times longer, and I don’t really have the time for that.

“I then overlaid this model over a carved pumpkin which is one of the items you can wear on your head in Minecraft. I then make the player invisible to make it look like you’re controlling Link. Then by using the data packs function folder, which is just command blocks in written form, I’m able to detect which way the player is moving based off armor stands and rotate the model to make it look like it’s moving. I then simply animate the textures, and boom. You have a controllable Link.”

C1OUS3R said on Reddit (viaKotaku) they will release the playable creation, which runs through the first boss fight, once their YouTube video gets 5,000 likes. (It has over 500 at the time of publication.) The developer says they want to eventually release an entire gaming engine inside Minecraft. “It’s much easier to understand rather than something like Unity. I believe Minecraft has the ability to really help people get into game development.”

Engadget

HBO’s Mario Kart

https://theawesomer.com/photos/2023/02/hbo_mario_kart_pedro_pascal_too_t.jpg

HBO’s Mario Kart

Link

With the success of The Last of Us, HBO has proven that video games can be turned into quality television programming. During his guest spot on SNL, TLOU star Pedro Pascal joins the cast of another famous video game franchise turned prestige TV drama.

The Awesomer

Setting up a WebSocket server for your Laravel app


This article has been cross-posted on the Knack Engineering blog.

Introduction

WebSockets are a ubiquitous tool for building real-time experiences for users. They provide a persistent, bidirectional connection between a client and a server. For example, say the frontend of your app needs to stay up-to-date within seconds of your backend to do things like deliver notifications, status updates, etc. You may have implemented this as a periodic check, or poll, of the backend via some API like REST or GraphQL. Now that you have more users, and/or your processes have become more complex, these requests can start to weigh on your infrastructure capacity. That’s a problem that WebSockets can help solve.

Laravel and its ecosystem play a significant role in our stack at Knack, and recently we embarked on a new WebSocket server implementation which would work closely with our Laravel-based core API. For the uninitiated, Laravel is a popular PHP framework and ecosystem that provides a rich set of tools and features for building modern web applications. We decided to use the swooletw/laravel-swoole library to build our server-side implementation of a custom subprotocol and I had the opportunity to document some of my experiences along the way. I’ll show how to get started with the library, provide some background information, some caveats to consider, and drop a few tips. Let’s get started!

WebSocket Server Solutions for Laravel

First, we are working with the assumption that you want, or need, to host your own WebSocket server, and that you want to do so in PHP. With a stateful protocol like WebSockets we need to be able to run PHP concurrently. There are basically two different approaches: language-level and extension-level.

Language-level libraries and frameworks implement concurrency in pure PHP. Examples include AMPHP and ReactPHP. In contrast, extensions are written in a lower-level language, typically C/C++, and expose APIs at the PHP-level to access the extension-level functionality. Swoole and OpenSwoole are examples of PHP extensions. In short, Swoole is an event-driven, asynchronous, multithreaded framework that makes it easy to build performant, concurrent servers.

Now let’s evaluate pre-packaged WebSocket Server solutions that easily plug into a Laravel app. On the language-level side we have the seemingly most popular choice: the beyondcode/laravel-websockets, a package by Beyond Code. It is built on Ratchet (which is built on ReactPHP), has a Pusher protocol implementation, and plugs well into the Laravel framework’s broadcasting API. While this supports a lot of use cases and does so in a familiar “Laravel way” it is not very flexible when you need something like a custom subprotocol implementation, and it is inherently limited in performance due to being built on a PHP server core rather than a C/C++ one.

Stargazer Statistics

On the extension-level side we have two libraries that are built around Swoole: swooletw/laravel-swoole and hhsxv5/laravel-s. They are both established packages with a wide contributor base, but my colleagues and I ultimately concluded that the sandbox and safety features within laravel-swoole were a bit more mature and reliable in our testing.

There are a few blog posts out there on getting started with laravel-s but not as many for laravel-swoole, so I felt particularly motivated to write and publish this article. The laravel-swoole default WebSocket implementation is built with Socket.io in mind, where laravel-s is a bit more agnostic in its implementation. Both packages have some feature overlap but some differences as well. I would consider both of them for your project and evaluate the best fit!

Getting started with swooletw/laravel-swoole

First, let’s install either Swoole or OpenSwoole. I’ll be using Swoole for this example. Be sure to enable support for WebSockets on installation when prompted like so:

Enable Sockets Support

pecl install swoole

If you run into any issues during the Swoole build process I included a few troubleshooting steps in the appendix.

Now, create a new Laravel app. Continue bootstrapping the app using Laravel Jetstream. I used the Intertia template, but I believe the API feature should work with Livewire as well.

laravel new
composer require laravel/jetstream
php artisan jetstream:install inertia

Let’s set up that feature: just enable it by uncommenting the line in config/jetstream.php:

'features' => [
    ...
    Features::api(),
    ...
],

Next, require the laravel-swoole package and publish its config files:

composer require swooletw/laravel-swoole
php artisan vendor:publish --tag=laravel-swoole

Here we’ll also want to adjust the config to enable the WebSocket server by default.

'websocket' => [
    'enabled' => env('SWOOLE_HTTP_WEBSOCKET', true),
],

Now, for this basic example we’ll just have our handlers defined inline as closures in the websockets “routes” definition. For anything that is more than a simple exploration I would recommend creating controllers or Laravel Actions to store the handler code.

<?php

declare(strict_types=1);

use App\Models\User;
use Laravel\Sanctum\PersonalAccessToken;
use SwooleTW\Http\Websocket\Facades\Websocket;

Websocket::on('whoami', function (SwooleTW\Http\Websocket\Websocket $websocket) {
    $websocket->emit(
        'message',
        $websocket->getUserId() === null
            ? 'You are not authenticated'
            : "Your userID is {$websocket->getUserId()}"
    );
});

Websocket::on('login', function (SwooleTW\Http\Websocket\Websocket $websocket, mixed $data) {
    if (is_string($data)) {
        $tokenInstance = PersonalAccessToken::findToken($data);

        if (
            $tokenInstance instanceof PersonalAccessToken &&
            $tokenInstance->tokenable instanceof User
        ) {
            $websocket->loginUsing($tokenInstance->tokenable);
            $websocket->emit('message', $tokenInstance);
        }
    }
});

Now we can test it out! Let’s start the Swoole server and test things out.

Note: You will need to disable Xdebug before you can run any Swoole code. If you skip this step your terminal will be overwhelmed with warning logs when you run this next command and things might not behave properly. If you expect to be doing a lot of Swoole development then you may want to configure a tool or script to enable or disable loading the Xdebug extension. For macOS there’s an open source tool to add a toggle button in the menu bar called xDebugToggler.

php artisan swoole:http start

Try navigating to http://127.0.0.1:1215 and seeing if you are able to register and login just like if you were to run php artisan serve. From there, head to the API Tokens section:

Jetstream API Tokens

Create a token and save it for the next step.

Create API Token

Now, let’s connect to the server via WebSocket and test our handlers! Open up your WebSocket client of choice. I’ll be using Postman here.

Let’s get connected and make sure everything works. Enter your hostname and port (likely 127.0.0.1:1215) and hit connect. You should see two messages come through and the status should still read CONNECTED.

Connect to WebSocket with Postman

If you’re wondering what those 1-2 digit numbers prefixing the server messages are, those are Socket.io packet type encodings. You can remove these and adjust anything about frame parsing by creating your own implementation of \SwooleTW\Http\Websocket\Parser.

Let’s send a whoami payload using this JSON:

[
  "whoami"
]

WebSocket whoami test

As expected we get the unauthenticated message. So let’s log in! Refer to the following JSON payload:

[
  "login",
  "YOUR_API_TOKEN"
]

WebSocket login test

And we get the $tokenInstance we emitted in our routes/websocket.php handler for login, and the default parser was nice enough to JSON-encode it for us! We can send another whoami to check our work:

WebSocket whoami second test

We now have a WebSocket server and a way to authenticate connections! This example is very basic, but I hope it gives a background to build something great with.

Appendix

Notes on using Swoole and laravel-swoole

Try Using Swoole (or RoadRunner) to serve your app

Swoole benchmark comparison

If you end up using a Swoole-based solution for your WebSocket server, why not serve HTTP requests using Swoole as well? Laravel’s request lifecycle by default is actually pretty redundant: for each incoming request that your Laravel app handles it needs to be fully bootstrapped every time: framework, service providers and all. There is a first-party solution to this: Laravel Octane, which uses your choice of Swoole (or OpenSwoole) or RoadRunner to provide a relatively easy way to serve many more requests by booting and loading the application into memory. Laravel Octane with RoadRunner is very likely to be a drop-in replacement for Nginx/PHP FPM for your Laravel app if you’d rather not add Swoole to your stack. Either way, it could be an easy win to dramatically increase your throughput for typical HTTP server needs using Laravel Octane, laravel-swoole, laravel-s, or another similar solution.

Choosing a WebSocket Room Driver

Be sure to choose your room driver, which associates WebSocket connections with users as well as membership in channels, appropriately for your use case. By default, the library will use a Swoole table to store these records. Swoole tables are an incredibly performant data store compared to Redis, as Cerwyn Cahyono concluded in May 2021. One consideration however is horizontal scaling: if you have more than one WebSocket server behind a load balancer, for instance, you need to consider that Swoole tables are only accessible by the Swoole server process and its forks.

If you need to have a common record among all of your WebSocket server instances with laravel-swoole then you may want to consider the provided Redis driver (\SwooleTW\Http\Websocket\Rooms\RedisRoom), or creating your own implementation. Be sure to add a prefix unique to the server for all records, that way you don’t end up sending a message intended for one WebSocket connection on Server A to another, unrelated WebSocket connection on Server B.

Implementing middleware for WebSocket frames/messages

You may also find that you’d like to have middleware for all incoming WebSocket messages. If all you need to do is interact with parts of the Frame then you can add this handling in a custom handler or parser. These are defined in config/swoole_websocket.php. If you need to get the user ID and interact with a WebSocket instead then you’ll have to override and extend the \SwooleTW\Http\Concerns\InteractsWithWebsocket trait to directly modify the Swoole onMessage handler.

Adding Swoole to an existing stack/system

If you have a system where a Swoole WebSocket server stands alongside other pieces like an HTTP server, queue worker, etc. then you will need to implement some kind of global pub/sub infrastructure that coordinates between the Swoole WebSocket server and everything else. Redis is one way to fill that need. You could have an async Redis client boot with the Swoole server and SUBSCRIBE to a given channel. The client could listen for a JSON payload which could simply have a user ID and data to emit to the authenticated WebSocket connection. That way, you could issue WebSocket messages from non-Swoole contexts by simply PUBLISHing the JSON payload to the corresponding channel. This does have the added overhead of having to establish a Redis connection for each emit from a non-Swoole context, but you get the flexibility of cooperating well with your existing system.

Troubleshooting installation of Swoole extension

When installing the Swoole extension on both ARM64 and x64 macOS machines I’ve run into a few issues and wanted to share how I resolved them.

fatal error: ‘pcre2.h’ file not found

If you get this error when installing Swoole then you need to be sure you have pcre2 installed. On macOS, you can do this using Brew:

brew install pcre2

Then you can use the Brew CLI to grep the location of the pcre2.h file and link it under your current PHP version’s include/php/ext/pcre/ directory.

brew list pcre2 | grep 'pcre2\.h$'

ln -s /opt/homebrew/Cellar/pcre2/xx.yy/include/pcre2.h /opt/homebrew/Cellar/php@x.y/x.y.z/include/php/ext/pcre/pcre2.h

fatal error: ‘openssl/ssl.h’ file not found

This guide doesn’t require building Swoole with OpenSSL support, but if you do you may need to set your OpenSSL directory during the build config. You can do so by first ensuring that you have OpenSSL installed locally, on macOS you can also do this using Brew:

brew install openssl

Then you can once again use the Brew CLI to get your OpenSSL directory and pass it in during the extension build configuration, right after executing pecl install. When prompted to enable OpenSSL support, type out “yes” and then add the --with-openssl-dir flag inline like so:

brew --prefix openssl
pecl install swoole


enable openssl support? [no] : yes --with-openssl-dir=/opt/homebrew/opt/openssl@3

Notes on WebSockets

Subprotocol gotcha

Be sure to pay attention to the Sec-WebSocket-Protocol HTTP header on the initial connection request. If the client request specifies a protocol in the header and the server doesn’t respond with that protocol, or any, then some browsers like Chrome will just drop the connection, which technically follows the WebSocket spec more closely, and others like Firefox and Safari will connect without hesitation.

Which WebSocket dev client to use?

For me this has been Firecamp, but I have gotten frustrated with the bugs and poor performance of the app. It has a lot of potential, so I’m definitely going to keep watching it! Insomnia just added WebSocket support, but it is still immature and lacking features. As of Jan 2023 I recommend using Postman, though note that even for them WebSockets support is somewhat of a beta.

Give your WebSocket server a heart(beat)

Be sure to implement some kind of heartbeat function for persistent WebSocket connections. It’s a good general practice, and helps when you have or want infrastructure configurations that close inactive connections. With many subprotocols the heartbeat is client-initiated.

Authentication Patterns

There are many patterns for authenticating WebSocket connections, but can be categorized as either during the initial connection request (authentication-on-connection) or afterwards within the established connection (authentication-after-connection). During the initial connection request the two most common approaches are to either use a cookie, or a token in the header or body. Typically, with the authentication-on-connection approach the connection is closed by the server if the authentication check fails. With the authentication-after-connection approach typically servers have a timeout which closes connections that don’t authenticate within a given timeout. At Knack, we created a WebSocket backend that implemented the graphql-transport-ws subprotocol which frontend library enisdenjo/graphql-ws supports.

For reference, laravel-swoole is configured by default for authentication and other middleware to be run on the initial connection request. While this is a valid approach, my impression is that the dominant WebSocket authentication pattern is to support authentication-after-connection. For this guide I implemented an authentication-after-connection flow as a barebones custom subprotocol. Before proceeding with your project be sure to consider what kinds of clients will be connecting to your WebSocket server and choose your approach accordingly.

Laravel News Links

Laravel create/show Route Doesn’t Work? A Typical Mistake.

https://laraveldaily.com/storage/322/Wrong-Way.png

If you have a few similar GET routes, there’s a danger of one overriding another.

Example 1: Two GET Routes

routes/web.php:

Route::get('posts/{post}', [PostController::class, 'show']);

Route::get('posts/create', [PostController::class, 'create']);

The problem with this pair is that “create” will match the same way as {post}, so if you load /posts/create in the browser, it will execute the first route of /posts/{post}, assigning {post} == "create".

In that case, you need to change the order:

routes/web.php:

Route::get('posts/create', [PostController::class, 'create']);

Route::get('posts/{post}', [PostController::class, 'show']);

Then, both routes would start working.


Example 2: Resource Controller with Extra Method

routes/web.php:

Route::resource('posts', PostController::class);

Route::get('posts/export', [PostController::class, 'export']);

If you launch /posts/export in the browser, it will instead execute the show() method of the Controller, and not the export() method.

The reason: as a part of Resource Controller, there’s a show() method, which has a signature of posts/{post}. So it will match the same way as posts/export.

If you want to add extra methods to Resource Controller, you need to add them before the Route::resource():

routes/web.php:

Route::get('posts/export', [PostController::class, 'export']);

Route::resource('posts', PostController::class);

The general rule of thumb is to have specific no-parameter routes earlier in the Routes file than the “wildcard” routes with parameters.

Laravel News Links