teleren/devto huggingface dataset:
Laravel - Automate Database Backup
Tags: backup, laravelbackup, backupmanagement, automaticbackups
Published: 2020-05-14 15:08:42

---
title: Laravel - Automate Database Backup
published: false
description: 
tags: Backup, Laravel Backup, Backup Management, Automatic Backups
published: true
cover_image: https://images.unsplash.com/photo-1518547606470-00ac2ae882af?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&crop=bottom&h=600&w=450&q=80
---

Backup your database and automate the process using this simple method. 

If you want to watch me doing it then below is the tutorial video for the same.
{% youtube 11ECvHYMfRY %}


Let’s Start!

Pull in the package “laravel-backup” using composer.

>composer require spatie/laravel-backup

Publish config file using this command.

>php artisan vendor:publish --provider="Spatie\Backup\BackupServiceProvider"

Open backup.php inside config folder.

There are a bunch of configuration settings here:

In the source, Write your file path or directory that you want to include or exclude from backup.

![](https://dev-to-uploads.s3.amazonaws.com/i/99ff66n3zmodd6t05x0y.png)

Write the database connection name which you want to backup.

![](https://dev-to-uploads.s3.amazonaws.com/i/tdvf8yn1qkr8wqvbygit.png)

Within destination, Write disk name on which you want to store backups. 

![](https://dev-to-uploads.s3.amazonaws.com/i/h9lk5iavkmsa6c9uc01k.png)

If you want to store them in AWS S3 then you can define your disk in filesystems.php. 

For using S3, pull in the package "league/flysystem-aws-s3-v3"

>composer require "league/flysystem-aws-s3-v3"

Write your S3 access credentials in .env file.

Select the notifications that you want to receive and Write your email id on which you want to receive your notification.

![](https://dev-to-uploads.s3.amazonaws.com/i/lg6i6rxkbjh83deqoohl.png)

You can even get these notification on slack as well. 

![](https://dev-to-uploads.s3.amazonaws.com/i/clk622vavi3yy7huwwld.png)

Configure email service if you haven’t from mail.php and write mail service credentials in .env file.

Set the no of days you want your backups to kept and deleted automatically after a certain time period.

![](https://dev-to-uploads.s3.amazonaws.com/i/fp1cmkvu1chw6b5hgakx.png)

Schedule these commands using Laravel Scheduler. For that Open app/Console/Kernel.php and write these inside schedule function.

>$schedule->command('backup:clean')->daily()->at('01:00');
>$schedule->command('backup:run')->daily()->at('02:00');

Set your Laravel Scheduler to run every minute using either crontab or supervisor. 

For crontab, it should look something like this.

```
* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1
```

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/hopjplyq1p74b6w18buy.png)

That's It!

All your backups now will be stored and you will be notified on email or slack and old backups will also be deleted automatically as configured by you in backup.php.
Daily Challenge #243 - Redacted!
Tags: challenge
Published: 2020-05-14 15:08:17

---
title: Daily Challenge #243 - Redacted!
published: true
series: Daily Challenge
description: Somewhere in a Pentagon basement, we're working on un-redacting files. 
tags: challenge
---
The first document has parts redacted, and the other one doesn't. But the clean document might be a fake! You need to compare the two documents and decide if it is possible they are the same or not. Return `true` if the two documents are possibly the same. Return `false` otherwise.

**Rules**
- Each document is made of any visible characters, spaces, punctuation, and newlines \n
- Any character might be redacted (except `\n`)
- The redaction character is ` X`
- The redacted document is always the first one

####Example
doc1 = "TOP SECRET:\nThe missile launch code for Sunday XXXXXXXXXX is:\nXXXXXXXXXXXXXXXXX"
doc2 = "TOP SECRET:\nThe missile launch code for Sunday 5th August is:\n7-ZERO-8X-ALPHA-1"
Documents look the same, therefore `true`.

####Tests
doc1 = "The name of the mole is Professor XXXXX"
doc2 = "The name of the mole is Professor Dinglemouse"

doc1 = "XXXXXXXX XXXXXXX XXXXXXXXXXXXXXXXXXX\nXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXX XXXXXXXXXXXXX XXXXX"
doc2 = "Area-51. Medical Report. 23/Oct/1969\nE.T. subject 4 was given an asprin after reporting sick for duty today"

Good luck!

***
_This [challenge](https://www.codewars.com/kata/5b662d286d0db722bd000013) comes from dinglemouse on CodeWars. Thank you to [CodeWars](<https://codewars.com/>), who has licensed redistribution of this challenge under the [2-Clause BSD License](<https://opensource.org/licenses/BSD-2-Clause>)!_

_Want to propose a challenge idea for a future post?  Email **yo+challenge@dev.to** with your suggestions!_
How I Discovered the Android Studio Colour Picker Tool.
Tags: todayilearned
Published: 2020-05-14 15:06:36

Hey everyone, I'd like to share something I recently discovered. You may have come across it before or probably, like me you didn't know it existed.

Yes! now to the (not-so) big discovery, it was a normal day of work on Android Studio I was getting frustrated with choosing a colour for the project I was working on and in a moment of brilliance I discovered the colour picker!

<img src="https://dev-to-uploads.s3.amazonaws.com/i/zoz761044e5ac95cejpm.png" width="450" />

Now you're wondering how did this show up, well simple click on the small square colour on the left in your colors.xml file or anywhere you store your colour resource and ta da! the colour picker dialog shows up. One cool thing to note is once you've selected a colour, Android Studio automatically replaces your new colour selection in `HEX` form which is of course just exactly the format we need.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/iz0nviorp8t2yjtl5m6o.png)

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/rv1xqbtcuf0pc9dkd75z.png)

Well this is looking great! We can also do few things on the colour picker dialog, I am just gonna run through the few I noticed.

<ul>
<li>You can choose the the level of tint (Material 50 - Material 900) and also from the A-Series (Material A100, A200, A400 & A700).</li>

<li>If Material colours do not do it for you and you are more of an <code>ARGB</code> or <code>RGB</code> person, well Android Studio got you covered.</li>

<li>You can also manually edit the colour in <code>HEX</code> and see how it looks like before saving.</li>

<li>And the old fashioned way of dragging the colour picker is also for your choosing.</li>
</ul>

And guess what, that's not all. In your other resource files where you reference colours like your `styles.xml` file or even in any of your layout files, you can choose any colour or even a colour resource you've previously created.

If you found this really helpful, why not share and show some love!

Till we see again :wave:.
Day 17 of #100DaysOfCode: apply structured data for AJAX data to improve SEO
Tags: 100daysofcode, seo, marketing, webdev
Published: 2020-05-14 15:04:17

## Introduction
Add structure data to the website is a way to improve SEO. This article is a note for applying structured data for AJAX.

## 1. How to add structure to your website?
* First, visit webmasters makeup helper (https://www.google.com/webmasters/markup-helper/). Choose the type of the website and put the URL of the website.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/sko2mh5jcfsbdvun2o0g.png)
* Then you can label fields like name, date, tile, etc on the website manually. This tool can convert labels to MicroData or JSON-LD format
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/x99a1yvfxfmssjjbld68.png)
* For AJAX, I thought using JSON-LD is a good choice. Google robot won't miss the structured data even though we have to retrieve data from the server.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/v81eeh8x6m5xm4yma7rn.png)

## 2. How to add JSON-JD in JavaScript?  
* You can append a Script node in $(document).ready
```javascript
$(document).ready(function(){
   var el = document.createElement('script');
   el.type = 'application/ld+json';
   ...
   list = []
   data.forEach(ele => {
            var t = { 
                "@context": "http://schema.org",  
                "@type": "Article", 
                "name": ele.title,
                "mainEntityOfPage": {
                    "@type": "WebPage",
                    "@id": 
                 },
                "author": {
                    "@type": "Person",
                    "name": ele.name
                },
                "datePublished": ele.time,
                "dateModified": ele.date,
                "url": ele.url,
                "image": ele.image,
                "publisher": {
                    "@type": "Organization",
                    "name": ele.name,
                    "logo": {
                        "@type": "ImageObject",
                        "url":
                    }
                },
                "headline": ele.title
            }
            list.push(t)
        });
        el.text = JSON.stringify(list);
        document.querySelector('head').appendChild(el);
});
```

## 3. How to verify the structure data we added?
* Visit Structured Data Testing Tool () and put the URL
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/rv1dwls92i3ouur0vxfo.png)

* This tool will show you if there are any warnings or errors
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/iukhapcectis25ns5kb6.png)

That's it!


## Articles
There are some of my articles. Feel free to check if you like! 
* My blog-posts for software developing: https://medium.com/a-layman
* My web resume: https://jenhsuan.github.io/ALayman/cover.html
* Facebook page: https://www.facebook.com/imalayman
Docker+Deno: Containerize a Deno hello world server
Tags: docker, deno, 100daysofcode, typescript
Published: 2020-05-14 14:59:01

Deno is the buzzword of the moment, and we still don't know how it will end. 

Honestly, I am very fond of node, but I was intrigued, so I created a hello world server with deno, and immediately I tried to containerize it with docker.

Warning!
this example is based on this docker image https://hub.docker.com/r/hayd/deno

Which is not an official deno repository

Github Repository: https://github.com/FrancescoXX/deno-docker

Please note the this the first time I use deno, so it is something pretty new also to me

# Short version

you can just clone the repository
```
git clone https://github.com/FrancescoXX/deno-docker
```
navigate to the folder where the docker-compose.yml is located, and run
```
docker-compose up --build
```
Done!
___

# Long version

If you want to follow along, and you use Visual Studio Code, I suggest you install this extension:

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/2wuaa3q9h7t683gymykz.png)

First of all, we create a file for the deno dependencies, called deps.ts.

In Deno, we import third part code directly from urls, no node_modules or package.json is needed

```typescript
export { serve } from "https://deno.land/std@0.50.0/http/server.ts";
```

Then, we create the main.ts file, and import the deps.ts file as a regular ts file

We also define a very simple Server, based on the official example
```typescript
import { serve } from "./deps.ts";

const PORT = 8000;

const s = serve({ port: 8000 });

const body = new TextEncoder().encode("Hello World\n");

console.log(`Server started on port ${PORT}`);
for await (const req of s) {
  req.respond({ body });
}
```

then, we create a very simple Dockerfile, using the hayd/alpine-deno:1.0.0 image
```dockerfile
FROM hayd/alpine-deno:1.0.0

EXPOSE 8000

WORKDIR /app

USER deno

COPY deps.ts .
RUN deno cache deps.ts

COPY . .
RUN deno cache main.ts

CMD ["run", "--allow-net", "main.ts"]
```
And last, we create a very simple docker-compose.yml file, which is no needed for now, but it could be useful in the future, for example, if we start using a database or some other services

We define port 8000 as both inner and outer one and a default network
```yaml
version: "3.7"

services:
  deno:
    image: "deno-docker:0.0.1"
    build: .
    ports:
      - "8000:8000"
    networks: 
      - deno
    
networks:
  deno: {}
```
from the folder where the docker-compose.yml file is located, we build the image:
```
docker-compose build
```

And finally, we can launch the service with this command
```
docker-compose up deno
```

visit localhost:8000 from a browser

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/3lpdyngh80ce7a18ageb.png)

That is not the best and most useful server, but it is intended as a point to start from

Also, using docker, we didn't need to install deno on the machine

Please leave a comment if you want more articles about this topic

Github Repository: Github Repository: https://github.com/FrancescoXX/deno-docker
6 new challenges
Tags: javascript, computerscience
Published: 2020-05-14 14:51:15

Ranked mode just got 6 new challenges, 4 hard and 2 medium ones.
I think the most interesting one is the implementation of an LRU (least recently used) cache structure. There are also 3 challenges related to the reverse Polish notation, which is a must-know for software engineers.

Below is a mysterious function, can you solve it?
```JS
function singleNumber(nums) {
  let ret = 0;
  for (let index = 0; index < nums.length; index++) {
    const element = nums[index];
    ret = ret ^ element;
  }
  return ret;
}

let A = singleNumber([2,3,4,3,2,5,1,5]);
// A = ?
```
POST to Database Without Routing to a New Page
Tags: express, mongodb, database
Published: 2020-05-14 14:49:25

The vast majority of online Express app tutorials show how to POST data to the database, but they often route to a new page once the data is submitted. This is not always necessary or desirable.

In the example below, I use the 204 No Content HTTP response code in my Express app.post function in order to send data to the database without changing or reloading the webpage. The MDN [204 No Content documentation](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/204) states:
"The HTTP 204 No Content success status response code indicates that the request has succeeded, but that the client doesn't need to go away from its current page."

In the example code below, the HTML form takes in two numbers, "num" and "numExp". Once the client submits the form data, these number values are formatted in the mongoose schema and passed into the app.post function before it is stored in the database. Nothing changes on the client browser during this process. And sometimes, that's what you want.

```
var fooSchema = new mongoose.Schema({
  num: Number,
  numExp: Number,
});


var fooBar = mongoose.model("fooBar", fooSchema);


app.post("/new", (req, res) => {
  var myData = new fooBar(req.body);
  myData
    .save()
    .then((item) => {
      res.status(204).send();
    })
    .catch((err) => {
      res.status(400).send("unable to save to database");
    });
});
```

Your HTML form should contain the following information:
```
 <form method="post" action="/new" id="cFactorForm" class="form">
```

For more information on HTTP response codes, visit the [HTTP Status Codes reference](https://httpstatuses.com/) by runscope.
Quitting my career at 40…
Tags: career, beginners, webdev
Published: 2020-05-14 14:39:30

**How to become a web developer after 15 years in a different industry.**

This is the first in a series of blog posts from me about my journey from quitting my job with ZERO coding experience to employed web developer. This one will be more personal, looking at why I’m doing this, later posts will be focused on my code and projects.

**Who am I?**

Hey, I’m Ian. I live out on the east coast in the UK. The last 15 years of my professional life have been spent working in various leadership positions, building happy and high performing teams, for a well known UK wine retailer.  And it’s been great, surrounded by talented people, immersed in a great culture and selling a product that you never get bored off. 

But. 

I had an itch that I needed to scratch. I wanted to explore something new, something that I loved, something that gave me even more.

**Why web development?**

It was time to start scratching.

I’m a super-geek at heart, I love all things tech and spend far too much money on gear for myself and my house. I die a little inside when I think about the amount I’ve spent on Sonos and Philips Hue lights alone…
I’ve also always been fascinated by the tech industry and the impact it has on our everyday lives. Who wouldn’t be excited about an industry that always promises the next big thing?

So I want to spend more of my working life surrounded by this stuff, I want to spend it building and creating tangible ‘things’ that bring joy to other people. And I guess there’s no better way to do that than as a web developer.  

And that’s where the big decision came in. After lots of debate, loads of pros and cons lists being written, LOTS of wine being drunk and a final push from my wonderful partner, the time came to quit my job. 

I’ve never been so terrified, was I about to “chuck it all away” to chase a pipe dream? I finally got my resignation email sent after the third pint in the pub. 

**What have I learnt so far?**

And here I am.  A few months into my course and I can’t believe how much we’ve covered.  We’ve flown through HTML, CSS and Javascript, I’ve built websites and fully functional apps.

I’ve also learnt that learning again more than 15 years after university isn’t easy. I’ve had to plan my time well, review the work I’ve done, spend time coding with other people and be relentless.

**What’s next?**

React starts next, then more coding, then more building.

**So how do you become a web developer after 15 years doing something else?**

I'm not there yet but so far it's been:

- Coding everyday. 👨‍💻
- Read something new everyday. 📖
- Ask for help. 🚑
- Ask for feedback. 🗣
- Keep building. 🏗️
Unity in an Unreal 5 World
Tags: unreal, unity3d, gamedev
Published: 2020-05-14 14:16:24

We recently saw the Unreal 5 demo and for those of us that use Unity as our primary dev environment, it was pretty cool. Now, as a Unity user who does have Unreal installed to test it out, I wasn't too surprised or hyped by Unreal 5's offerings. While I haven't researched much into Unreal 5's features, I'm guessing that we'll still see more issues pop up dealing with storage sizes and optimization for lower-end hardware. As a dev who focuses on building games for lower to medium PC specs, Unreal 5 isn't (imo) geared towards me. AAA companies will love it, Indie MMO creators will love it, and I'll still be using Unity.

That being said, Unity is becoming outdated. The CEO loves throwing out the statistics of Unity's use, but what's after stats? Broken, deprecated features. Almost all the useful features are in "preview" and do not work well with older versions of Unity. The visual scripting solution changed to DOTS, while they bought BOLT to satisfy users preparing to jump ship. I prefer non-visual scripting. I can write C# well enough to build games, but cannot write C++, which keeps me tethered to Unity. I think Unity Technologies knows that C# devs are mostly stuck with them. 

I like Unity quite a lot, but their practices of placing paid assets on the store, their learning center locked behind a subscription, and of pointing to assets on the store instead of implementing common assets into the engine has started to tear down the initial market. They claim to democratize game dev, but Epic is pushing ahead of Unity with Unreal 5. 

While I'm not going to jump ship just yet, I think I may start to learn C++ after I get a better understanding of C# in a desktop environment (as my C# knowledge is limited to Unity). Hopefully, Unity Technologies fixes their engine and improves it to have common core features alongside Unreal. Until then, I think I'll start preparing my lifeboat.

And really, have you tried making multiplayer games in Unity? It's not simple, and Unity doesn't help by deprecating their net code.
#TIL how to move uncommitted code from one git repo to another
Tags: git, todayilearned
Published: 2020-05-14 13:56:55

## TL;DR:
in the source repo, do:
```
git stash
git stash show -p > /tmp/stash.patch
git stash drop
```
in the target repo, do:
```
git apply /tmp/stash.patch
```

:tada: WIN :tada:

## The full story:

I often have two clones of work repos on my machines:
- one I'm working in
- one where I can check out reviews or do fixes for ongoing PRs without disrupting my main working repo

Today, I started doing some work in the secondary clone and realised that I needed to move that work over to the primary one. I hadn't committed, and I figured that there was a way to do this with git's `stash` command, but I wasn't sure. So I googled a bit to get to the above, based on [a stackoverflow post](https://stackoverflow.com/questions/3973034/export-a-stash-to-another-computer).

Let's go through what's happening:

### In the source repo

- `git stash` puts all your uncommitted changes in the [stash](https://www.git-scm.com/docs/git-stash), which is a stack-based storage for changesets.
- `git stash show -p` shows the latest stashed changeset in patch format. Here I pipe it into a file in `/tmp`, but you could pipe it anywhere. Without the `-p`, `git stash show` will give you similar information as what you'd see with `git log --stat`: showing a condensed version of the changes per file. So don't forget that `-p`!
- `git stash drop` drops the latest stash -- you won't be needing it, since you have a patch file, but if you're feeling nervous, don't: [there's a way to get it back](https://stackoverflow.com/questions/89332/how-to-recover-a-dropped-stash-in-git)

### In the target repo
- `git apply /tmp/stash.patch` applies the patchset to your current repository

## Wrapping up
git can be challenging and confusing when you're new to it... even when you're not-so-new to it :laughing: but the one thing I like to remind people is that it's quite difficult to _permanently_ lose information in git. Well, except if you `git reset --hard`, then you can kiss those uncommitted changes good-bye! But most of the time, the reflog or fsck can find pieces you think are gone forever. Also, git probably does a lot more than you might expect, so try googling what you want to do before resorting to a manual plan or panicking -- chances are someone has had the same problem before and found a solution!
React Expense Tracker
Tags: react, javascript, frontend, webdev
Published: 2020-05-14 13:55:21

Hi all!

Last week was really fun. I've been coding some stuff and had more practice with React. (I work with Vue and Angular, mostly) and I have to say I really love React Hooks!

This time I want to share with you this little *Expense Tracker App* and I hope some people will find it useful to learn.

Some things you will find:

-React Hooks
-Context API
-Themming (Light and Dark mode)
-Change UI language using React n18next.
-Firebase CRUD
-Firebase Authentication using ReactFire.
-Data visualization with Charts JS.

Demo --> https://react-exp-tracker.netlify.app/
Repo --> https://github.com/AlexSegen/react-expense-tracker


Any feedback is very appreciated.