teleren/devto huggingface dataset:
superPyOS- the terminal
Tags: python, linux
Published: 2020-04-29 07:26:30

It's been a while I know, but here is the second chapter!

----------

the terminal was the main part of the OS, it had different commands controlling parts of the system. Something so powerful i'm going to say only involved the basic parts of python like user input, IF and the os module.

---------

# 1. the modules

firstly you need to import your modules, we reccommend:

```python
import os
import io
import platform    # modules to use
import subprocess
import sys
import glob
from time import *
import logging
from datetime import datetime
```

*logging will be explained later in the series.

# 2. the prompt

An OS prompt would be the location it is now, we can program this by using;
```python
currentpath = os.getcwd() # get current path
```

so your prompt would be:
```python
command = input(currentpath + "> ")
```

# 3. the commands!

Now that we have our input prompt, we can start adding commands!

each command would start as:
```python
if command == "COMMAND":
```
then below that you add your function- what do you want it to do?

for example, perhaps we want to clear the screen? we would use the OS module for that.

```python
if command == "clear":
   os.system("clear")

```

of course- we need a way to loop the script- or after each command it'll quit.

so at the VERY END, we would put:

```python
os.system("python3 SCRIPTNAME.py")
```

-----------

if you know how to use other modules, then you can link them up and start making your own beginner 'guest' operating systems!
We're not smarter than browsers
Tags: webdev
Published: 2020-04-29 17:04:08

---
title: We're not smarter than browsers
published: true
date: 2020-04-29 00:00:00 UTC
tags: webdev
canonical_url: https://remysharp.com/2020/04/29/were-not-smarter-than-browsers
---

This morning during performing another search through npm for the package that matched my needs, I was feeling lazy and didn't want to type "npm i x" - thankfully npm provided a helpful "click to copy". And that's where it went wrong.

I recorded a [video of my experience](https://www.youtube.com/watch?v=nnD0-h7fVEg) and this is part transcript, part conclusion, part repeating the obvious.

* * *

Look when you disable user-select or try to disable right-click on your web page and you're not only breaking the accessibility the page, but you're also making the rather bold statement that _your code will **never, ever** break_.

It seems too much of a risk.

This morning's npm visit was an excellent example. I wanted to copy the text, so I hover over "npm i chart.js" and it says briefly, if I catch it, "click here to copy" but mousing over the copy not doing anything, and indeed "clicking here" when I check my clipboard has not copied anything.

I'm clicking, but it's not copying.

Okay, bugs happen, clearly the copy button doesn't work. Instead let's select this text and just… copy? Nope, no, I can't select the text.

In fact, this is the one bit of text on that page that has been intentionally disabled for selecting, because we think as "web developers" we are smarter than the user and there's no way our code will ever break.

Well, I have news for us web developers: we are fallible. Our code will break.

So let's not break intentionally break accessibility features the browser works so hard to provide the user.

Stop preventing select - selecting text is useful both for copying, but also for reading text (see dyslexic users).

Stop not using buttons - buttons are clickable and we forget to add aria roles.

Stop reinventing links - they're magic and [our versions](https://remysharp.com/2019/04/04/how-i-failed-the-a) are rubbish.

Stop [scroll jacking](https://chrome.google.com/webstore/detail/no-more-scroll-jacking/fpialmplgijjacabejjgheeifmfamjcd) - it's squarely in the the uncanny valley, and often scrolls to fast for content to be properly read.

Let's stop thinking we're smarter than the browser.

Enhance the browser, don't reinvent.

_Originally published on [Remy Sharp's b:log](https://remysharp.com/2020/04/29/were-not-smarter-than-browsers)_
In-App switching API URL from testing to production in react-native
Tags: reactnative, react, javascript
Published: 2020-04-29 07:00:49

Make the state of your endpoint first,
```javascript
state = {
  endpoint: 'http://test.sample.com'
}
```

write a method that will change the API endpoint state on button click

```javascript
envUsage = (environment) => {
  if (environment == 'testing') {
    this.setState({ endpoint: 'http://test.sample.com' })
  } 
  else if (environment == 'production') {
     this.setState({ endpoint: 'http://production.sample.com' })
  }
}
```

Now, call the method by passing your environment as a parameter,

```javascript
<Button name="production" title="Use Production" onPress={() => this.envUsage('production')} />

<Button name="testing" title="Use Testing" onPress={() => this.envUsage('testing')} />
```

I have shown the above as a demo for a sample. you can make a global service and maintain the endpoint this will work better in your all components by inheriting that service. 

Github Repo: https://github.com/muhammadawaisshaikh/react-native-switch-url
Secret Santa
Tags: twiliohackathon
Published: 2020-04-29 06:56:23

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

The "problem" I'm solving here:
--
You and your friends want to do the secret santa this christmas and you need a way to randomly pick secret santas for each in the group.

1. User goes to the website.
2. ~~(Register)~~
2. Fill in the info of your friends (Name & Phone number)

Once you've added all of your friends, the system will randomize who gets who as the secret santa. It will then ~~send sms~~ make a phone call to each person in the group telling them who is their "target".

---

> Unfortunately there's no available phone numbers with SMS for Finland in Twilio. So I switched to phone calls instead. Also dropped the registration part here.

---

This way no one will know each others target. You only know what you need to know. This way also the "organiser" can participate, because they don't need to be the one that knows all the info.

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


[Reminder]: # (Make sure you've submitted the Twilio CodeExchange agreement: https://ahoy.twilio.com/code-exchange-community)


## Category Submission: Exciting X-Factors


### Demo

> Please don't bug your friends with this. If you want to try it, you can add one real number (yours) and for the rest, add: +358012345678.

https://secret-santa-bfeba.web.app/

### Code

https://github.com/jakate/secret-santa

## How I built it

Stack was pretty much:
- Firebase (Hosting & Functions)
- Twilio call API
- React
Subscribe Pusher on the node environment
Tags: javascript, node, pusher
Published: 2020-04-29 06:46:11

[Pusher](https://pusher.com/) is great pub/sub service.

Basically, we need to subscribe pusher with [`pusher-js`](https://github.com/pusher/pusher-js), and this library has `node` platform.
When we need private/presence channel, we need authorize with [`pusher-http-node`](https://github.com/pusher/pusher-http-node).

## Problem
Sometimes we need to subscribe private channel on node server.

Pusher have [webhooks](https://pusher.com/docs/channels/server_api/webhooks), but we can't detect only one endpoint in the some case (like IoT, edge device etc...)

## Solution

`pusher-js` client can custom [`authorizer`](https://github.com/pusher/pusher-js#authorizer-function).
We can create self-auth authorization client.

```js
const Pusher = require("pusher-js/node")
const PusherServer = require("pusher")
const uuid = require("uuid")


const pusherServer = new PusherServer({
  appId: PUSHER_APP_ID,
  key: PUSHER_KEY,
  secret: PUSHER_SECRET,
  cluster: "ap3",
  encrypted: true,
})
// Pusher.logToConsole = true
const pusher = new Pusher(PUSHER_KEY, {
  cluster: "ap3",
  authorizer: (channel) => {
    return {
      authorize: (socketId, callback) => {
        const auth = pusherServer.authenticate(socketId, channel.name, {
          user_id: `server-${uuid.v4()}`, // we require userId when presence channel
        })
        callback(false, auth)
      },
    }
  },
})
```
Upgrading Ubuntu Server from 19.04 to 20.04 (Focal Fossa)
Tags: todayilearned, ubuntu, linux
Published: 2020-04-29 06:39:31

---
title: Upgrading Ubuntu Server from 19.04 to 20.04 (Focal Fossa)
published: true
description: Steps to take when upgrading Ubuntu Server to latest LTS release.
tags: todayilearned, Ubuntu, Linux
canonical_url: https://paulbradley.org/upgrading-ubuntu-focal-fossa/
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/a70at491ngjct9y5msea.png
---

## Preparation

Before upgrading your Ubuntu server take a backup or snapshot of your existing server so that you can restore it to a working server if the upgrade fails at any point. Most hosting providers offer a facility via their control panel to make a snap shot backup. It's probably best practice to take this snap shot while the server is powered down.

Upgrading to Ubuntu 20.04 LTS (Focal Fossa) is a good idea as it's a long term support release which means you'll get security updates for the next five years. Focal Fossa comes with a lot of new packages and major software upgrades, including the latest versions of Java, Python, Ruby, PHP and many more. This release is based on the Linux 5.4 LTS kernel and adds support for new hardware and file systems.

## Check for held packages & update

Start by checking if you have any held packages by using the the `showhold` command. If you do have any then mark them as un-held by issuing an `unhold` command followed by the package names listed in the previous command.

``` bash
sudo apt-mark showhold
sudo apt-mark unhold package_name
```

Once you have un-held any packages, perform a standard update and upgrade and then reboot the server.

``` bash
sudo apt update
sudo apt upgrade
sudo systemctl reboot
```

## Purge & remove unwanted packages

After the server restarts then perform a full upgrade and then purge any unwanted or unused packages to recover some disk space.

``` bash
sudo apt full-upgrade
sudo apt --purge autoremove
```

## Upgrade to 20.04

At this point you're ready to upgrade from 19.04 to 20.04 by performing the release upgrade commands. As the upgrade progresses you'll be prompted to answer various questions in relation to your setup. These questions will vary depending on what software you've already installed and configured on your Ubuntu server.

``` bash
sudo apt install update-manager-core
sudo do-release-upgrade -d
```

## Verifying the version number after the upgrade

After the upgrade has completed and the server has rebooted you can check the current version of your Ubuntu server by checking the release version.

``` bash
lsb_release -a
```

Which should output something like.

``` bash
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 20.04 LTS
Release:	20.04
Codename:	focal
```
Quality Assurance is About Facilitating Change 
Tags: testing
Published: 2020-04-29 06:38:39

There are some really great statements about the purpose of testing. Is it to find issues? Are just communicating risk or function to stakeholders? Do we ensure requirements are met? Is it to advocate for the user.

Well, I think they might be all wrong, kidding those are levels below. At the heart quality assurance is working to allow changes to occur.

Regression testing is the clearest activity to support changes. If the software is modified, a regression pass is to identify unexpected changes. 

When verifying requirements it is in direct support of getting a change through as designed. 

Advocating for a user is about identifying needed changes which make the software better for a user.

---

Being in a QA role as an SDET, I'm building tools to improve the developers ability to make changes. Being focused at the contract level I am supporting larger changes then unittesting.

I think this mindset is important because it appears the other mindset is to stop change. Change increases risk. Change creates unknowns. Change means more work for testing. Thus we must only change the bear minimum. QA then advocate for avoiding change.

Don't update the third party libraries you use, that introduces unnecessary risk. That security patch, throw it away. The OS updates, ack... We should definitely stay on Java 7, who knows what 8 will bring.

Being an advocate for change means, I want you to refactor code. I want you to update to the latest tools and techniques. I know how valuable that can be for quality.
How to limit resources using Quotas & Limit Ranges in OpenShift?
Tags: openshift, kubernetes, node, devops
Published: 2020-04-29 06:23:46

## Objective
- Create project **my-project**
- Create Quota & Limit Ranges for project **my-project**
- Deploy Node JS Application using S2I
- Verify allocated Quota & Limits

### Step 1: Set up OpenShift environment
Go to [Katacoda.com](https://katacoda.com/openshift/courses/playgrounds/openshift39) & click on start scenario

### Step 2: Create project my-project
```
oc new-project my-project
```

### Step 3: Create quota
```
oc create quota project-quota --hard=pods=10
```

### Step 4: Describe quota
```
oc describe quota project-quota
```

### Step 5: Create limit ranges
```
vi limits.yaml
```
Add following limit range

```
apiVersion: v1
kind: LimitRange
metadata:
    name: project-limits
spec:
    limits:
        -
            type: Container
            max: {cpu: '2'}
            min: {cpu: 100m}
            default: {cpu: 300m}
```

```
oc create -f limits.yaml
```

### Step 6: Describe limit ranges
```
oc describe limits project-limits
```

### Step 7: Describe node
```
oc describe node localhost | grep -A 4 Allocated
```

### Step 8: Deploy nodejs application using s2i
```
oc new-app -i nodejs:8 https://github.com/sagar-jadhav/node-hello --name nodejs -l app=demo
```

### Step 9: Describe quota
```
oc describe quota project-quota
```

### Step 10: Describe limit
```
oc describe limits project-limits
```

### Step 11: Scale up nodejs application
```
oc scale dc nodejs --replicas=9
```

### Step 12: Describe quota
```
oc describe quota project-quota
```

### Step 13: Describe limit
```
oc describe limits project-limits
```

### Step 14: Scale up nodejs application
```
oc scale dc nodejs --replicas=15
```

### Step 15: List pods
```
oc get pods
```

### Step 16: List events
```
oc get events
``` 

{% youtube BVCpuUUGHuc %}
Working on a hair professional mobile app (Xamarin, C#, PHP, MySQL)
Tags: architecture, php, sql, sideprojects
Published: 2020-04-29 06:23:23

Up late making great progress on a mobile app I’m working on called ‘Cut Corners’! I’m coding this in C# using the cross-platform Xamarin framework. Cut Corners helps potential clients find stylists in their area based on detailed criteria. 📲

To avoid reinventing the wheel, I’m forked a lot of the back-end/API logic from a previous/similar app I built. This consists of a MySQL database/tables and simple PHP scripts. The PHP scripts are basically endpoints that expose the data layer for querying and mutation.

Over the years I’ve learned that as a developer having some basic PhotoShop skills helps move things along when you don’t have the resources for a UI/UX. The owner provided the Cut Corners logo but I was able to modify it to work better in the app. I often use ‘Canva’ when I can instead of PhotoShop since it’s easier/free.

Can’t wait to get the next build out to the owner very soon...have to do a few things first:
· implement appointment and scheduling database tables
· code a PHP script/API endpoint for retrieving availability and booking appointments
· implement an availability schedule view and booking screen in the app

Let me know if you have any questions about the app, the technology used, or if you have any tips/feedback. 🔆

![mobile app and code](https://dev-to-uploads.s3.amazonaws.com/i/t1dj84rwbgi2s48t4ouy.jpeg)
![mobile app pro sign-in](https://dev-to-uploads.s3.amazonaws.com/i/v3wr685bdrzhqgguky74.jpeg)
![mobile app sign-in](https://dev-to-uploads.s3.amazonaws.com/i/rxvk7b7zuaa99vue8h97.jpeg)
![canva logo editing](https://dev-to-uploads.s3.amazonaws.com/i/tr7o9tkfpq6s3k0oxn5z.jpeg)
pattern.css
Tags: showdev, css, design
Published: 2020-04-29 05:48:47

Last week I made CSS only library to fill empty background with beautiful patterns.

Features
* Only CSS. No JavaScript!
* < 1KB minified and gzipped!
* Supports all modern browsers
* Built Using SCSS.
* Full color control.

Documentation and demo: https://bansal.io/pattern-css
Github: https://github.com/bansal-io/pattern.css

Hope you enjoy this product and please let us know what you think.
DevOps best practices for setting up recovery points in infrastructure.
Tags: devops, deployment, bluegreen, disasters
Published: 2020-04-29 05:34:33

One of the challenges with automating deployment is the cut-over itself, taking software from the final stage of testing to live production. You usually need to do this quickly in order to minimize downtime. The blue-green deployment approach does this by ensuring you have two production environments, as identical as possible. At any time one of them, let's say blue for the example, is live. As you prepare a new release of your software you do your final stage of testing in the green environment. Once the software is working in the green environment, you switch the router so that all incoming requests go to the green environment - the blue one is now idle.

Blue-green deployment also gives you a rapid way to rollback - if anything goes wrong you switch the router back to your blue environment. There's still the issue of dealing with missed transactions while the green environment was live, but depending on your design you may be able to feed transactions to both environments in such a way as to keep the blue environment as a backup when the green is live. Or you may be able to put the application in read-only mode before cut-over, run it for a while in read-only mode, and then switch it to read-write mode. That may be enough to flush out many outstanding issues.

The two environments need to be different but as identical as possible. In some situations they can be different pieces of hardware, or they can be different virtual machines running on the same (or different) hardware. They can also be a single operating environment partitioned into separate zones with separate IP addresses for the two slices.

Once you've put your green environment live and you're happy with its stability, you then use the blue environment as your staging environment for the final testing step for your next deployment. When you are ready for your next release, you switch from green to blue in the same way that you did from blue to green earlier. That way both green and blue environments are regularly cycling between live, previous version (for rollback) and staging the next version.

An advantage of this approach is that it's the same basic mechanism as you need to get a hot-standby working. Hence this allows you to test your disaster-recovery procedure on every release. (I hope that you release more frequently than you have a disaster.)
🚀 Dictionary API built using Serverless Framework and AWS Lambda Functions
Tags: javascript, opensource, aws, productivity
Published: 2020-04-29 05:33:30

Recently, I was working on a project that required dictionary words and their meanings. I tried to find some good Dictionary APIs. 🚀

I found some but they were paid one and that too available with a cap value. 

So I created my own dictionary API with no request limitations using Serverless Framework Stack with Amazon Web Services (AWS) Lambda and AWS Cloudfront.

AWS Lambda provides 10,00,000 free requests every month and only triggers on a particular event like http request. So it saves alot of computing power and resources.

For those who want to start with Serverless Stack they can see the link of the repository [here](https://github.com/realabbas/dictionary-api)

Currently the api endpoint takes a word and returns the meaning. I'll try to add more options like synonms and antonyms.

GitHub Contributors are welcome to contribute. Also, you may use the dictionary api for your project.
Use this trick to map over single objects in Javascript
Tags: javascript, tutorial, beginners, react
Published: 2020-04-29 05:32:40

The title is of course, misleading. We know from Javascript that we can't use the `.map()` method on non-arrays so what I am talking about? Let's say we make a request to a server and then we convert the json text into the corresponding object. It is of course possible that after the parsing we get back a single object and not an array. If we'll try to iterate over the result, `.map()` won't work so we'll run into issues. You can see this happening in the code bellow. For simplicity, I didn't fetch any real data, I used some hard-coded one. We have a simple React component that should display the names of the imaginary people we get back from the server. When trying to run the code we'll get an error: `Property 'map' does not exist on type Object`.

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

How can we avoid this situation and make sure that we'll be able to map over the result, even if we get a single object after parsing the response? Let's look at the code bellow:

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

What we did was use the `Array.isArray()` built-in method to check if what we get back is an array and if it's not, we store the single object into a single element array. Since `.map()` iterates over single entry arrays, we won't run into an error. You can see the complete code here: https://codesandbox.io/s/sass-jzgxv

*__P.S: this excludes, of course, the scenario in which fetch returns nothing so then we'll have to check for null responses.__*
 *Image source: @divinetechygirl on Pexels*
MT(my thoughts) - A note tool can record your thoughts in terminal
Tags: showdev, productivity, go
Published: 2020-04-29 05:19:10

---
title: MT(my thoughts) - A note tool can record your thoughts in terminal
published: true
description: A tool can record thoughts in terminal
tags: showdev, productivity, go
---

I write a tool that can record thoughts in the terminal. So as long as you have a terminal, you can conveniently record and manage your thoughts.
 
Some use case: iterm, vscode terminal, any server terminal.

I just released the first version. Hope somebody would like it. 🍻

{% asciinema 325041 %}

{% github https://github.com/daoleno/mt %}