teleren/devto huggingface dataset:
[Java] Apply Background Image to PowerPoint Slides
Tags: java, powerpoint, background
Published: 2020-08-13 08:07:21

When manipulating a Powerpoint document, the background is very important. A unified background image can make the whole document looks cleaner and more attractive. This article will introduce how to apply background image to all slides in a PowerPoint document by using Free Spire.Presentation for Java.

**Installation**
**Method 1:** Download the [Free Spire.Presentation for Java](https://www.e-iceblue.com/Download/presentation-for-java-free.html) and unzip it. Then add the Spire.Presentation.jar file to your project as dependency.

**Method 2:** You can also add the jar dependency to maven project by adding the following configurations to the pom.xml.

```java
<repositories>
        <repository>
            <id>com.e-iceblue</id>
            <name>e-iceblue</name>
            <url>http://repo.e-iceblue.com/nexus/content/groups/public/</url>
        </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>e-iceblue</groupId>
        <artifactId>spire.presentation.free</artifactId>
        <version>2.6.1</version>
    </dependency>
</dependencies>
```

**Java Code**

```java
import com.spire.presentation.FileFormat;
import com.spire.presentation.Presentation;
import com.spire.presentation.SlideBackground;
import com.spire.presentation.drawing.*;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.FileInputStream;

public class AppplyBgToAllSlides {

    public static void main(String[] args) throws Exception {

        //load a PowerPoint file
        Presentation presentation = new Presentation();
        presentation.loadFromFile("test1.pptx");

        //get the image data
        BufferedImage bufferedImage = ImageIO.read(new FileInputStream("background.jpg"));
        IImageData imageData = presentation.getImages().append(bufferedImage);

        //loop through the slides
        for (int i = 0; i < presentation.getSlides().getCount() ; i++) {

            //apply the image to the specific slide as background
            SlideBackground background = presentation.getSlides().get(i).getSlideBackground();
            background.setType(BackgroundType.CUSTOM);
            background.getFill().setFillType(FillFormatType.PICTURE);
            background.getFill().getPictureFill().setFillType(PictureFillType.STRETCH);
            background.getFill().getPictureFill().getPicture().setEmbedImage(imageData);
        }

        //save the file
        presentation.saveToFile("output/BackgroundImage.pptx", FileFormat.PPTX_2013);
        presentation.dispose();
    }
}
```

![](https://dev-to-uploads.s3.amazonaws.com/i/svopaejd6j14nwcfbaml.jpg)
First step as an iOS AR developers
Published: 2020-08-13 08:02:58

A very gentle humongous crash. 
The first hour of me as an AR iOS app developer.
 
1/ Learn how to right click the pad mouse on Mac.
2/ Learn how to open a terminal to install cocoapods.
3/ Dance around the room with the computer overhead after installing: XCode >= 11, Cocoapods >= 1.9.1 (can be installed via brew),  Unity3D >= 2019.3.14f1.

Yasou! 
(chose the Greek word for goodbye, as I felt quite bacchanalian)
Converting a django CMS plugin to a different model
Tags: django, djangocms
Published: 2020-08-13 08:01:26

Once in a while you might find yourself in the situation in which a django CMS plugin you are using in a project is no longer supported or no longer suited for your goals.
But then, you have hundreds (or thousands) of instances of the old plugin and you need a quick way to migrate all the data to a new one.
Luckily, it's possible to achieve this using a rather simple data migration.

Sample code used referenced below: https://gist.github.com/yakky/31466588da712e25e1f2c200d56d3776

## How it works

In order to have a successful migration we must achieve the following:
- keep the plugins tree consistent
- keep the reference to the plugin valid (eg: the tag embedded in text fields when the plugin is embeddable in a text field)
- keep custom data intact (at least the ones supported by the new plugin model)

To achieve this we can use the fact that Django models instances are python classes disconnected from the database until an explicit database update is run.

### deceiving Django ORM and the database

So the first step (lines 9-10) is to create an instance of the new plugin class *without* saving it to the database, then set the id of the new plugin to the one that's being removed; at the end (21-22) we delete the old instance before saving the new one to free any constraint on unique fields.
By keeping the same id, plugin instances embedded in text plugins (whose reference is kept by hardcoding the id in the text body) are moved to the new model.

### Migrating tree data

Django CMS plugins are stored in the database using the materialized path algorithm by Django-treebeard, and the plugins hierarchy information is stored in a few fields which neees to be copied verbatim (lines 11-18). This bypass the tree algorithm and we effectively replace a single node in the tree without affecting the tree balancement or triggering the automatic tree rebalance.

### Migrating custom data

We now can save the custom model data to the new one. To achieve this we can add the lists of assignments from the field on the old plugin to the one the new plugin: `new_plugin.field_name = old_plugin.field_name`. If the plugin has any many to many relationship we can copy those as well, after saving our new plugin, using `new_plugin.many2many.set(old_plugin.many2many.all())`.

## Closing

The above snippet has still room for improvements (like using `_meta.get_fields` to copy the fields data without writing every single field, but should provide you a good starting point to customise them your needs.
Create your own card with Google
Tags: tutorial, google, webdev, personalcard
Published: 2020-08-13 07:56:28

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/qmnjl877qj4251e5kakk.jpg)<br>
**Google India** introduced the people's card on Google Search.

So, now instead of showing your business card just ask them to search you on Google. How cool is that, no?

*To get your own people card you just need an android or IOS device. Remember, the feature is not available on the desktop.*

**STEPS** to create your own people card:
<br>
* Log in to your Google account on your device and search for "add me to search" OR just type in your name in the search.
*'Get Started' will appear for you, here it's 'edit' as I've already created the card. Tap on 'Get Started'!*
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/u3bxpzzoowo7mrv53m6q.jpeg)
<br>

* Fill all your details and socials and tap 'Preview' to review the card last time.
*Be careful will uploading phone number and Email, it'll be shown publicly.*
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/irj0kwyhfqt7m4zaciol.jpeg)
<br>

* Tap on 'Save' and that's it.
Congratulation!, Now you have your own card on *Google.*
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/4ijgk59lzrqiej9glj69.jpeg)
<br>

Thanks for reading :)
Connect with me through: [Linkedin](https://www.linkedin.com/in/swastika-yadav-12a605171/)  [Twitter](https://twitter.com/SwastikaYadav15)
Summer is blazing let's Howl
Tags: watercooler, 100daysofcode, howl, csharp
Published: 2020-08-13 07:43:01

Scantily covered CLIs are upon us. I have been hinting at Howl, a new way to C# and .dotnet. 

With 100 days of code upon us I thought hey it'd be a shame if devs can't pick this up and try it out.

If all goes fine? pre-👀 ⬆️ today 🔥.

## What is Howl?

Howl is a symbolic notation engine. Now used with C# to write beautiful code:

```
‒̥ ㄹ ⨕ % (ㄹ x, Map y) → Rev(x, y.nits);

‒̥ ᆩ[] ⨕ !(Map m) → (‖ x ∈ m.rules ¿ !x ፥ x.a[0])৴;
```

Two lines here above define operator overloads; now this 〜 `(‖ x ∈ m.rules ¿ !x ፥ x.a[0])৴` is a Linq expression (yes, `◺` and `◿` are a thing).

The whimsy `৴` is synonymous with `.ToArray()`

Howl does not require a special keyboard. An advanced HCI (think mind-reading) handles all of this gracefully (and syntax highlighting too) via snippets. Bonus you can learn the notation as you type good ol' C# code.

Nor do you *have* to adopt each and every notation. Similar to ice cream, you might leave some 🍨.

Scanty coverage or not (actually *slightly* over 0.97%), Howl has been a hard month in the works with some of the ideas going... over 20 years, maybe?

CLI itself very, very fresh. If you are looking for a fun challenge this summer, I'll share a build today... probably. 

```
+ howl
(•ᴗ•)ノ Howl CLI v0.0 〜 Usage:
howl run                    - Build and run
howl export SRC_DIR DST_DIR - Export Howl scripts to C#
howl import SRC_DIR DST_DIR - Convert C# scripts to Howl
🍙 
```

(´• ω •`)
Dart & Flutter Easy Wins 8-14
Tags: flutter, dart
Published: 2020-08-13 07:42:11

---
title: Dart & Flutter Easy Wins 8-14
description: Easy ways to improve your Dart & Flutter code. Published weekly.
published: true
tags: flutter, dart
canonical_url: https://codewithandrea.com/tips/dart-flutter-easy-wins-8-14/
series: Dart & Flutter Easy Wins
---

I recently started a series of [daily tweets](https://twitter.com/search?q=from%3Abiz84%20Easy%20Win&src=typed_query&f=live) about easy ways to improve your Dart & Flutter code. I called this **Easy Wins**. 

To make these easier to find, I'm sharing 7 tips every week here.


## 8. Use a `finally` block for code that should be executed *both* on success and failure.

![Use a `finally` block for code that should be executed **both** on success and failure.](https://codewithandrea.com/tips/2020-08-13-dart-flutter-easy-wins-8-14/images/008.try-catch-finally.png)

## 9. Implement `toString()` in your classes to improve the debugging experience.

![Implement `toString()` in your classes to improve the debugging experience.](https://codewithandrea.com/tips/2020-08-13-dart-flutter-easy-wins-8-14/images/009.implement-toString.png)

## 10. Use the if-null operator to provide a fallback for null values.

![Use the if-null operator to provide a fallback for null values.](https://codewithandrea.com/tips/2020-08-13-dart-flutter-easy-wins-8-14/images/010.if-null-operator.png)

## 11. Use multi-line strings to represent large blocks of text.

![Use multi-line strings to represent large blocks of text.](https://codewithandrea.com/tips/2020-08-13-dart-flutter-easy-wins-8-14/images/011.multi-line-strings.png)

## 12. String literals can use 'single' or "double" quotes as delimiters. Escape special characters with a backslash (\), or use raw strings.

![String literals can use single or double quotes as delimiters. Escape special characters with a backslash (\), or use raw strings.](https://codewithandrea.com/tips/2020-08-13-dart-flutter-easy-wins-8-14/images/012.string-double-quotes-raw.png)

## 13. Use triple slashes to generate documentation comments.

![Use triple slashes to generate documentation comments.](https://codewithandrea.com/tips/2020-08-13-dart-flutter-easy-wins-8-14/images/013-triple-comments.png)

## 14. Want to auto-generate hashCode, == and toString() implementations for your classes? Use the Equatable package:

- [Equatable package](https://pub.dev/packages/equatable)

![Want to auto-generate hashCode, == and toString() implementations for your classes? Use the Equatable package:](https://codewithandrea.com/tips/2020-08-13-dart-flutter-easy-wins-8-14/images/014.equatable.png)


More tips coming next week. [Subscribe via RSS](https://codewithandrea.com/rss.xml) for updates!

Happy coding!
What would you do if you had a Time Machine?
Tags: watercooler, discuss
Published: 2020-08-13 07:32:57

If I had a Time Machine then I would probably won't ever use it because it will affect my present if I tried to travel and altered my past and future. What I have now, I may not have now as you have to give sacrifices to achieve in life and you learn lessons when you make mistakes and improve further. At least that's my way of thinking.

So if you had a time machine then what you would do?
#100DaysOfCode | Day 17, 18(Are You committed Yourself?)
Tags: 100daysofcode, python, beginners, challenge
Published: 2020-08-13 07:19:23

▄█ █▀█ █▀█ █▀▄ ▄▀█ █▄█ █▀ █▀█ █▀▀ █▀▀ █▀█ █▀▄ █▀▀
░█ █▄█ █▄█ █▄▀ █▀█ ░█░ ▄█ █▄█ █▀░ █▄▄ █▄█ █▄▀ ██▄
Hey everyone
Two days ago was day 17 and 18 of __100DaysOfCode challenge__!
I created a snake game in the last week and learned a lot out of it.
It was so fun to make your own game to play with it. 
Last day I decided to start a new project to level up my coding skills.
My new project would be __Web Scraping__, using selenium.
I think today going to post second part of snake game.


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


Keep Moving Forward __ツ__

Enjoy Your Journey 👊

Code with __💛__

__🅑🅐🅝🅙🅘__
Secure code review: Part 4 - Enforce secure authentication
Tags: security, codequality, codenewbie
Published: 2020-08-13 07:01:03

Code reviews are hard to do well. Particularly when you’re not entirely sure about the errors you should be looking for! The DevSecOps approach pushes security testing left so that vulnerabilities can be found and fixed earlier, in the design, development, or CI/CD stages of the workflow. It’s always a good idea to check for security issues in code that you review. In case you don’t know what to look for, check out this series to give you pointers for your next code reviews!

## Enforce secure authentication
Authentication verifies that a user, service, or entity (internal or external) is who they say they are. This could be as simple as a user passing you their credentials, or a server providing you with its TLS certificate to validate it is indeed the server it claims to be. Authentication doesn’t tell you what the user or service is allowed to do, but rather that they are indeed that user or service. Let’s cover a few authentication best practices you should make note of:

### Assume they’re not who they say they are.
You should work under the principle that they’re not who they say they are until they have provided the credentials to prove it. Assuming the user or service shouldn’t have access to your data is, of course, the safest way of behaving. Make sure your code reflects that.

### Enforce password complexity
In the case of users, consider being more lenient, in terms of the usernames, particularly when using email addresses. For instance, there’s little value in distinguishing between Patch@snyk.io and patch@snyk.io, whereas it’s important to enforce password complexity (at least 1 uppercase character, 1 lowercase character (a-z), 1 digit (0-9) and 1 special character) and length (NIST SP800-132). I understand, it’s difficult to remember all those random — or not, long, and complicated passwords. But, come on! It’s the year 2020 and password managers are here to save you!

### Re-authenticate before sensitive operations
Asking users for their credentials — before transferring monies, or performing sensitive actions — mitigates potential Cross-Site request forgery (CSRF) and session hijacking attacks. An attacker might perform these sensitive tasks without ever having provided the user’s credentials. This security measure, while inconvenient to your users, can protect them in long term.

### TLS client authentication
TLS Client Authentication, also known as two-way TLS authentication, requires both the browser and server to authenticate, each sending their TLS certificates in a TLS handshake. This is achieved by a user or service obtaining a client certificate from the server and providing it on subsequent interactions. The user may need to install the certificate if using a browser.

## Want to know more
Check the complete [Secure code review cheat sheet](https://snyk.io/blog/secure-code-review/)
One should know this before trying macOS in a virtual machine
Tags: macos, parallels, virtualmachine
Published: 2020-08-13 06:43:58

Working with virtual machines is part of my daily bread and butter.

Since I have a MacBook Pro (16") again after a long time, I wanted to use macOS in a virtual machine (VM).

The installation is quick. After starting the VM, I first opened the Safari browser and felt a not-so-pleasant surprised after opening several tabs. In the animated GIF below, you can see that the tab titles are illegible and flicker.

![Fig. 1: Open additional tabs in Safari](https://dev-to-uploads.s3.amazonaws.com/i/a5rjson1sfm1kzo8vwej.gif)
<figcaption>Fig. 1: Open additional tabs in Safari</figcaption>

I had a déja vu when I opened Visual Studio Code after installing it to edit a text. The inserted text is only partially or not displayed at all. If you move the mouse pointer over the taskbar of the editor, the icons simply disappear.

![Fig. 2: Open a text file in VSC](https://dev-to-uploads.s3.amazonaws.com/i/irzgh3lfqlvrahc3fmbb.gif)
<figcaption>Fig. 2: Open a text file in VSC</figcaption>

As it stands, there is a problem with the graphical resolution or the representation. After briefly researching the topic on the net, it became clear that hardware acceleration is not supported in a virtual machine with macOS.

Parallels support confirms this: "Parallels Desktop does not support 2D or 3D acceleration in OS X/macOS guest operating systems (installed inside the virtual machine) because Apple does not provide an API for creating a video driver with 2D/3D acceleration support."

Until now, I was very satisfied with Parallels (I had always used VMware in the past, even on previous Macs). But as it turns out, this is the same with VMware. As Parallels support has said, it's not up to the product, but to Apple that doesn't release the necessary information.

One solution is to turn off the use of hardware acceleration per app, provided the app offers this option. It is possible with Visual Studio Code. Here you can turn off the use of hardware acceleration in the settings.

Using the "Command Palette" and "Preferences -> Configure Runtime Arguments," you open the file "argv.json" and can then activate the switch for hardware acceleration or turn it off.

{% gist https://gist.github.com/dergroncki/15335257c1fda47581c963413fc82dd3 %}

After a restart, Visual Studio Code will work as expected.

![Fig. 3: Open a text file in VSC hardware acceleration switched off](https://dev-to-uploads.s3.amazonaws.com/i/qvfa8xs8cs4c5yjv2rdl.gif)
<figcaption>Fig. 3: Open a text file in VSC hardware acceleration switched off</figcaption>

Unfortunately, I couldn't find a way to turn off the use of hardware acceleration for the Apple Safari browser. However, for example, the browser of Google offers such a setting, accessible via "Settings -> Advanced -> System."
Understanding Docker: part 3 – Run a container
Tags: docker, devops, beginners, cloud
Published: 2020-08-13 06:34:24

---
title: Understanding Docker: part 3 – Run a container
published: true
description: Serie of sketchnotes about Docker. Explaining in a visual way Docker principles.
tags: Docker, DevOps, beginners, Cloud
series: Understanding Docker in sketchnotes
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/aj2o83ikb5cr4fik2f02.jpg
---

Understanding Docker can be difficult or time-consuming. In order to spread knowledges about Cloud technologies I started to create sketchnotes about Docker. I think it could be a good way, more visual, to explain Docker (and others technologies like Kubernetes and Istio).

We start the serie of Docker Sketchnotes with a focus about how to run a container.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/aj2o83ikb5cr4fik2f02.jpg)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/k977412tlsfek0xaajzg.jpg)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/2tor6fgfb1bgmrbublrp.jpg)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/8w00wg7jblq29uusfbpy.jpg)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/cc7bbguj3eecgxwkhwpg.jpg)

If you are interested, I published all the sketchnotes on Docker (and new ones!) to make a "book" of 93 pages: ["Understanding Docker in a visual way"](https://gumroad.com/aurelievache#YTLzM).

As usual, if you like theses sketchnotes, you can follow me, and tell me what do you think. I will publish others sketchs shortly :-).
Vanilla JavaScript Email Validation
Tags: javascript
Published: 2020-08-13 06:08:45

Today I want to address a topic I use quite often but noticed I've never written about.
Email validation! Since my day job is in marketing, we build a lot of pages with forms, and the least we need is an email address. So how do we make sure the input is at least a valid email type in JavaScript?

## HTML Structure

For today's work we'll use a very simple form, with only a email input and a button to submit. Then we'll have a response div to show us if the email was correct.

```html
<div class="container">
  <input type="email" id="emailField" />
  <br />
  <button id="button">Check validation</button>
  <div id="response"></div>
</div>
```

## JavaScript Validating an Email Address

Ok, now on to the fun part, `JavaScript`! Let's start by defining our variables we need to use.

```js
var emailField = document.getElmentById('emailField');
var button = document.getElementById('button');
var response = document.getElementById('response');
```

Awesome, very basic selectors, but enough for this excercise.

Now we want to add a click listener to our button.

```js
button.addEventListener('click', function() {
  var email = emailField.value;
  console.log(email);
});
```

This function will log the value of what we put in the input field.

So for now let's make our actual function to check if it's valid:

```js
function validateEmail(email) {
  const re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
  return re.test(String(email).toLowerCase());
}
```

BAM! Please don't be scared; it's a plain old `regular expression` we are using. This will validate a valid email format.

It will return true or false, depending on the state.

So let's implement this back in our button click.

```js
button.addEventListener('click', function() {
  var email = emailField.value;
  if (validateEmail(email)) {
    response.innerHTML = 'Hiya Cowboy, this email will work for us 🤠';
  } else {
    response.innerHTML = 'Sorry, this email is not cool enough 😩';
  }
});
```

There we go! Of course, you would like to do something with this information, but I'll leave that up to you!

View this example on the following Codepen.

{% codepen https://codepen.io/rebelchris/pen/KKzdOJG default-tab=js,result %}

### Thank you for reading, and let's connect!

Thank you for reading my blog. Feel free to subscribe to my email newsletter and connect on [Facebook](https://www.facebook.com/DailyDevTipsBlog) or [Twitter](https://twitter.com/DailyDevTips1)