teleren/devto huggingface dataset:
How to Print or Get Last Executed Query in Laravel 8
Tags: laravel, php, tutorial, beginners
Published: 2022-05-12 03:17:51

Originally posted @ https://codeanddeploy.com visit and download the sample code:
https://codeanddeploy.com/blog/laravel/how-to-print-or-get-last-executed-query-in-laravel-8

In this post, I will show you how to print or get the last executed query in your Laravel 8 application. Sometimes we need to do this to log or debug and determine what is the performance of our queries.

 

Luckily Laravel provides a method to get the last executed query and I will show you how.

 

## Get Last Query in Laravel Eloquent

In this example, we will just add toSql() method to our eloquent query. See the below example:

```php
$user = User::where('id',1)->toSql();
dd($user);
```

See below output:

```php
"select * from `users` where `id` = ?"
```

Log Last Query in Laravel Eloquent

In this method, we will log our last Laravel eloquent query. See below example code:

```php
DB::enableQueryLog();
$user = User::get();
$query = DB::getQueryLog();
dd($query);
 
```

Sample output:

```
array:1 [▼
  0 => array:3 [▼
    "query" => "select * from `users`"
    "bindings" => []
    "time" => 30.66
  ]
]
```

Debug the Last Laravel Eloquent Query

In this sample, we will debug the last Laravel eloquent query. See below code:

```php
DB::enableQueryLog();
$user = User::get();
$query = DB::getQueryLog();
$query = end($query);
dd($query);
```

Sample output:

```
array:3 [▼
  "query" => "select * from `users`"
  "bindings" => []
  "time" => 22.04
]
```

## Get/Print Last Executed MySQL Query
In this section, we will get/print the last executed MySQL query. See the following example:

```php
\DB::enableQueryLog();
$users = \DB::table("users")->get();
$query = \DB::getQueryLog();
dd(end($query));
```

Output:

```
array:3 [▼
  "query" => "select * from `users`"
  "bindings" => []
  "time" => 26.94
]
```

Now you have an idea of how to log/debug the last executed query in your Laravel application.

I hope this tutorial can help you. Kindly visit here https://codeanddeploy.com/blog/laravel/how-to-print-or-get-last-executed-query-in-laravel-8 if you want to download this code.

Happy coding :)
How to Create Personal Projects on Salesforce
Tags: salesforce, beginners, tutorial, career
Published: 2022-05-12 02:48:51

Creating a project in Salesforce can seem complicated, but it's actually really simple! So here's how you can accomplish that.
### Prerequisites
- Just Your Internet 😊

# Sign Up for a Developer Org
![Developer Org](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6q070jnoecjcoran8yf0.PNG)
I know what your thinking, but Dave, I don't know a single line of code! Don't panic, this applies to architects, admins, business managers, and more (for Omnistudio developers, you'll have to access the Vlocity Success community and have a Vlocity license).

## Fill in the Fields

![Sign Up Fields](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dlm8qzyf7zvnuu92rhar.PNG)
There are a couple things you should know before filling in the fields:
- Usernames MUST be in an email format, but it doesn't have to be an actual email; ex: daveguz@acmeindustries.com
- Usernames MUST be unique across ALL orgs. Because Salesforce is like an apartment building and each tenant must have a unique name.

#Conclusion
And now you have a Developer Org you can mess around in and build custom projects. There are some limits like you can only have two salesforce license users. But now you can build projects special to you!
Free Tailwind Css News Template
Tags: tailwindcss, html, tailwindtemplates, css
Published: 2022-05-12 02:45:34

Tailnews is Tailwind News Template with optimized for Newspapper and Magazine site. Integrated with Npm tool like Gulp, Browsersync and other tools for automatic workflow. Documented with live examples and snippets code. Easy to change colors, text sizes and all style only from html file.

Demo Preview: https://tailnews.tailwindtemplate.net/

**Tailnews template features**

- Design optimized with Google Core Web Vital
- 2 Homepage examples
- 2 Post example
- Supported Latest Tailwind Css
- tegrated Gulp, Browsersync and other tools
- Fast loading speed
- Seo Friendly (heading tag structured)
- Mobile first design
- Modern svg icons
- All source link images included in download package
- Commented code
- Well Documented
- … and much more

**Tailwind Components included**

Tailnews Components are also available on the documentation page. So you can develop this template design easily without having to create components again. 

**The powerful Plugins Included**

To make the design more attractive, we use some of the best plugins that we have selected by considering the plugin size and loading speed, so that it doesn’t affect the performance of the Tailnews template.

- Splide js Slider
- Splide Video
- Hc sticky
- Glightbox
- Google Fonts

**How to start with Tailnews ?**

Looking to quickly add Tailnews components to your project? Please read our docs/index.html and follow instruction step by step. All Tailnews components is well documented with live examples. We’re using official Tailwind classes and components whenever possible so integration with your project will be as smooth as possible.

**Workflow Tools**

Speed up your development process with modern tools. Tailpro included npm scripts to automate your time-consuming tasks in your development workflow with Gulp toolkit and BrowserSync live browser reload.

Open directory

Running "npm install"

Running "npm run start"

Yup that’s it !

**Note:**

This template is html version ( Not WordPress, Blogger or other cms theme )

**Download Link**
https://themes.tailwindtemplate.net/tailwind-news-template

Follow my Twitter https://twitter.com/ari_budin for get other freebies and premium html template.
Pegam - Password Protected Message Sharing Platform
Tags: appwritehack
Published: 2022-05-12 02:38:13

I saw this Appwrite hackathon on dev.to and I guess I was taken in by the big numbers or the promise of a free t-shirt, but one way or another I thought “I could do that!” and so now I’m doing that.
Its Pegam - Password Protected & Encrypted Message Sharing Platform


### Overview of My Submission
Its a file and message sharing file where you can send encrypted password protected messages to anyone and share it to anyone. Thought I have built this within 3 days due to my exams but i think its pretty good for this hackathon. The tech stacks which were used was React JS, Material UI and Appwrite.


License: MIT License :  https://github.com/kafle1/pegam-hackathon/blob/master/LICENSE



### Submission Category: 

Web2 Wizards, Wacky Wildcards


### Link to Code

Check out my Github Repo for the source code:
https://github.com/kafle1/pegam-hackathon

### Additional Resources / Info
Images/ Screenshots:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/arqc5h9kwx4ovog5fwwc.png)
 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a3sss005oja5u5hvifb4.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/54ltt2ohj10ltg4rpafp.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ls4wlw1jo1fqwx2quw6c.png)

Database:
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i5neqnugsft52jnmabdd.png)
ADDEVENTLISTENER
Published: 2022-05-12 01:43:25

Event listeners are what make Javascript dynamic and fun. It allows the developer to be creative and experiment with their application to make it interesting and expressive. There are all kinds of keyword events that just about allow the user to do anything to interact with the browser.

The addEventListener() is an inbuilt function in JavaScript which takes the event to listen for, and a second argument to be called whenever the described event gets fired. Any number of event handlers can be added to a single element without overwriting existing event handlers.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m8pupflc4cfwyttpiuy8.png)

Here are some of the most common event types and event names:

- Mouse Events: click, dblclick, mousedown, mouseup, contextmenu, mouseout, mousewheel, mouseover.

- Touch Events: touchstart, touchend, touchmove, touchcancel.

- Keyboard Events: keydown, keyup, keypress.

- Form Events: focus, blur, change, submit.

- Window Events: resize, scroll, load, unload, hashchange.

Touch events are triggered on touch-enabled devices such as smartphones, tablets, and touch-screen laptops. Mouse events are triggered on the majority of all browsers and devices. The MouseEvent interface represents events that occur due to the user interacting with a pointing device.

The click event: The onclick event occurs when the user clicks on an element.

The dblclick event: ondblclick event occurs when the user double-clicks on an element.

Mousedown & Mouseup events:A pointing device button is pressed/released on an element.

Mouseout event: A pointing device is moved off the element that has the listener attached.

Keyboard events(keydown, keyup):

- Keydown: Any key is pressed.

- keyup: Any key is released.


Form Events(change, submit):

- change: Event that is fired for input, select, and textarea elements when an alteration to the element’s value is done by the user.

- submit: The submit button is pressed.

DOM events that are used are:

- error: A resource has failed to load.

- online: The browser has gained access to the network.

Window Events(resize, load, unload):

- resize: This event fires when the document view(window) has been resized.

- load/unload: The load event is fired when the whole page has loaded, including all resources such as css and images. Unload is when the document or child resource is being unloaded.
Hiring Sr. Full Stack Developer-Rails/React (100% Remote) USA Citizen or GC Only
Tags: rails, ruby, react, angular
Published: 2022-05-12 01:29:56

My SaaS client is seeking a full time direct hire Sr. Full Stack Developer (Rails/React).  100% Remote, candidate must be living in the USA and be US Citizen and or Green Card Holder.  My staffing company is seeking candidates to interview who are available for full time W2 employment.
Appwrite Hackathon Submission - Income Tracker
Tags: appwritehack
Published: 2022-05-12 01:09:30

### Overview of My Submission
An income tracker application built with Vue and Appwrite allows users to monitor and keep track of their expenses. The
income tracker app makes it easy for anyone to add, edit, update, and delete any information from the client-side, and
it updates accordingly in the database.


### Submission Category: 

Web2 Wizards


### Link to Code

{% embed https://github.com/Terieyenike/vue-income-tracker-with-appwrite %}


### Additional Resources / Info

Tutorial: [How to Build an Income Tracker Using Vue and Appwrite](#)

### Screenshot

![income tracker preview](https://user-images.githubusercontent.com/25850598/167958427-c5ef7843-2f6b-401c-9cea-815e99d27aa4.png)

### Screen recording

{% youtube zzF76LH2u00 %}
Blockchain Layers
Tags: blockchain, programming, opensource, ethereum
Published: 2022-05-12 01:02:29

There are 4 layers in blockchains:

[https://medium.com/@nick.5montana/blockchain-layers-l0-l1-l2-l3-in-a-diagram-569162398db](https://medium.com/@nick.5montana/blockchain-layers-l0-l1-l2-l3-in-a-diagram-569162398db)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u5t896f4cm173ihl63w2.png)

**Layer 0:**
The ground floor. This is where the internet, hardware, and connections exist that allow layer 1s like Bitcoin to run smoothly. Layer 0s are allowing several things to happen:

1) Allow blockchains to interact with each other

A great example is Cosmos, which creates an ecosystem of interoperable blockchains thanks to its ‘Tendermint IBC’ (Inter-blockchain communication protocol).
For developers, this is massive. If a Dapp can function on one blockchain, it can function automatically on other blockchains so long as they’re built using the same layer 0. No need to invest more time and resources to build the same app on another chain.

2) Faster and cheaper transactions

With IBC, PoS consensus can be achieved across multiple chains resulting in finality times happening almost instantaneously (finality = when a block is approved, can’t be rolled back, and is considered irreversible). The result is faster and cheaper transactions on cross-chain exchanges.

3) Infrastructure for developers

Developers don’t need to start from scratch and build their blockchains from the ground up. Many features are pre-built and ready to be implemented immediately.

**Layer 1:**
Layer 1s are blockchains (Bitcoin and Ethereum) that process and finalize transactions on their own blockchain. This is where things like consensus (PoW, PoS) and all the technical details like block time and dispute resolution take place.

The most important three aspects of blockchains are conquering the blockchain trilemma: decentralization, security, and scalability. Still no single blockchain has nailed all three.

**Layer 2:**
Layer 2s are third-party integrations used in conjunction with layer ones to increase scalability and transactions per second (system throughput).

When you hear zero-knowledge rollups (zk rollups), side chains, or anything to do with speeding up transaction throughput, it’s likely layer 2.

**Layer 3:**
Layer 3 is the application layer. This is the UI that we as consumers actually interact with.
Jest + Typescript minus TS-Jest
Tags: typescript, productivity, webdev, javascript
Published: 2022-05-12 01:02:14

`ts-jest` is a popular package for `typescript` + `jest`.

But one issue that is bugging me recently is the uncovered lines stat is not correct, my test coverage dropped by 10+%.

After some googling, seem like folks also having the same issue, still nothing useful come up, no solution

With some troubleshooting, I found out that it was `ts-jest` that causing the issue

so I decided to use babel for compilation instead

install dependencies
```bash
npm i -D @babel/preset-env @babel/preset-typescript typescript jest
```

setup npm script
```json
"scripts": {
  "test": "jest",
}
```

create a `jest.config.js`
```ts
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */

module.exports = {
	testEnvironment: 'node',
	roots: ['<rootDir>/src'],
	testMatch: ['**/__tests__/**/*.+(ts|js)', '**/?(*.)+(spec|test).+(ts|js)'],
	transform: {
		'^.+\\.(js|ts)$': 'babel-jest',
	},
	moduleDirectories: ['node_modules', 'src'],
	collectCoverage: true,
	collectCoverageFrom: ['**/*.{js,ts}', '!**/*.d.ts'],
}

```

create a `babel.config.js`
```ts
module.exports = {
	presets: [
		'@babel/preset-typescript',
		[
			'@babel/preset-env',
			{
				targets: {
					node: 'current',
				},
			},
		],
	],
}

```

you don't need to install `babel-jest`, it comes with `jest`

finally `npm test` and boom, your 100% test coverage is back.
What's Your Fav Lang?
Tags: programming, computerscience, discuss
Published: 2022-05-12 00:32:53

What's your favourite programming language? Any particular reason like difficulty/learning curve, job prospect, tools, etc. 

For me personally, it's Rust, one reason is that I love all the tools integrated into Cargo, the language's syntax that just works like how I think, and the memory/thread safety in safe Rust. 

I always see myself using it in some way, even in my own programming language that's written in C, guess what going to make all of the documentation (html/man pages), exactly it's Rust!

Please feel free to comment your favourite language and some reasons of why.
How to Titleize a Sentence in JavaScript
Tags: javascript, tutorial
Published: 2022-05-12 00:28:56

---
title: How to Titleize a Sentence in JavaScript
published: true
description: How to Titleize a Sentence in JavaScript
tags: JavaScript, tutorial
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/onrpx0yz86ug72bon8ix.png
canonical_url: https://www.jenniferbland.com/how-to-titleize-a-sentence-in-javascript/
---
We recently ran into a scenario at work where we went through the process to redo all the email templates used in our application. There were over 300+ templates that we redesigned. After we finished somebody requested that we change the subject line to be title cased like you would in a print headline. Not wanting to manually change all 300+ templates, I wrote this quick function that handled the process automatically.

## What is Title Case

At first glance it might sound like we wanted the first letter of every word in a the subject line to be uppercase and the remainder of the word to be lowercase.  

Well that is almost correct. We don't want certain words to be capitalized. Words like `a`, `an` or `and` we wanted to remain lowercase.

Here is the quick function I created that handled this transition for us.

First I created an array of words that we wanted to remain lowercase in the subject of the email.

```
const small_words = ['a', 'an', 'and', 'as', 'at', 'but', 'by', 'for', 'if', 'in', 'into', 'nor', 'of', 'on', 'or', 'out', 'so', 'the', 'to', 'up', 'yet', 'and', 'as', 'at', 'but', 'by', 'for', 'if', 'in', 'into', 'nor', 'of', 'on', 'or', 'out', 'so', 'the', 'to', 'up', 'yet'];
```

Next I created a function that would have the text of the subject line passed into it. I would break this string into an array with each word in the subject an entry in the array. Now that I have an array I can loop over every word. If the word matches an entry in the `small_words` array then I convert it to lowercase. Otherwise I capitalize the first letter of the word and lowercase the remainder of the word.

There is one exception that I have to account for and that is the first letter in the subject text. Regardless of what is the first word I want it to have the first letter capitalized.

With those requirements, here is my function:

```
const titleize = (title) => {
  return title.split(' ').map((word, index) => {
    if (index !== 0 && small_words.includes(word)) {
      return word.toLowerCase();
    } else {
      return word[0].toUpperCase() + word.slice(1).toLowerCase();
    }
  }).join(' ');
}
```

To test out the function I added 3 titles and console.log the new title.

```
console.log(titleize('notes on a scandal'));  // Notes on a Scandal
console.log(titleize('a good man is hard to find')); // A Good Man Is Hard to Find
console.log(titleize('midnight in the garden of good and evil')); // Midnight in the Garden of Good and Evil
```

You will see the output for each test of a subject line.

If you ever need to titleize a string based on print title formatting, you can use this function. All you would need to do is edit the `small_words` array to include your list of words to remain lowercase.
How to Fix error with openai in your nodeJS app
Tags: javascript
Published: 2022-05-12 00:04:53

I was trying out openAI's api when I came across this error.

![cannot import module](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pr986v4obn6wcu23yluj.png)

It was quite annoying. To solve it, you add the `"type": "module"` to your package.json file.

If you don't have a package.json file, use `npm init -y"` to create one.

With that, you should have this:
![type module](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ggvolljuzmhpmlbedobu.png)
 
which should solve it.

but...something else might come up. Since you need your API key in a .env file to access the api, you would need to import the dotenv package. 

after installing with npm or yarn, I used the require keyword to import it:

`require('dotenv').config();`

For some reason, that seems to throw another error:

![cannot use require](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pnrqm4atk09hn1j64n9s.png)

It was very frustrating and stack overflow didn't seem to have a direct answer.

To solve it, change require to a normal import statement, 

in this case it would be, `import dotenv from 'dotenv/config'`

the final code looks like this:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kx0sh6bkpt77xdx9qptk.png)
 

![everything works](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tdnm1o1dskcw0a48uwia.png)

with that, you are done.
Rebasing All Dependabot Pull Requests
Tags: github, dependabot, gh
Published: 2022-05-12 17:33:36

---
title: Rebasing All Dependabot Pull Requests
published: true
date: 2022-05-12 00:00:00 UTC
tags: 
- github
- dependabot
- gh
canonical_url: https://justin.poehnelt.com/posts/rebase-all-dependabot-pull-requests/
---

The [GitHub cli tool](https://cli.github.com/) `gh` now has a search feature! I recently had a use case requiring DependaBot to rebase all pull requests across the GitHub organization repositories.

The following shell command did the trick by piping the output of `gh search prs` to `gh pr comment`:

```
gh search prs \
  --owner googlemaps \ # replace with GitHub owner
  --state open \
  --label dependencies \
  --limit 200 \
  --json "url" --jq ".[] | .url" \
| xargs -n 1 -I{} \
  gh pr comment -b "@dependabot rebase" {}
```
Automatically Approving and Merging Dependabot Pull Requests
Tags: github, dependabot
Published: 2022-05-16 15:49:29

---
title: Automatically Approving and Merging Dependabot Pull Requests
published: true
date: 2022-05-12 00:00:00 UTC
tags: github, dependabot
canonical_url: https://justin.poehnelt.com/posts/automatically-approving-and-merging-dependabot-pull-requests/
---

I’ve recently been using a combination of GitHub apps to automate the approval and merging of Dependabot pull requests, but wanted to simplify this into a GitHub workflow, using branch protection and GitHub’s auto merge feature.

The GitHub workflow looks something like:

```
name: Dependabot
on: pull_request

permissions:
  contents: write

jobs:
  dependabot:
    runs-on: ubuntu-latest
    if: ${{ github.actor == 'dependabot[bot]' }}
    env:
      PR_URL: ${{github.event.pull_request.html_url}}
      GITHUB_TOKEN: ${{secrets.MY_PA_TOKEN}}
    steps:
      - name: approve
        run: gh pr review --approve "$PR_URL"
      - name: merge
        run: gh pr merge --auto --squash --delete-branch "$PR_URL"
```

❗ **Warning** : I wouldn’t implement this without branch protection and required status checks.

And it works! 🎉

The pull request now looks like the following:

[![Automating DependaBot pull request approval and merging](https://justin.poehnelt.com/images/automating-dependabot-pull-requests-4438xHy3KC-200.jpeg)](https://justin.poehnelt.com/images/automating-dependabot-pull-requests-4438xHy3KC-600.jpeg)

Automating DependaBot pull request approval and merging

Once I had this implemented and pushed to all the repositories, I just need to [tell Dependabot to rebase all pull requests](https://justin.poehnelt.com/posts/rebase-all-dependabot-pull-requests/).

It would be fairly easy to add a check for labels on the pull request, and only `gh approve` if the label was present, but I really didn’t have a use case for this right now because I feel confident in the required status checks.