In the code snippet above, a short closure is used. It’s a bit beyond the scope of this post, but in Laravel 7, the booted lifecycle method was introduced, which will, unsuprisingly, be called we the model has booted. Using that method, you can lose the static::boot(); call from the initial code snippet.
A lot of people seemed to like it. Some didn’t, and that’s ok. When introducing new syntax, I don’t think there’s a single thing where all programmars will agree on. A comment I agree on however, is the line length. Luckily this can be easily fixed by moving the closure itself to it’s own line.
To make the line length shorter, you could opt to remove the typehint. You could even rename the $team variable to $t, this is pretty common practice in the JavaScript. Personally I live typehints and full variable names, so personally I stick to the code snippet above.
I think it would be silly to blindly switch to short closures wherever it is technically possible. The question you should keep in mind when converting a closure to a short one is: “Does this make the code more readable?”. Of course, the answer is subjective. When in doubt, I recommend just asking your team members, they’re the ones that will have to read your code too.
If you use PhpStorm you can easily switch between a normal and a short closurse, so you can quickly get a feel of how it reads.
.
Let’s end by taking a look at an example where I think short closures really shine: in collection chains (thanks for the example, Liam).
How to Scrape SERP with the now free and open source Laravel Scavenger
https://ift.tt/2WkgBDD
Web scraping is nothing new and often times we find ourselves with the need to scrape a few pages. Enter Laravel Scavenger, the package allows you to scrape and save Search Engine Result Pages (SERP) for analysis and processing later. Let’s look at how we can get up and running with this. For this example we will scrape SERP from Bing.
Prerequisites
Working Laravel 6+ Application
Step 1 – Install Scavenger
Scavenger can be installed via composer as follows:
composer require reliqarts/laravel-scavenger
After which you must publish the configuration file with the following command:
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateBingResultsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('bing_results', function (Blueprint $table) {
$table->increments('id');
$table->text('link');
$table->text('description');
$table->integer('position')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('bing_results');
}
}
/app/BingResult.php
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class BingResult extends Model
{
}
Step 3 – Configure Scavenger
In your /config/scavenger.php file we need to create a target. We will use this the following for our setup. See: Target Breakdown for a full list of available options.
This configuration tells scavenger to go to bing.com, enter “dog” as a search term and scrape the results from the first 5 pages. In the markup section of the config we explain to Scavenger how each item should be transformed into the different attributes of our BingResult class. Again, these config keys are explained in detail here.
Note:__result, __link and __position are special markup keys which literally refer to the result item, link, and position in the result page list respectively. Meaning the item with __position = 5 appeared 5th in the bing results list.
With this target in place our complete configuration file looks something like this:
/config/scavenger.php
<?php
$bing = [
'example' => false,
'serp' => true,
'model' => \App\BingResult::class,
'source' => 'https://bing.com',
'search' => [
'keywords' => ['dog'],
'form' => [
'selector' => 'form#sb_form',
'keyword_input_name' => 'q',
],
],
'pager' => [
'selector' => '.sb_pagN',
],
'pages' => 3,
'markup' => [
'__result' => '.b_algo',
'title' => 'h2 a',
'description' => '.b_caption p',
'link' => '__link',
'position' => '__position',
],
];
return [
// debug mode?
'debug' => false,
// whether log file should be written
'log' => true,
// How much detail is expected in output, 1 being the lowest, 3 being highest.
'verbosity' => 1,
// Set the database config
'database' => [
// Scraps table
'scraps_table' => env('SCAVENGER_SCRAPS_TABLE', 'scavenger_scraps'),
],
// Daemon config - used to build daemon user
'daemon' => [
// Model to use for Daemon identification and login
'model' => \App\User::class,
// Model property to check for daemon ID
'id_prop' => 'email',
// Daemon ID
'id' => '[email protected]',
// Any additional information required to create a user:
// NB. this is only used when creating a daemon user, there is no "safe" way
// to change the daemon's password once he has been created.
'info' => [
'name' => 'Scavenger Daemon',
'password' => 'pass',
],
],
// guzzle settings
'guzzle_settings' => [
'timeout' => 60,
],
// hashing algorithm to use
'hash_algorithm' => 'sha512',
// storage
'storage' => [
'log_dir' => env('SCAVENGER_LOG_DIR', 'scavenger'),
],
// different model entities and mapping information
'targets' => [
'bing' => $bing,
],
];
Step 4 – Execution
With this in place it is now time to hop over to artisan and begin scraping our SERP.
Step 5 – Results
In the end Scavenger gives a comprehensive summary:
Our SERP have been successfully inserted into the database:
And, that’s it! We have 25 dog-based links scraped from bing on which we may perform any analysis/actions we desire.
Researchers have figured out the mystery behind ultra-black butterfly wings.
Some butterflies have ultra-black wings that rival the blackest materials made by humans, using wing scales that are only a fraction as thick.
Set against a piece of black construction paper, the wings of the male cattleheart butterfly look even blacker than black.
“Some animals have taken black to an extreme,” says Alex Davis, a graduate student in the lab of Duke University biologist Sönke Johnsen.
The butterflies they study are 10 to 100 times darker than charcoal, fresh asphalt, black velvet, and other everyday black objects. As little as 0.06% of the light that hits them is reflected back to the eye.
That approaches the blackest black coatings humans have made to help solar panels absorb more energy from the sun, or that line telescopes to reduce stray light.
Yet they achieve this light-trapping effect using wing scales that are only a few microns deep, just a fraction as thick as the blackest synthetic coatings.
In a study in Nature Communications, researchers report that ultra-black butterflies from disparate regions of the globe appear to have converged on the same trick.
The secret to making blacks this dark and lightweight, they say, isn’t a surplus of melanin—the pigment responsible for a crow’s feathers or a black cat’s fur. It’s an optical illusion created by the 3D structure of the butterflies’ wing scales.
Light goes into their scales, but very little of it bounces back out.
In the study, the researchers used high resolution scanning electron microscopy and computer simulations to examine the microscopic structures on the wings of 10 species of ultra-black butterflies and four regular black or dark brown butterflies from Central and South America and Asia.
Butterfly wings may look smooth to the naked eye. Up close it’s a different story. Magnified thousands of times, butterfly wings are covered in scales with a mesh-like surface of ridges and holes that channel light into the scale’s spongy interior. There, pillar-like beams of tissue scatter light until it is absorbed.
Until recently, the explanation for the incredible light-absorbing properties of some black butterflies was that it was due to a honeycomb-like pattern in the tiny holes on the scales’ surface.
But the new study suggests “that doesn’t matter,” Johnsen says. Looking at butterflies from four subfamilies—the widest range of ultra-black butterflies that have been examined to date—the team found that other ultra-black butterflies suck up similar amounts of light using holes with a variety of shapes and sizes, from honeycombs and rectangles to a chevron pattern.
It turns out the key differences between ultra-black and regular black scales lie elsewhere. When they looked at the butterflies’ wings under an electron microscope, they found that both ultra-black and regular black scales have parallel ridges on their surface and pillars within. But the ridges and pillars are deeper and thicker in ultra-black scales compared to “normal” black scales.
When the team mimicked different wing scales in computer simulations, scales lacking either the ridged surface or interior pillars reflected up to 16 times more light. That would be like going from ultra-black to dark brown, Davis says.
This 3D architecture is so good at swallowing light that the ultra-black scales still looked black even when coated with gold.
“You almost can’t make them shiny,” Davis says.
Similar deep blacks have popped up in other animals, such as peacock spiders and birds of paradise, which are known to reflect as little as 0.05% of visible light.
None of these natural beauties is quite as dark as the blackest synthetic blacks on record, which absorb more than 99.99% of incoming light using tightly packed “forests” of carbon nanotubes around 10 to 50 microns high. But what makes butterflies interesting, the researchers say, is they rival the best light-trapping nanotechnology, using structures that are only a fraction as thick.
Ultimately, the findings could help engineers design thinner ultra-black coatings that reduce stray light without weighing things down, for applications ranging from military camouflage—for stealth aircraft that can’t be seen at night or detected by radar—to lining space telescopes aimed at faint, distant stars.
Why ultra-black coloration has popped up again and again across the butterfly family tree is still unclear, Johnsen says.
The blackness on the wings of many male butterflies is darker than it is on their female counterparts, so one theory is it helps them show off to potential mates. The black regions always border white, colored, or iridescent patches, so the idea is they might work like a dark picture frame to make the brighter blotches pop.
“Artists have known for a long time that the same color can look very different on different backgrounds,” Johnsen says.
The next step, Davis says, is to figure out how many times butterflies have evolved ultra-black wings, and determine whether those species have anything in common that might help explain what favored the change.
“Why be so black?” Davis says. “We think it’s likely some sort of signal to mates or maybe a predator. But there’s a host of other possibilities, and we’re hoping to clear that up.”
Support for the research came from the Duke University biology department and a Sigma Xi Grant-in-Aid.
Ruger recently announced the newest version of its pistol caliber carbine is hitting distribution channels, and based on the success of the PC9, we’re reasonably confident it will find a ready audience. Like the 10/22 Charger, the latest addition to the lineup is a chopped-down version of an existing carbine, but is sold in a pistol configuration, rather than a factory SBR.
We’re currently in the process of wringing this one out, but for the moment the stats are as follows:
6.5-inch hammer forged barrel, threaded 1/2-28 for the muzzle device of your choice
Polymer chassis system which accepts AR15 pistol grips
Interchangeable mag wells to accept Glock and Ruger pistol mags
Takedown barrel and fore end
Pic rail section on rear of chassis to accept braces
The takedown feature means you can leave your can attached to the barrel, rather than unscrewing it
The takedown feature might seem to have limited use when teamed up with a six inch tube, but when used in conjunction with a can, it really comes into its own. You can leave the suppressor connected to the host and instead use the takedown feature as a QD mount – as an added benefit, the fore end doesn’t heat up anywhere near as much as the suppressor, so you can disassemble it without either waiting for it to cool, or using your shirt tail to avoid getting burned.
The pistol version of the PC carbine features a polymer chassis which accepts AR pistol grips
As part of our initial testing we added a Liberty Mystic X suppressor, Trijicon MRO, and SIG folding brace and it makes for a compact backpack gun- just the ticket for a run to the store to pick up more toilet paper …
When it comes to digital design, information architecture is all about enhancing the user experience (UX). Your website, software, and app must be designed in a way that is easy for your users to navigate.
The information must be divided into small parts. Also, information should be communicated concisely so the user can find the content they are looking for without any hassle. The process requires you to study your target audience thoroughly, define the context of your business, and provide valuable content.
Just like at the time of building a house, an architect needs a blueprint that has all the details. This includes floor plans and position of doors and windows. Information architecture gives the designer a blueprint for the users’ experience of the website.
The elements of information architecture include search systems, navigation systems, organization structuring, tags, and labeling systems. Information architecture allows you to build a website that is optimized for maximum conversion. Let’s have a look at a few ways in which information architecture affects the usability of your site.
Information Architecture Improves the User’s Experience
The toughest part of redesigning or improving a user interface is to figure out which features are most vital. By developing infrastructure, designers must involve the stakeholders. Usually, however, stakeholders are not familiar with the process of designing.
Still, they can provide you valuable information on how to communicate the content. This allows you to figure out the highlights of the project and lets you prioritize it accordingly as a designer. Information architecture (IA) will enable you to save valuable time while you build an improved product. That is what information architecture is all about.
IA Helps Correct Content Gaps
A designer may not have excellent command over the content he or she is integrating into the website. Still, they still must make sure that there are no gaps in the content. This is where information architecture comes in extremely handy for design professionals.
It provides you with a blueprint that projects content grouping, intuitive control, decision-congestion, recursive paths, and unused areas. According to designers, “IA has a tremendous impact on product design by making it easier for users to find important information.”
IA also differentiates between main content and extra information. This helps fill content gaps suitably. Additionally, IA helps enhance the overall quality of your website and improves SEO.
Information Architecture Mental Models and Improved Design
The mental model refers to the intuitive perception of an individual or a group of people. It explains a person’s thought process and how they think something works in the real world.
In simple terms, it is how an individual perceives their surroundings to deduce conclusions. Information architecture helps you understand your target audience’s mental model. This not only expands the designer’s knowledge, but it also allows them to customize a successful user experience.
How to Install MySQL 8 Database Server on CentOS 8
https://ift.tt/2UesiZB
MySQL is a free, open-source and one of the most popular database systems around the globe. In this tutorial, we will show you how to install MySQL 8 on CentOS 8 server.
As COVID-19, the disease caused by the coronavirus, spreads, it’s more important than ever to cancel unnecessary outings and use social distancing measures to try and limit how many people get infected. In other words, you’re going to be spending a lot of time inside. Here are some of the best video games to help you pass the time.
Some are classics, others are more recent, but all of them should help keep you occupied during the coming weeks and months depending on how long the pandemic continues. Even if they don’t completely distract you from our government’s inept and lie-filled response to the crisis, their dense beauty or brain-teasing complexity can hopefully restore your spirit a little.
Red Dead Redemption 2 (PS4, Xbox One, PC)
Maybe you bought Rockstar’s 19th-century wilderness simulator back when it came out. Maybe you got it recently as a gift or picked it up during a sale and then let it sit there on your TV stand collecting dust. Either way you probably haven’t finished it, or found even a tenth of what there is to discover and look at. It’s a big, beautiful game where you can pick up and leave civilization behind whenever you want.
Civilization VI (PS4, Xbox One, PC, Switch, iOS)
Speaking of civilization, if you’ve ever wished you could just completely break the world and then remake it in your own image and manage it as if you were a bureaucratic god, you’ve probably toyed with playing a Civilization game. If you have you know it’s easy for hours of your life to slip by unnoticed as you fine-tune tax policy and construct new religions determined to make your society not just work but flourish. If you haven’t there’s no better time to try and work out all of those pent up, half-baked ideas about war, peace, and social engineering on a world that you can always simply reboot with the click of a button.
The Legend of Zelda: Breath of the Wild (Switch, Wii U)
Some people have cars they dream about buying, or trips they’d go on if they ever came into some money. I have games that I think about playing if only the rest of my life ground to a halt. Breath of the Wild remains at the top of that list. I have spent dozens of hours running through its grass and teasing out its puzzles, and I still feel like I’ve only scratched the surface. Even if you could go outside it wouldn’t be as bright and colorful as it is in Breath of the Willd. Singer St. Vincent spent 300 hours playing it. Now you can, too.
No Man’s Sky (PS4, Xbox One, PC)
What Breath of the Wild does for the great outdoors, No Man’s Sky does for the galaxy. If you heard some bad things about it when it first launched, don’t worry. It’s all been fixed now, and then some. You can fly to dozens of planets, treating each one like a sandbox by exploring, creating, and crafting, then fly to a dozen more. Some of the spaceships are even alive. Plus, there are other people to meet in the game now. Maybe they’ll even invite you over to their own bespoke tiny homes for tea and space cookies.
Dragon Quest XI (PS4, Switch, PC)
Imagine a Final Fantasy game drawn by the guy who created Dragon Ball. That’s the pitch for the Dragon Quest series, and according to former Kotaku video producer Tim Rogers, Dragon Quest XI is the best one in the whole lot. Rogers liked it so much he played hundreds of hours of the Japanese version before going through and beating the English version as well. And the best part about this colorful love letter to classic JRPGs? It doesn’t even really get started until dozens of hours in. Yes. It’s one of those. If you need a comfort snack to last you for weeks, look no farther.
Assassin’s Creed Odyssey (PS4, Xbox One, PC)
There are a ton of Assassin’s Creed games, and a lot of them are pretty good, but none is as long and as chock full of weird details and extraneous content as Odyssey. It starts on a small island, and then moves to a bigger island, and then before you know it you have your own ship and are exploring the whole of ancient Greece. You don’t even need to visit most of the islands, but if you do, there will be a handful of characters waiting to tell you their stories and send you into a shimmering grotto or torch-lit cave to slay their enemies for them. And you will. And then you’ll do it again and again, drunk on the freedom of being able to climb anything and then dive off of it without dying.
Total War: Shogun 2 (PC)
There have been a lot of good Total War games. Some of the best ones have come out in just the last few years. Plenty of earlier ones still hold up just fine, though, including Shogun 2. Its battle systems and strategic possibilities have stood the test of time so much that the newer games are still basically just refining them. Sure, if you have a shiny new gaming rig that can play anything, dive into Total War: Warhammer 2 or Total War: Three Kingdoms. But if you want to painstakingly plan out some grand military campaigns and just have a work laptop because you never planned to spend days or possibly weeks at home playing a video game, Shogun2 will do you just fine.
The Witcher 3 (PS4, Xbox One, PC, Switch)
The Witcher 3 is a chilling mix of medieval fantasy and The X-Files where you can get drunk, play cards, box, and discover who murdered a farmhand’s family all in one night. Hands down one of the best games of the last decade. Play this game whether you’re quarantined or not.
Super Metroid (Switch, Wii U, New 3DS)
I’d be remiss if I didn’t recommend you took at least some of this time to play through a retro classic or two. Super Metroid is one of the best games from one of the best series on one of the best consoles of all time. Maybe a global pandemic isn’t the right time to be hunting through dark alien structures for parasites shaped like giant jellyfish. Or maybe that’s precisely the time to do it, facing the fear and challenge of being in a cramped, confined space with bombs and missiles until you come out the other side with your faith in the majesty of life reaffirmed.
Crusader Kings 2 (PC)
Crusader Kings 2 is such a good game we reviewed it twice. It’s a politics simulator for people who care about people—what they want, what they fear, what lies they tell about you behind your back. As with all the best simulators, you can keep running it over and over again and get different results each time. Feeling cut off from your family, friends, or coworkers? Play Crusader Kings 2 to remind yourself of the myriad ways people can stab one another in the back, then take some solace in the fact that you’ve finally got some time alone.
Monster Hunter: World (PS4, Xbox One, PC)
Want to kill the same creature over and over again, have it feel slightly different each time, and then use what you killed to make better weapons and cooler armor to go and kill even bigger ones? This is the central formula for lots of games, but Monster Hunter: World has so much fun with it that it’s hard not to want to keep coming back. It’s like going on a camping trip where sometimes you’re hiking through lush valleys and other times you’re slaying giant dinosaurs, and you always end the night cooking a big hunk of their meat over the fire while goofing around with friends.
Persona 5 (PS4, PS3)
Lots of schools are shutting down. Persona 5’s is still open, full of people to cheer up and extracurricular activities to take your mind off things. You also occasionally go into nightmare dungeons and enlist demons to help you beat up evil adults. There’s a running joke that while a lot of people love Persona 5 and have played it for dozens of hours, most still have never beaten it. Eventually you just graduate and move on, looking back fondly on the time you and your friends did that bullshit you thought was really important instead of going to class because it made you feel super cool. Now’s your chance to go back and turn in all those homework assignments the dog ate.
The Elder Scrolls: Skyrim (PS4, Xbox One, Switch, PC, PS3, Xbox 360)
Skyrim is a sprawling, open-world RPG that exists on almost every gaming device and platform for a reason: All it takes is a few fire spells, sword swings, and dragon yells to transport you back to the land of Tamriel like you’d been born there. I don’t even like Bethesda’s RPGs that much and I still get a fuzzy feeling every time I trek through a dense forest or up a snowy mountain hunting for somebody else’s business to entangle myself in. You don’t even need to finish the game. You can just go buy a house and live there.
Amazon delivery infrastructure strained as COVID-19 outbreak sparks surge in online shopping
https://ift.tt/3b18EXX
With thousands of Americans telecommuting and self-isolating to slow the spread of COVID-19, Amazon’s Prime and Fresh delivery services are grappling with high demand and inventory issues, as warehouse workers report increased order volumes.
Amazon is out of stock on a number of household staples and popular items, according to the company’s COVID-19 response page.
“You will also notice that some of our delivery promises are longer than usual,” the site says. “We are working around the clock with our selling partners to ensure availability on all of our products, and bring on additional capacity to deliver all of your orders.”
The consumer impact: Amazon can no longer guarantee two-day delivery on all Prime orders and some of the program’s 150 million subscribers customers are already experiencing delays. The Amazon Fresh website warns grocery deliveries “may be temporarily unavailable due to increased demand.” Amazon Fresh did not have any delivery windows available in the Seattle area as of Monday morning.
The increased demand comes as Amazon navigates supply chain threats from slowed or shuttered factories in China. Amazon did not immediately respond to questions about the delays.
The worker impact: The Seattle tech giant has asked all employees who can work from home to do so, an option unavailable to warehouse workers and delivery drivers. The company is providing two weeks of paid time off to all employees diagnosed with the virus or placed under quarantine.
Amazon is spending $25 million to help its network of independent delivery drivers, Amazon Flex workers, and seasonal employees deal with disruptions caused by the outbreak. The Amazon Relief Fund will provide grants equal to about two weeks’ pay for workers who have the virus or are quarantined. Grants are also available to workers facing financial or other hardships. Several warehouse worker groups have been circulating blog posts and petitions calling for more comprehensive sick time.
Other changes: Amazon has paused all fulfillment center tours, canceled large events, and shifted to virtual job interviews.
Bottom line: High demand is already causing delays for Amazon Prime and Fresh customers, a phenomenon that could be exacerbated by slowed imports or outbreaks of the virus among warehouse workers, who are already fielding high volumes of orders. Experts predict Amazon’s delivery infrastructure “will falter,” Motherboard reports.
However, some predict that Amazon will be one of the companies least impacted by a potential recession despite the disruptions. Analysts with RBC Capital Markets wrote on March 13 that Amazon “will be only modestly impacted” during a global financial crisis, due to growing reliance on the company for consumer staples, and expectations of continued growth in its Amazon Web Services cloud division.
In an all-out effort to slow the spread of the new coronavirus, health and government officials worldwide have mandated travel restrictions, closed schools and businesses, and set limits on public gatherings. People have also been urged to practice social distancing in public spaces, and to isolate themselves at home as much as possible. This rapid and widespread shift in rules and behavior has left much of the world looking very different than it did a few months ago, with emptied streets, schools, workplaces, and restaurants, and almost everyone staying home. Gathered below, some recent scenes from this pandemic, and the people coping with the many problems it is causing.