teleren/devto huggingface dataset:
A simple extension to add buttons above the keyboard 
Tags: ios, swift
Published: 2020-06-21 09:48:21

It is quite common when you have an input view on an iOS app to show some actions above the keyboard to improve the user experience. Those actions can range from a `Done` button on a number pad, a `Cancel` button to dismiss the keyboard to literally anything. 

Though there are various options you can use to add those actions, the most common and probably the easiest is to set the property `inputAccessoryView` of the `UITextField` to an instance of `UIToolbar` with items the buttons you would like to add. 

Since it's such a common practice, I am using an extension to make this operation a little bit nicer to use:

```swift
extension UITextField {

    typealias ToolbarItem = (title: String, target: Any, selector: Selector)

    func addToolbar(leading: [ToolbarItem] = [], trailing: [ToolbarItem] = []) {
        let toolbar = UIToolbar()

        let flexibleSpace = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)
        let leadingItems = leading.map { item in
            return UIBarButtonItem(title: item.title, style: .plain, target: item.target, action: item.selector)
        }

        let trailingItems = trailing.map { item in
            return UIBarButtonItem(title: item.title, style: .plain, target: item.target, action: item.selector)
        }

        var toolbarItems: [UIBarButtonItem] = leadingItems
        toolbarItems.append(flexibleSpace)
        toolbarItems.append(contentsOf: trailingItems)

        toolbar.setItems(toolbarItems, animated: false)
        toolbar.sizeToFit()

         self.inputAccessoryView = toolbar
    }
}
```
---

Now, with that extension in place, you can add the toolbar in the following way: 

```swift
let textField = UITextField()
let cancelButton = UITextField.ToolbarItem(title: "Cancel", target: self, selector: #selector(cancelPressed))
let resetButton = UITextField.ToolbarItem(title: "Reset", target: self, selector: #selector(resetPressed))
let doneButton = UITextField.ToolbarItem(title: "Done", target: self, selector: #selector(donePressed))
textField.addToolbar(leading: [cancelButton, resetButton], trailing: [doneButton])
```
---
If you run the app, the keyboard will look like the following screenshot 🤓

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

---
➡️ This post was originally published on my [blog](https://diamantidis.github.io).
Uncaught SyntaxError: Unexpected token < in a script tag
Tags: help, php, javascript
Published: 2020-06-21 11:38:35

So I have a PHP file which contains some JS code and I'm trying to pass an array from PHP into JS
```
<?php
include('autocomplete.js');
?>
<script type="text/javascript">
// any valid JS code can reproduce this issue because the syntax error is on the line above
var people = <?php echo json_encode($people)?>
</script>
```
I get an "unexpected token '<'" error and the line referenced is always the one with the script tag in it
Not really sure what to try so if anyone can help out that would be great
Thank you
AWS: EC2 Hibernation
Tags: aws, beginners, career, 100daysofcloud
Published: 2020-06-22 15:02:26

[Amazon Elastic Compute Cloud (Amazon EC2)](https://aws.amazon.com/ec2/) is a web service that provides secure, resizable compute capacity in the cloud. 

It is designed to make web-scale computing easier for developers.

### What is EC2 Hibernation?

Have you ever put your computer to "sleep"? 
When you close the computer your work is still saved and available as soon as you open the computer back up.

In the same way we can put our EC2 instances "to sleep" or hibernation.

### Hibernation Flow:
![EC2 Hibernation flow](https://dev-to-uploads.s3.amazonaws.com/i/vbgiffwdnlsh8ql0kexc.png)

### Benefits

**[Hibernation](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Hibernate.html)** saves the contents from the instance memory (RAM) to your [Amazon EBS](https://aws.amazon.com/ebs/?ebs-whats-new.sort-by=item.additionalFields.postDateTime&ebs-whats-new.sort-order=desc) root volume.

This leads to a **faster** boot up time for your instances.

AWS persists the instance's Amazon EBS root volume and any attached Amazon EBS data volumes.

####When an instances is started again:

- Your Amazon EBS volume is restored to it's previous state. (*Like when opening a computer that has been "put to sleep"*)
- Your **RAM contents** are reloaded and **the processes** that previously were running on the instance are **resumed.**

### Important Information

EC2 hibernation is available for [On-Demand](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-on-demand-instances.html) and [Reserved](https://aws.amazon.com/ec2/pricing/reserved-instances/) Instances.

An Instance can only be put in to hibernation if it meets the [hibernation prerequisites.](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Hibernate.html#hibernating-prerequisites)

####Examples of prerequisites include:

- The root **EBS** volume must be **encrypted**.
- Supported instance families include: C3, C4, C5, M3, M4, M5, R3, R4, and R5
- Instance RAM size must be less than 150 GB
- The Amazon Machine Images it currently supports are Amazon Linux 2, Linux AMI, Ubuntu and Windows

AWS does not charge for a hibernated instance when it is in a **stopped** state.

There are limitation and actions not supported for hibernation. 

For a complete list of limitations check out the [AWS documentation.](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Hibernate.html#hibernating-not-supported)

####Use Cases for Hibernation:

- Apps with long-running processing
- To save RAM state for quicker boot-up
- For services that take a lot of time to initialize

This topic is addressed in the new [AWS Solutions Architect Exam](https://aws.amazon.com/certification/coming-soon/)**[SAA-C02]**

If you want to learn even more and prepare for the AWS Certified Solutions Architect Associate Exam then check out our course on [ExamPro.](https://www.exampro.co/aws-exam-solutions-architect-associate)
Proxy Component
Tags: react, beginners, javascript, webdev
Published: 2020-06-22 07:45:18

A proxy component is a placeholder component that can be rendered to or from another component. In short a proxy component is a reusable component.

Example:

```js
import React from 'react'

class Button extends React.Component {
  render() {
    return <button type="button">My Button</button>
  }
}

class App extends React.Component {
  render() {
    return <Button />
  }
}

export default App
```

<hr/>

### React Patterns

To learn more React Patterns visit: <a href="https://reactpatterns.js.org/">https://reactpatterns.js.org</a>

To get the latest React patterns follow/star/like us on:

* Twitter: <a href="https://twitter.com/reactjspatterns">@reactjspatterns</a>
* Github: <a href="https://github.com/reactpatterns/reactpatterns">reactpatterns</a>
* Facebook: <a href="https://www.facebook.com/reactjspatterns">reactjspatterns</a>
You can try AiSara for Free !
Tags: machinelearning
Published: 2020-06-22 09:22:42

#**Grab the opportunity**
[Malaysia's Next Generation Artificial Intelligence](https://www.aisara.ai/)
### **Upcoming Demo**
AiSara team is going to launch a demo version of AiSara soon ! Where user can upload their own numerical data and do their own prediction. 

**1. General Aisara**
**2. Oil & Gas Production Forecast , History Matching**
**3. Hyperparameter Tuning**

Aisara can predict any kind of numerical data, no model design are needed the only thing that you need is your input and output data then Aisara can easily find the pattern ! Visit our website OR Email us directly on support@aisara.ai for the latest update regarding the demo launching date
python list directory files
Tags: python
Published: 2020-06-22 21:19:52

Do you want to find out how to display all directory's files using Python?

You can use `os.walk()` or `glob()` in the Python programming language. 

To list files and folders you can use `os.walk()`. From there you can do specific <a href="https://python-commandments.org/python-file-handling/">file handling</a>

Did you know Python can <a href="https://pythonspot.com/http-download-file-with-python/">download files</a> from the web?

## List files and folders

## os.walk()

List all the Python files in the directory
and subdirectories:

```python
import os                                                                       
files  = []                                                                     
cwd = os.getcwd()                                                               
# (r)oot, (d)irectory, (f)iles                                                  
for r,d,f in os.walk(cwd):                                                      
    for file in f:                                                              
        if '.py' in file:                                                       
            files.append(os.path.join(r,file))                                  
                                                                                
for f in files:                                                                 
    print(f)      
```

List folders and sub folders

You can also use `os.walk()` to get the folders and sub-folders.

```python
import os
cwd =os.getcwd()
print("folder {}".format(cwd))

folders = []
for r,d,f in os.walk(cwd):
    for folder in d:
            folders.append(os.path.join(r, folder))

for f in folders:
    print(f)
```

You can <a href="https://pythonprogramminglanguage.com/how-to-run/">run</a> this both in the terminal and the web.

## glob.glob()

The function `.glob()` can be used for the same purpose. To list all files with the py extension 

```python
import glob                                                                     
cwd = "/home/you/Desktop/"                                                    
files = [f for f in glob.glob(cwd + "**/*.py", recursive=True)]                 
for f in files:                                                                 
    print(f)    
```

To list all folders and sub folders

```python
import glob
cwd = "/home/you/Desktop/"
folders = [f for f in glob.glob(cwd + "**/", recursive=True)]
for f in folders:
     print(f)
```     

If you are new to Python, I suggest this <a href="https://gumroad.com/l/dcsp">Python book and course</a>
Tailwind CSS & Svelte on Snowpack - Svelte Preprocess
Tags: svelte, tailwindcss, snowpack, webdev
Published: 2020-06-23 05:41:31

[Snowpack](https://www.snowpack.dev/) is a tool for building web applications with less tooling and 10x faster iteration. [Tailwind CSS](https://tailwindcss.com/) is a utility-first CSS framework for
rapidly building custom designs. Let's explore how to combine both of them. [Svelte](https://svelte.dev/) is a radical new approach to building user interfaces.

This article talks about how to use them in combination. This will also interest you if you want to add `svelte-preprocess` when using a Snowpack app.

# Template

Premade template is available on [Github](https://github.com/agneym/svelte-tailwind-snowpack). You can use the template with command:

```bash
npx create-snowpack-app dir-name --template @snowpack/app-template-svelte
```

## Setup Svelte and Snowpack

Snowpack provides an official template for svelte that can be initialised with:

```bash
npx create-snowpack-app dir-name --template svelte-tailwind-snowpack
```

[Template Source](https://github.com/pikapkg/create-snowpack-app/tree/master/templates/app-template-svelte)

## Svelte Preprocess

If you wanted to add PostCSS to your Svelte application, [`svelte-preprocess`](https://github.com/sveltejs/svelte-preprocess) would probably be the plugin you think of. It functions as an automatic processor for PostCSS, SCSS, Less and a lot more.

But since we are using Snowpack's custom plugin, none of the usual loaders would work. Luckily, snowpack plugin has a secret hatch to push in plugins. It's a config file named `svelte.config.js`. You can create one in your root folder and export your pre-processor.

```javascript
module.exports = {
  preprocess: () => console.log('Preprocess Script'),
};
```

To add `svelte-preprocess`, you would need to install it with:

```bash
npm i svelte-preprocess
```

Modify the `svelte-config.js` with:

```javascript
const sveltePreprocess = require("svelte-preprocess");

const preprocess = sveltePreprocess({
  // options to preprocess here
});

module.exports = {
  preprocess,
};
```

## Configuring PostCSS

As [suggested on Tailwind docs](https://tailwindcss.com/docs/installation), we will use Tailwind CSS with PostCSS. To add this to preprocess:

```javascript
const sveltePreprocess = require("svelte-preprocess");

const preprocess = sveltePreprocess({
  postcss: {
    plugins: [
      // Plugins go in here.
    ]
  }
});

module.exports = {
  preprocess,
};
```

## Adding Tailwind

Tailwind is available as a PostCSS plugin, you can add it with:

```javascript
const sveltePreprocess = require("svelte-preprocess");

const preprocess = sveltePreprocess({
  postcss: {
    plugins: [
      require('tailwindcss')
    ]
  }
});

module.exports = {
  preprocess,
};
```

After installing `tailwindcss` package ofcourse.

---

and you are good to go. You can find the complete template on Github:

{% github agneym/svelte-tailwind-snowpack %}

It is also listed on the page for community templates on Snowpack website.

Have Fun 🎉
Learn With Me 3
Tags: html, css, javascript, beginners
Published: 2020-06-23 10:50:42

Hey developers.How are you feeling today?So this is the 3rd part of my <i><h3>Learn with me</i></h3>In my 2nd blog I said I would talk about CSS today.But thinking about it and reading the 2nd blog again I didn't saw any html topic to be discussed in my post.So I wanted to discuss html topics,what aspect of html you should care more about and also some tips to learn html.

Ok now,a quick overview on html.html isn’t vastly spread all over the place.It is a very small and sorted markup language.So its easy to read it all.Whoever is trying to master html should remember explicitly that html cannot do everything on its own.So he/she better be ready to learn the extension for doing anything with html.The extensions are not that hard to learn but its not that easy too.It's like the <b>English</b> language(For people who are **not** native English speaker)They have to learn it.Its not easy at first.But once you get hold of it,It's easy to get around or may be not.Because I have only been exposed to CSS.But it's fine I will let you people know about it once I cover all the extensions.

About the extensions I will list some of the important ones that I think is important:
<ul><li>css</li><li>java-script</li><li>bootstrap</li></ul>

Before moving on to the next topic I would love to tell you about this movement that was started sometime ago.And its a big movement for new coders.Its called the #100dayschallenge.So what happens is you basically code for 100 days consistently for at least an hour.I joined it yesterday.You can join it if you want.Just tweet once by saying <q> I start the #100dayschallenge</q>.Here is the link: https://twitter.com/osmang670/status/1275068165811101698?s=19.

Now about the topics you should give more attention.First of all there aren't many topics so its easy to remember all.But what happened with me is that I started css and now I keep forgetting some important things like combining a link from html.That is why you should learn how to link an url with any button or image or word and practice it.And other tags and small things are easy to remember or you can google it when you need.But you always need to remember the process how to make a form,table,link an image/word/button.Also learn about how to link an email in a form(so that the admin gets the message).That is something I forgot too.

Now about learning html.Actually you dont have to do much.You just have to be consistent enough to take all the demotivation in and kick it out.For getting materials just search in youtube <em>learn html</em> and filter it to **playlist**.You will see 100s of playlist.If you need written document I would suggest www.w3schools.com
So this is all about html that I learned and from where I learned.Hope it helps you guys.I will give a blog after I finish CSS.It will take some time.May be a week or more no idea.If I can,I will give another blog in the meanwhile.

**Thanks for reading till the end**
How To Test NPM Packages Locally
Tags: javascript, npm
Published: 2020-06-23 16:18:01

---
title: How To Test NPM Packages Locally
published: true
date: 2020-06-23 15:00:36 UTC
tags: javascript, npm
canonical_url: https://www.jamesqquick.com/blog/how-to-test-npm-packages-locally
cover_image: https://cdn.sanity.io/images/rx426fbd/production/ec2a77c87b63089a7cba9d4590ef9a9a8bc34c79-1920x1080.png
---

{% youtube Knw8U5XyHaM %}

When creating NPM packages, it's much better to test them locally before publishing. Let's take a look at how to do that.

> Shoutout to [Brad Garropy](https://bradgarropy.com/) for sharing his knowledge on NPM packages with me.

## TLDR

- link your package locally

- create a test application

- link the NPM package in your test application

- do the test stuff

## Getting Started

You'll need an NPM package local on your machine. If you've never created an NPM package before, you can learn how to create one by following this article, [Creating and Publishing NPM Packages](https://jamesqquick.com/blog/how-to-create-and-publish-npm-packages).

> For clarity, let's assume the name of the package we are working on is name `jqq-package`. You'll need to replace this with the name of your actual package.

You'll also need an application to test your package with. For this, create a new folder and open it inside of your text editor. I recommend VS Code 😀.

Then, initialize this test project by running `npm init`.

## Let's Test It

With your NPM package local to your machine, you'll need a way to reference/install it in the test application.

**Inside of the original NPM package directory** , run `npm link` from the command line. This command will allow us to simulate installing this NPM package without it actually being published.

From there, we need to link to this package from inside of the **test directory**. You can do this by running `npm link` followed by the name of the local package. In this demo, the name of the package we want to test is `jqq-package` so you would run `npm link jqq-package`, but make sure to use the specific name of the package you are testing.

Now, you should be able to test the package in whatever way makes sense. I won't go into detail here because this varies significantly based on what your package does, but hopefully, this sets you up to run whatever tests you think make sense.

## Wrap Up

I've been really pleased with how easy it is to create, test, and publish NPM packages. Hopefully, this helps you in testing your packages. If you have any awesome NPM packages to share or additional questions, please reach out on [Twitter](https://www.twitter.com/jamesqquick).

> This article was first posted on my [blog](https://www.jamesqquick.com/blog). You can also follow me on [Twitter](https://www.twitter.com/jamesqquick).
I build Stadia clone with Vuetify.
Tags: vue, webdev, showdev, javascript
Published: 2020-06-29 17:06:00

---
title: I build Stadia clone with Vuetify.
published: true
description: I made a fully responsive template for Stadia Homepage, in a short time
tags: vuejs, webdev, showdev, javascript
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/6ioxjdho8t46uvu8chlf.png
---
I made a fully responsive template for Stadia Homepage, in a short time 🔥🔥 with vuetify.

check it out 😊

[Github Repo](https://github.com/benyou1969/vuetify-stadia-clone)

The Site demo: [stadia.netlify.app](https://stadia.netlify.app)

[Vuetifyjs.com](http://vuetifyjs.com/)
My first codewar solved
Published: 2020-06-29 17:30:52

the Question : 
You are going to be given a word. Your job is to return the middle character of the word. If the word's length is odd, return the middle character. If the word's length is even, return the middle 2 characters.

#Examples:

Kata.getMiddle("test") should return "es"

Kata.getMiddle("testing") should return "t"

Kata.getMiddle("middle") should return "dd"

Kata.getMiddle("A") should return "A"

#Input

A word (string) of length 0 < str < 1000 (In javascript you may get slightly more than 1000 in some test cases due to an error in the test cases). You do not need to test for this. This is only here to tell you that you do not need to worry about your solution timing out.

#Output

The middle character(s) of the word represented as a string.



my solving :
function getMiddle(s) {
  var length = s.length;
  var middle = length / 2;
  let floor = Math.floor(middle);
  const middleNumber = Number(middle);
  const floorNumber = Number(floor);
  const mathNumber = middleNumber - floorNumber;
  if (mathNumber > 0) {
    let finalMiddle = s[floorNumber];
    return finalMiddle;
  } else {
    let finalMiddle1 = s[floorNumber - 1];
    let finalMiddle2 = s[floorNumber];
    return finalMiddle1 + finalMiddle2;
  }
}

ofcourse i know my solving is not to the point but im really happy to solve this
Understanding the Mobility Adoption, Trends, and Its Future Outlook
Published: 2020-06-29 20:51:55

Mobility and Mobile Technology is one of the prominent aspects that has largely influenced our daily lives and most importantly professional lives. The sight of new generation modern workforces using advanced smart technologies is quite common and Entrepreneurs can predict and see a new genre of work process influencing the coming future more extensively.

Mobility is a growing trend with business sectors adapting to workforce mobility. The infographic gives a magnified insight into the mobile ecosystem and understanding into the adoption of mobility, its influence in the 21st-century organizations, employees, and customers who are looking for a high level of connectivity, productivity and what the future has in store with enterprise mobility transforming businesses and redefining its workability.

Infographic source- https://blog.scalefusion.com/the-magnified-mobile-ecosystem-infographic/