SQL Order of Operations – SQL Query Order of Execution


Knowing the bits and bytes of an SQL query’s order of operations can be very valuable, as it can ease the process of writing new queries, while also being very beneficial when trying to optimize an SQL query.

If you’re looking for the short version, this is the logical order of operations, also known as the order of execution, for an SQL query:

You can speed up any SQL query, automatically. Try it now for free.

  1. FROM, including JOINs
  2. WHERE
  3. GROUP BY
  4. HAVING
  5. WINDOW functions
  6. SELECT
  7. DISTINCT
  8. UNION
  9. ORDER BY
  10. LIMIT and OFFSET

But the reality isn’t that easy nor straight forward. As we said, the SQL standard defines the order of execution for the different SQL query clauses. Said that, modern databases are already challanaging that default order by applying some optimization tricks which might change the actual order of execution, though they must end up returning the same result as if they were running the query at the default execution order.

Why would they do that? Well, it can be silly if the database would first fetch all data mentioned in the FROM clause (including the JOINs), before looking into the WHERE clause and its indexes. Those tables can hold lots of data, so you can imagine what will happen if the database’s optimizer would stick to the traditional order of operations of an SQL query.

Let’s look into each of the SQL query parts according to their execution order.

FROM and JOINs

The tables specified in the FROM clause (including JOINs), will be evaluated first, to determine the entire working set which is relevant for the query. The database will merge the data from all tables, according to the JOINs ON clauses, while also fetching data from the subqueries, and might even create some temporary tables to hold the data returned from the subqueries in this clause.

In many cases though, the database’s optimizer will choose to evaluate the WHERE part first, to see which part of the working set can be left out (preferably using indexes), so it won’t inflate the data set too much if it doesn’t really have to.

WHERE clause

The WHERE clause will be the second to be evaluated, after the FROM clause. We have the working data set in place, and now we can filter the data according to the conditions in the WHERE clause.

These conditions can include references to the data and tables from the FROM clause, but cannot include any references to aliases defined in the SELECT clause, as that data and those aliases may not yet ‘exist’ in that context, as that clause wasn’t yet evaluated by the database.

Also, a common pitfall for the WHERE clause would be to try and filter out aggregated values in the WHERE clause, for example with this clause: “WHERE sum(available_stock) > 0“. This statement will fail the query execution, because aggregations will be evaluated later in the process (see the GROUP BY section below). To apply filtering condition on aggregated data, you should use the HAVING clause and not the WHERE clause.

GROUP BY clause

Now that we filtered the data set using the WHERE clause, we can aggregate the data according to one or more columns appearing in the GROUP BY clause. Grouping the data is actually splitting it to different chunks or buckets, where each bucket has one key and a list of rows that match that key. Not having a GROUP BY clause is like putting all rows in a one huge bucket.

Once you aggregate the data, you can now use aggregation functions to return a per-group value for each of the buckets. Such aggregation functions include COUNT, MIN, MAX, SUM and others.

You can speed up any SQL query, automatically. Try it now for free.

HAVING clause

Now that we have grouped the data using the GROUP BY clause, we can use the HAVING clause to filter out some buckets. The conditions in the HAVING clause can refer to the aggregation functions, so the example which didn’t work in the WHERE clause above, will work just fine in the HAVING clause: “HAVING sum(available_stock) > 0″.

As we’ve already grouped the data, we can no longer access the original rows at this point, so we can only apply conditions to filter entire buckets, and not single rows in a bucket.

Also, as we mentioned in previous sections, aliases defined in the SELECT clause cannot be accessed in the section either, as they weren’t yet evaluated by the database (this is true in most databases).

Window functions

If you are using Window functions, this is the point where they’ll be executed. Just like the grouping mechanism, Window functions are also performing a calculation on a set of rows. The main difference is that when using Window functions, each row will keep its own identity and won’t be grouped into a bucket of other similar rows.

Window functions can only be used in either the SELECT or the ORDER BY clause. You can use aggregation functions inside the Window functions, for example:

SUM(COUNT(*)) OVER ()

SELECT clause

Now that we are done with discarding rows from the data set and grouping the data, we can select the data we want to be fetched from the query to the client side. You can use column names, aggregations and subqueries inside the SELECT clause. Keep in mind that if you’re using a reference to an aggregation function, such as COUNT(*) in the SELECT clause, it’s merely a reference to an aggregation which already occurred when the grouping took place, so the aggregation itself doesn’t happen in the SELECT clause, but this is only a reference to its result set.

DISTINCT keyword

The syntax of the DISTINCT keyword is a bit confusing, because the keyword takes its place before the column names in the SELECT clause. But, the actual DISTINCT operation takes place after the SELECT. When using the DISTINCT keyword, the database will discard rows with duplicate values from the remaining rows left after the filtering and aggregations took place.

UNION keyword

The UNION keyword combines the result sets of two queries into one result set. Most databases will allow you to choose between UNION DISTINCT (which will discard duplicate rows from the combined result set) or UNION ALL (which just combines the result sets without applying any duplication check).

You can apply sorting (ORDER BY) and limiting (LIMIT) on the UNION’s result set, the same way you can apply it on a regular query.

ORDER BY clause

Sorting takes place once the database has the entire result set ready (after filtering, grouping, duplication removal). Once we have that, the database can now sort the result set using columns, selected aliases, or aggregation functions, even if they aren’t part of the selected data. The only exception is when using the DISTINCT keyword, which prevents sorting by a non-selected column, as in that case the result set’s order will be undefined.

You can choose to sort the data using a descending (DESC) order or an ascending (ASC) order. The order can be unique for each of the order parts, so the following is valid: ORDER BY firstname ASC, age DESC

LIMIT and OFFSET

In most use cases (excluding a few like reporting), we would want to discard all rows but the first X rows of the query’s result. The LIMIT clause, which is executed after sorting, allows us to do just that. In addition, you can choose which row to start fetching the data from and how many to exclude, using a combination of the LIMIT and OFFSET keywords. The following example will fetch 50 rows starting row #100: LIMIT 50 OFFSET 100


via Planet MySQL
SQL Order of Operations – SQL Query Order of Execution

Kavanaugh Accusers’ Official High School Yearbooks Detail Sex, Drunkenness & Racism

Photos from Christine Blasey Ford High School Yearbooks
Photos from Christine Blasey Ford High School Yearbooks

USA – -(AmmoLand.com)- Christine Blasey Ford, the accuser of Supreme Court nominee Bret Kavanaugh of a pool party groping, own High School yearbooks list in great detail rampant drinking & guns, promiscuity, racism, and sexual predation by the class of 82, 83 and 1984. The years “Chrissy”, as Blasey Ford is referred to, attended the all-girl school of Holton-Arms.

The yearbook title is SCRIBE. The relevant issues are SCRIBE 82, SCRIBE 83 and SCRIBE 84, corresponding to Blaseys’s sophomore, junior and senior years when she and her classmates (and Kavanaugh) were 15-17-year-old juveniles.

You can read an in-depth dissection of the yearbooks on the website Cult Of The 1st Amendment, but the shocking thing is how this detailed description of partying and disrespect could be the featured content of school approved and financed yearbook.

From the report “They [the yearbooks] are a testament to the incredible power these girls had over their teachers, parents and the boys of Georgetown Prep, Landon and other schools in the area. In the pages below, [see link above] you will see multiple photos and references to binge drinking and the accompanying joy of not being able to remember any of it.”

While Blasey Ford is only mentioned by name and in photos a few times, the implications are that in such a small group how we are to believe that she was not caught up in the wild predatory social party scenes?

Binge Drinking & Male Strippers:

Scribe 84 is the yearbook for her senior year. Her name was Christine Blasey in high school, often referred to as “Chrissy.” In the image below, Blasey is pictured at a Halloween party in her junior year. The caption on the right says:

“Lastly one cannot fail to mention the climax of the junior social scene, the party. Striving to extend our educational experience beyond the confines of the classroom, we played such intellectually stimulating games as Quarters, Mexican Dice and everyone’s favorite, Pass-Out, which usually resulted from the aforementioned two.”

Christine Blasey Ford is pictured at a Halloween party in her junior year
Christine Blasey Ford is pictured at a Halloween party in her junior year.

Specifically relevant to the accusations at hand is one section of the yearbook articles that report a regularly occurring pool party:

“10th grade seems to have been a ritual initiation into the “Holton party scene”. Another sophomore girl [named Martha, last name redacted, but we assume to be Martha Mispireta Shannon a fellow class mate, if it is her she could be a witness] threw multiple all night benders, the highlight of which featured an [adult?] male erotic dancer in gold g-string:”

Christine Blasey Ford Binge Drinking Pool Party's
Christine Blasey Ford Binge Drinking Pool Party’s

This info may help Christine Blasey Ford remember the exact details of events or provide info for a line of questioning for Senators trying to get to the facts.

Read the entire report at Cult Of The 1st Amendment.

The post Kavanaugh Accusers’ Official High School Yearbooks Detail Sex, Drunkenness & Racism appeared first on AmmoLand.com.

via AmmoLand.com
Kavanaugh Accusers’ Official High School Yearbooks Detail Sex, Drunkenness & Racism

Here’s What You Can Do With Apple’s New iOS 12 Parental Controls 


Parents, to curb your kid’s phone usage, you may no longer need to hold their chargers hostage, yell out nightly countdowns (“Three more minutes!”) or draft up elaborate tech contracts that you’ll look at exactly once. At least, if you’re on Apple devices. The new iOS 12 parental controls are here, and they allow you to manage your children’s screen time—set app time limits, block off chunks of “downtime” and track their daily habits—all from your own phone. Here’s what you can do, and how to do it.

How to access the Screen Time feature for your child using your own device:

  • Make sure both of your devices are on iOS 12.
  • Set up Family Sharing if you haven’t already.
  • Go to Settings > Screen Time.
  • Scroll down to the names of those in your Family Sharing plan. Choose the child for which you’d like to set up parental controls.
  • Enter a four-digit Screen Time passcode. Choose one that you can remember and your kid can’t guess. You’ll need it to approve requests for more screen time.

Now, here’s a look at what you can do with Screen Time.

Lock Your Kid Out of Their Phone During Family Dinner or Bedtime

The feature: Downtime

How it works: Remotely schedule a block of time in which your kid’s device cannot be used, such as during family dinner or his little sister’s flute recital. During this stretch, an icon will appear on all his apps indicating that they are not allowed to be used. (Phone, Messages, FaceTime, Alarm and some other functions will still work by default, but you can shut those down, too, if you wish.) If there are apps that you do want your kid to have access to during the scheduled downtime—say, bedtime meditations or white noise—you can make them Aways Allowed.

Tip: It might help to talk about your limits with other parents in your neighborhood. If you all plan to block your kids out of their apps at the same time, perhaps they can—gasp—call each other on the phone or even hang out IRL.

Put Time Limits on Fortnite (or Any App)

The feature: App Limits

How it works: Set a specific amount of time that your kid can be on certain apps each day. You can create limits for either specific categories, such as Social Networking or Gaming, or all apps. (It’s a little frustrating, however, as you don’t get to determine which apps go in which categories.) A warning will appear five minutes before the time is up, preventing screams of shock and despair. Once the allotted limit has been reached, your child can send you a request for more time, and you can either approve it or not.

See How Your Kid Is Really Spending Her Time On Her Phone

The feature: Activity Reports

How it works: On your own device, you can check out daily and weekly activity reports showing you how much time your kid is spending in each app (or across categories of apps), along with the number of notifications he’s receiving and how often he’s picking up his phone. It’s a way to know if he’s sneaking in games during third-period math or playing Roblox when he’s supposed to be in his room reading.

The reports can also be a good place to start a conversation with your kids about screen time, especially if you’re tracking your own phone usage. (I am, and it’s slightly horrifying.) You can ask your children how much time they think they’re spending on their phones, and then compare that to the actual data. As Tommy Sobel, the founder and CEO of Brick, writes: “Most people use their phones twice as much as they think they do, so seeing your actual minutes spent can be an incredibly powerful impetus to get real with yourself and get motivated about the need to take control of your phone habits.”

Block Content and Turn Off In-App Purchases and Location Services

The feature: Content & Privacy Restrictions

How it works: We’ve long been able to limit kids’ access to music, movies and other content on Apple devices, but with iOS 12, we can now do all of this remotely. Under iTunes and App Store Purchases, you can choose whether your child may install new apps, delete apps or make in-app purchases. Under Content Restrictions, you can set content ratings for books, music, TV shows, movies and apps. (I like how specific you can get—for instance, you may want to block “explicit” TV shows while giving your kid unfiltered access to books.) If you don’t want any app to know your kid’s location, you can indicate that, too.

As your kids get older and show that they can use their phones responsibly, you’ll want adjust their Screen Time settings in a way that makes sense. Let it be an ongoing conversation. If you need some talking points, check out our age-by-age guide to setting smartphone limits for your kids.


via Gizmodo
Here’s What You Can Do With Apple’s New iOS 12 Parental Controls 

MySQL and Memory: a love story (part 1)

As you may know, sometimes MySQL can be memory-hungry. Of course having data in memory is always better than disk… RAM is still much faster than any SSD disk.

This is the reason why we recommended to have the working set as much as possible in memory (I assume you are using InnoDB of course).

Also this why you don’t want to use Swap for MySQL, but don’t forget that a slow MySQL is always better than no MySQL at all, so don’t forget to setup a Swap partition but try to avoid using it. In fact, I saw many people just removing the Swap partition… and then OOM Killer did its job… and mysqld is often its first victim.

MySQL allocates buffers and caches to improve performance of database operations. That process is explained in details in the manual.

In this article series, I will provide you some information to check MySQL’s memory consumption and what configuration settings or actions can be made to understand and control the memory usage of MySQL.

We will start the series by the Operating System.

Operating System

In the OS level, there are some commands we can use to understand MySQL’s memory usage.

Memory Usage

You can check mysqld‘s memory usage from the command line:

# ps -eo size,pid,user,command --sort -size | grep [m]ysqld \
  | awk '{ hr=$1/1024 ; printf("%13.2f Mb ",hr) } { for ( x=4 ; x<=NF ; x++ ) { printf("%s ",$x) } print "" }' \ 
  |cut -d "" -f2 | cut -d "-" -f1

1841.10 Mb /usr/sbin/mysqld 
   0.46 Mb /bin/sh /usr/bin/mysqld_safe

top can also be used to verify this.

For top 3.2:

# top -ba -n1 -p $(pidof mysqld) | grep PID -A 1
PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                                                                                
 1752 mysql     20   0 1943m 664m  15m S  0.0 11.1  19:55.13 mysqld                                                                                                                                 
# top -ba -n1 -m -p $(pidof mysqld) | grep PID -A 1
  PID USER      PR  NI  USED  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                                                                                
 1752 mysql     20   0  664m 664m  15m S  2.0 11.1  19:55.17 mysqld

For more recent top, you can use top -b -o %MEM -n1 -p $(pidof mysqld) | grep PID -A 1

VIRT represents the total amount of virtual memory used by mysql. It includes all code, data and shared libraries plus pages that have eventually been swapped out.

USED reports the sum of process rss (resident set size, the portion of memory occupied by a process that is held in RAM) and swap total count.

We will see later what we can check from MySQL client.

SWAP

So we see that this can eventually include the swapped pages too. Let’s check if mysqld is using the swap, and the first thing to do is to check is the machine has some information in swap already:

# free -m
             total       used       free     shared    buffers     cached
Mem:          5965       4433       1532        128        454       2359
-/+ buffers/cache:       1619       4346
Swap:         2045         30       2015

We can see that a little amount of swap is used (30MB), is it by MySQL ? Let’s verify:

# cat /proc/$(pidof mysqld)/status | grep Swap
VmSwap:	       0 kB

Great, mysqld si not swapping. In case you really want to know which processes have swapped, run the following command:

for i in $(ls -d /proc/[0-9]*) 
do  
   out=$(grep Swap $i/status 2>/dev/null)
   if [ "x$(echo $out | awk '{print $2}')" != "x0" ] && [ "x$(echo $out | awk '{print $2}')" != "x" ]
   then    
	  echo "$(ps -p $(echo $i | cut -d'/' -f3) \
         | tail -n 1 | awk '{print $4'}): $(echo $out | awk '{print $2 $3}')" 
   fi
done

Of course the pages in the swap could have been there for a long time already and never been used since…  to be sure, I recommend to use vmstat and verify the columns si and so (a trending system is highly recommended):

# vmstat  1 10
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 0  0  31252 1391672 505840 2523844    0    0     2    57    5    2  3  1 96  0  0	
 1  0  31252 1392664 505840 2523844    0    0     0   328  358  437  6  1 92  1  0	
 0  0  31252 1390820 505856 2523932    0    0     0  2024 1312 2818 28  3 67  2  0	
 0  0  31252 1391440 505860 2523980    0    0     0   596  484  931  1  1 98  1  0	
 0  0  31252 1391440 505860 2523980    0    0     0  1964  500  970  0  1 96  3  0	
 0  0  31252 1391440 505860 2523980    0    0     0    72  255  392  0  0 98  2  0	
 0  0  31252 1391440 505860 2523980    0    0     0     0  222  376  0  0 99  0  0	
 0  0  31252 1391440 505908 2524096    0    0     0  3592 1468 2095 34  6 52  9  0	
 0  0  31252 1391688 505928 2524092    0    0     0  1356  709 1179 12  1 85  2  0	
 0  0  31252 1390696 505928 2524092    0    0     0   152  350  950  4  6 90  1  0

On this server, we can see that mysqld is not using the swap, but if it was the case and some free RAM was still available, what could have been done ?

If this was the case, you must check 2 direct causes:

  1. swappiness
  2. numa

Swappiness

The swappiness parameter controls the tendency of the kernel to move processes out of physical memory and put them onto the swap disk partition. As I explained earlier,  disks are much slower than RAM, therefore this leads to slower response times for system and applications if processes are too aggressively moved out of memory. A high swappiness value means that the kernel will be more apt to unmap mapped pages. A low swappiness value means the opposite, the kernel will be less apt to unmap mapped pages. This means that the higher is the swappiness value, the more the system will swap !

The default value (60) is too high for a dedicated MySQL Server and should be reduced. Pay attention that with older Linux kernels (prior 2.6.32), 0 meant that the kernel should avoid swapping processes out of physical memory for as long as possible. Now the same value totally avoid swap to be used. I recommend to set it to 1 or 5.

# sysctl -w vn.swappinness=1

Numa

For servers having multiple NUMA cores, the recommendation is to set the NUMA mode to interleaved which balances memory allocation to all nodes. MySQL 8.0 supports NUMA for InnoDB. You just need to enable it in your configuration: innodb_numa_interleave = 1

To check if you have multiple NUMA nodes, you can use numactl -H

These are two different output:

# numactl -H
available: 1 nodes (0)
node 0 cpus: 0 1 2 3 4 5 6 7
node 0 size: 64379 MB
node 0 free: 2637 MB
node distances:
node 0 
0: 10
# numactl -H
available: 4 nodes (0-3)
node 0 cpus: 0 2 4 6
node 0 size: 8182 MB
node 0 free: 221 MB
node 1 cpus: 8 10 12 14
node 1 size: 8192 MB
node 1 free: 49 MB
node 2 cpus: 9 11 13 15
node 2 size: 8192 MB
node 2 free: 4234 MB
node 3 cpus: 1 3 5 7
node 3 size: 8192 MB
node 3 free: 5454 MB
node distances:
node 0 1 2 3 
0: 10 16 16 16 
1: 16 10 16 16 
2: 16 16 10 16 
3: 16 16 16 10

We can see that when there are multiple NUMA nodes (right column), by default the memory is not spread equally between all those nodes. This can lead to more swapping. Check these two nice articles from Jeremy Cole explaining this behavior:

Filesystem Cache

Another point we can check from the OS is the filesystem cache.

By default, Linux will use the filesystem cache for all I/O accesses (this is one of the reason why using MyISAM is not recommended, as this storage engine relies on the FS cache and can lead in loosing data as Linux sync those writes up to every 10sec). Of course as you are using InnoDB, with O_DIRECT as innodb_flush_method, MySQL will bypass the filesystem cache (InnoDB has already enough optimized caches anyway and one extra is not necessary). InnoDB will then not use any FS Cache Memory for the data files (*.ibd).

But there are of course other files used in MySQL that will still use the FS Cache. Let’s check this example:

# ~fred/dbsake fincore binlog.000017
binlog.000017: total_pages=120841 cached=50556 percent=41.84

# ls -lh binlog.000017 
-rw-r----- 1 mysql mysql 473M Sep 18 07:17 binlog.000017

# free -m
             total       used       free     shared    buffers     cached
Mem:          5965       4608       1356        128        435       2456
-/+ buffers/cache:       1716       4249
Swap:         2045         30       2015

# ~fred/dbsake uncache binlog.000017 
Uncached binlog.000017
# free -m
             total       used       free     shared    buffers     cached
Mem:          5965       4413       1552        128        435       2259
-/+ buffers/cache:       1718       4247
Swap:         2045         30       2015

Some explanations. I started checking how much of one binary log was present in the filesystem cache (using dbsake fincore), and we could see that 42% of 473M were using the RAM as FS cache. Then I forced an unmap of those pages in the cache (using fincore uncache) and finally, you could see that we freed +/- 195MB of RAM.

You could be surprised to see which logs or datafiles are using the FS cache (making a file copy for example). I really encourage you to verify this 😉

The next article will be about what can be seen from MySQL’s side and what are the best configuration practices.

via Planet MySQL
MySQL and Memory: a love story (part 1)

New Ohio law incentivizes businesses that comply with cybersecurity programs

On Aug. 3, 2018, Gov. John Kasich signed Senate Bill 220, also known as the Ohio Data Protection Act. Under the Act, eligible organizations may rely on their conformance to certain cybersecurity frameworks as an affirmative defense against tort claims in data breach litigation. The Act is intended to provide organizations with a legal incentive to implement written cybersecurity programs. 
In order to qualify for this new defense, the organization must implement a written cybersecurity program…

via Columbus Business News – Local Columbus News | Business First of Columbus
New Ohio law incentivizes businesses that comply with cybersecurity programs

Many to Many Polymorphic Relations

We’ve finally made it to the most intimidating of Eloquent relationships: many to many polymorphic. Don’t worry; it’s far simpler to understand than you might initially think. In this lesson, we’ll construct a standard many-to-many relationship: a user can "like" a post. Then, we’ll throw a wrench into the mix. What if a user can also "like" a comment? How might we restructure our existing structure to allow for this?
via Laracasts
Many to Many Polymorphic Relations

How To Tell If You Or Someone You Love Is A Narcissist

We have all known that person, the one who monopolizes the conversations or seems to always have a flattering story to tell – always about themselves. Maybe, we listen politely for a bit and make a break for it as soon as we possibly can. Perhaps, we suffer silently while inwardly rolling our eyes.

But what if that person is you? Would you even know it?

Identifying narcissism in others is one thing. There are some glaring signs that we can all agree upon. However, identifying it in yourself can be more difficult.

Most narcissists have no idea that they fall into this category. They often view themselves as unique, special, outgoing or justifiably confident. What they don’t realize is that those views taken to the extreme can cause many problems in their relationships, work or even their family.

Why Narcissism Is Dangerous

narcissistic person

Although narcissism can be a dangerous trait, it exists in all of us to some degree. In its most mild and most common form, it can be looked at as a desire to feel special. We can all relate to that on some level. Wanting to feel like there is something that makes us unique, interesting or desirable is completely normal.

For some, however, this goes far beyond the general desire to stand out. For certain people, narcissism can become so extreme that they can no longer relate to anyone around them. They feel they are in a category of greatness no one can understand. They may also assume that they are so unique that rules don’t apply to them or that they are more interesting and have far more to offer than anyone else.

The narcissist may become so intent on proving their superiority that they lie, manipulate or hurt those around them. They do these things in order to maintain the feeling that they are better and more worthy of admiration than anyone else. While these behaviors are destructive in and of themselves, they also have an impact that goes far beyond the day-to-day.

Relationships for someone with extreme narcissistic behavior are often either short-lived or unhealthy. A healthy relationship balances the needs of both partners with each respecting and appreciating the other. When your focus is completely on yourself, this isn’t possible. People in relationships with narcissists will often be used as a prop for the narcissist’s ego. This should prompt a swift end to a relationship because it often results in emotional and mental abuse.

Recognizing Narcissism

narcissist

This isn’t really a fair question because almost everyone will answer no. None of us wants to feel like our behavior rises to that level. It is possible, however, that you are or someone you love is exhibiting narcissistic tendencies.

Consider the following questions when recognizing narcissism:

  • Do you often feel like your decision-making skills are better than others?
  • Do you override what others want because you are sure your desires/interests/plans are better?
  • Are your achievements over-embellished?
  • Do you often think, “they will thank me for this later” when you are doing things?
  • Do you feel like you have an undiscovered talent and you are just biding your time until people see it?
  • Are you a good listener or are you just waiting for someone to stop talking so that you can talk?
  • Do you feel like you have a way to get around things you don’t like and that the rules don’t really apply to you?
  • Do you expect to receive special treatment above others in the same situation?
  • Are you looking forward to talking about your achievements?
  • Do you always have an “I can do you one better” kind of story when others have talked about something?
  • Do you reject criticism and feedback as being stupid or a product of other people’s jealousy of you?

If the answer to more than a couple of these questions is yes, you or the person you answered for could likely be classified as a narcissist.

Narcissism can be a disabling trait. It destroys friendships, romantic relationships, careers, and causes a great deal of personal pain and conflict. When a person finally comes to terms with the truth, it can be a difficult road to recovery.

If you recognize these behaviors in yourself or someone else, it is time to initiate change. For a narcissist, change is a big step in the right direction.

That change is possible but it won’t happen overnight. So, if you or someone you love is trying to make positive alterations, be patient. With time, effort, and a good support system it can be done.

The post How To Tell If You Or Someone You Love Is A Narcissist appeared first on Dumb Little Man.


via Dumb Little Man – Tips for Life
How To Tell If You Or Someone You Love Is A Narcissist

Laravel View Models



Laravel Packages
/
September 18, 2018

Laravel View Models

The Laravel View Models by Brent Roose of Spatie is a package that can move the work you might do in a controller to a “view model”:

Have you ever made a controller where you had to do a lot of work to prepare variables to be passed to a view? You can move that kind of work to a so-called view model. In essence, view models are simple classes that take some data and transform it into something usable for the view.

A view model class is designed to house the complex logic of your views and clean up view-related logic from controllers:

class PostViewModel extends ViewModel
{
    public $indexUrl = null;

    public function __construct(User $user, Post $post = null)
    {
        $this->user = $user;
        $this->post = $post;

        $this->indexUrl = action([PostsController::class, 'index']); 
    }

    public function post(): Post
    {
        return $this->post ?? new Post();
    }

    public function categories(): Collection
    {
        return Category::canBeUsedBy($this->user)->get();
    }
}

The above view model class gets created in the controller:

class PostsController
{
    public function create()
    {
        $viewModel = new PostViewModel(
            current_user()
        );

        return view('blog.form', $viewModel);
    }

    public function edit(Post $post)
    {
        $viewModel = new PostViewModel(
            current_user(), 
            $post
        );

        return view('blog.form', $viewModel);
    }
}

And together, the view model and the controller provide your view with the following abilities:

<input type="text" value="" />
<input type="text" value="" />

<select>
    @foreach ($categories as $category)
        <option value=""></option>
    @endforeach
</select>

<a href="">Back</a>

All public methods and properties in a view model are automatically exposed to the view.

I think this package is an excellent abstraction of this logic, and instead of passing the view model to the view, you can return a view directly like this:

class PostsController
{
    public function update(Request $request, Post $post)
    {
        // …

        return (new PostViewModel($post))->view('post.form');
    }
}

And last but not least, you can expose functions which require extra parameters:

class PostViewModel extends ViewModel
{
    public function formatDate(Carbon $date): string
    {
        return $date->format('Y-m-d');
    }
}

Which you can then reference in your template:


Thanks to Brent Roose and the folks at Spatie for this excellent package! You can access the code and installation instructions from the GitHub repository spatie/laravel-view-models.


via Laravel News
Laravel View Models

Congressional Research Service Reports Now Officially Publicly Available

For many, many years we’ve been writing about the ridiculousness of the Congressional Research Service’s reports being kept secret. If you don’t know, CRS is a sort of in-house think tank for Congress, that does, careful, thoughtful, non-partisan research on a variety of topics (sometimes tasked by members of Congress, sometimes of its own volition). The reports are usually quite thorough and free of political nonsense. Since the reports are created by the federal government, they are technically in the public domain, but many in Congress (including many who work at CRS itself) have long resisted requests to make those works public. Instead, we were left with relying on members of Congress themselves to occasionally (and selectively) share reports with the public, rather than giving everyone access to the reports.

Every year or so, there were efforts made to make all of that research available to the public, and it kept getting rejected. Two years ago, two members of Congress agreed to share all of the reports they had access to with a private site put together by some activists and think tanks, creating EveryCRSReport.com, which was a useful step forward. At the very least, we’ve now had two years to show that, when these reports are made public, the world does not collapse (many people within CRS feared that making the reports public would lead to more political pressure).

Earlier this year, in the Consolidated Appropriations Act of 2018, there was a nice little line item to officially make CRS reports publicly available.

And, this week, it has come to pass. As announced by Librarian of Congress Carla Hayden, there is now an official site to find CRS reports at crsreports.congress.gov. It appears that the available catalog is still limited, but they’re hoping to expand backwards to add older reports to the system (a few quick test searches only shows fairly recent reports). But all new reports will be added to the database.

The result is a new public website for CRS reports based on the same search functionality that Congress uses – designed to be as user friendly as possible – that allows reports to be found by common keywords. We believe the site will be intuitive for the public to use and will also be easily updated with enhancements made to the congressional site in the future.

Moving forward, all new or updated reports will be added to the website as they are made available to Congress. The Library is also working to make available the back catalog of previously published reports as expeditiously as possible.

This is a big deal. The public pays over $100 million every year to have this research done, and all of it is in the public domain. Starting now, we can actually read most of it, and don’t need to rely on leaks to find this useful, credible research.

Permalink | Comments | Email This Story

via Techdirt
Congressional Research Service Reports Now Officially Publicly Available