teleren/devto huggingface dataset:
Quick Notes for Go os/exec
Tags: go, beginners
Published: 2020-10-25 13:07:29

Golang's os/exec package is tricky to use. For beginners, you might have a lot of questions like
- How to use os/exec with multiple parameters?
- Why the cwd of the exec call is not what I have assigned?
- How to pass piped command into the exec function call?

In this notes, I will show some quick examples on how to use os/exec with some conditions that is kind of common if you are working on a project that requires interaction to other software binary / system commands.

## ⌨ A very basic os/exec function call
Lets start from here, this is a basic exec function call and the results are returned in "out" as []byte
```
func main() {
	cmd := exec.Command("ls", "-lah")
	out, err := cmd.CombinedOutput()
	if err != nil {
		log.Fatalf("cmd.Run() failed with %s\n", err)
	}
	fmt.Printf("combined out:\n%s\n", string(out))
}
```

## 🌲 os/exec function call with extra Environment variable
```
cmd := exec.Command("programToExecute")
additionalEnv := "FOO=bar"
newEnv := append(os.Environ(), additionalEnv)
cmd.Env = newEnv
out, err := cmd.CombinedOutput()
if err != nil {
	log.Fatalf("cmd.Run() failed with %s\n", err)
}
fmt.Printf("%s", out)
```

## 📁 Set the cwd of the execution path
```
cmd:= exec.Command("git", "log")
cmd.Dir = "your/intended/working/directory"
out, err := cmd.Output()
```

Notes: If you are calling a binary instead of a variable / program inside the ENV variable (or %PATH% in Window's case), use the absolute path of the binary. For example
```
abspath, _ := filepath.Abs("./mybinary")
cmd:= exec.Command(abspath, "log")
cmd.Dir = "your/intended/working/directory"
out, err := cmd.Output()
```

## ⌨️ Use os/exec with Linux pipe / bash commands
```
rcmd := `iw dev | awk '$1=="Interface"{print $2}'`
cmd := exec.Command("bash", "-c", rcmd)
out, err := cmd.CombinedOutput()
if err != nil {
	log.Println(err.Error())
}
log.Println(string(out))
```

## 🖥️ Use os/exec with Windows Batch commands
```
cmd := exec.Command("cmd", "/c", "ffmpeg -i myfile.mp4 myfile.mp3 && del myfile.mp4")
out, err := cmd.CombinedOutput()
if err != nil {
	log.Println(err.Error())
}
log.Println(string(out))
```

## 📑 Use string slice in os/exec function call
```
args := []string{"hello", "world"}
cmd := exec.Command("echo", args...)
out, err := cmd.Output()
if err != nil {
    fmt.Println(err)
}
fmt.Println(string(out))
```

## 🍆 Solving localization problem in Windows CMD for os/exec
This is suitable for developers that is using a non-Unicode supported version of Windows with default codepage of cmd localized in not English language.
```
cmd := exec.Command("cmd", "/c", "chcp 65001 && netsh WLAN show drivers")
out, err := cmd.CombinedOutput()
if err != nil {
	log.Println(err.Error())
}
log.Println(string(out))
```

Notes: Remember to remove the first line of the output which should be a confirmation of successfully changed codepage using chcp command

If you find this useful, feel free to share or bookmark this article 😉
Aspiring Fullstack Developer
Published: 2020-10-25 13:04:14

I made a mistake of slacking off in college, i had the ability to learn but i chose to go bare minimum just so i could graduate. With much regret i switched to Linux and studied hard as hell on freecodecamp.org and other resources to become a Full-stack developer. i love programming, and i should have done my best and not the bare minimum effort just because i was being lazy.
JavaScript Programming Problem 2
Tags: javascript, codenewbie, coding, interview
Published: 2020-10-25 13:03:31

# JavaScript Programming Problems Series
I started Programming test series where i will be sharing  share commonly asked interview questions and my solution for JavaScript developers . 

##  Problem # 2 
### Count the number of individual vowels in a given string 
 you are given a string, count and return the number of vowels used in that string. for example if string has **a** four times and **e** two times  it must return 
 ```
{ 
   a:4,
   e:2 
 } 
```

## My Solution
```
const vowelCount = (str)=>{
    str = str.toLowerCase().split("");
    const vowel = "aeiou";
    const obj = {}

    for(let wo of str){
    if(vowel.indexOf(wo) !== -1){
        if(obj[wo]) {
        obj[wo] ++
        }
        else {
        obj[wo] = 1
        }
      }
    }


return obj
}

vowelCount("3123dasds JJKH e o a eee iJ")
```
Share your possible solution
Net Neutrality
Tags: lis160
Published: 2020-10-25 12:17:56

The principle of net neutrality states that Internet Service Providers should not be able to control what their customers do on the internet by prioritizing or discriminating against certain content. This comes in the form of providing slower service for certain sites or preventing users from accessing them. 

In the case of the Philippines, net neutrality is not in effect. ISPs freely choose to prioritize some sites over others. An example of this would be the free data that can be used to access Facebook, but not other sites.

The lack of net neutrality is in fact a large problem in the Philippines. When ISPs give out "free" access to some sites over others they are essentially funneling their customers into using that site. This is especially a problem when that prioritized site is a site like Facebook that tailors it's content to individual users, regardless of the trustworthiness of that content. Users that rely on free Facebook will not be able to access links to more reputable news sites, or cross reference anything they see on Facebook with news on another site. According to Rappler, this dependency on Facebook has lead to an online platform where fake news and armies of trolls abound.

It is clear that by limiting access to some information you prevent people from forming opinions about it. Prioritizing some sites over others and curating the content people can access effectively prevents them from formulating truly informed opinions.

References:

Curiae, A. (2017, Dec 28). *Net neutrality in the philippines.* BusinessWorld. [https://www.bworldonline.com/net-neutrality-philippines-necessary/](https://www.bworldonline.com/net-neutrality-philippines-necessary/)

Public Knowledge. (2017, Dec 14). *Net neutrality.* Public Knowledge. [https://www.publicknowledge.org/issues/net-neutrality/](https://www.publicknowledge.org/issues/net-neutrality/)

Rappler. (2019, Aug 25). *8chan founder: Filipinos not accessing the 'real internet'.* Rappler.[https://www.rappler.com/technology/8chan-founder-filipinos-not-accessing-the-real-internet](https://www.rappler.com/technology/8chan-founder-filipinos-not-accessing-the-real-internet)
Daily Developer Jokes - Sunday, Oct 25, 2020
Tags: jokes, dailydeveloperjokes
Published: 2020-10-25 12:00:29

---
title: "Daily Developer Jokes - Sunday, Oct 25, 2020"
description: "Check out today's daily developer joke! (a project by Fred Adams at xtrp.io)"
series: "Daily Developer Jokes"
cover_image: "https://private.xtrp.io/projects/DailyDeveloperJokes/thumbnail_generator/?date=Sunday%2C%20Oct%2025%2C%202020"
published: true
tags: #jokes, #dailydeveloperjokes
---

Generated by Daily Developer Jokes, a project by [Fred Adams](https://xtrp.io/) ([@xtrp](https://dev.to/xtrp) on DEV)

___Read about Daily Developer Jokes on [this blog post](https://xtrp.io/blog/2020/01/12/daily-jokes-bot-release/), and check out the [Daily Developer Jokes Website](https://dailydeveloperjokes.github.io/).___
### Today's Joke is...
![Joke Image](https://private.xtrp.io/projects/DailyDeveloperJokes/public_image_server/images/5e1258cecd22f.png)

---
*Have a joke idea for a future post? Email ___[xtrp@xtrp.io](mailto:xtrp@xtrp.io)___ with your suggestions!*

*This joke comes from [Dad-Jokes GitHub Repo by Wes Bos](https://github.com/wesbos/dad-jokes) (thank you!), whose owner has given me permission to use this joke with credit.*

<!-- 
Joke text:
___Q:___ Why did the computer squeak?

___A:___ Because someone stepped on its mouse!
 -->
Keyboards - Full size, TKL, or other?
Tags: discuss, watercooler
Published: 2020-10-25 11:55:21

Following the discussion about keyboards and [does backlighting matter](https://dev.to/_garybell/keyboards-does-backlighting-matter-2m56) I'm wondering whether there's a preference for a Full size keyboard, a TKL (no number pad) or something smaller?

Personally, I find myself drawn always to a full-size keyboard. Mainly because I use 2FA a lot (so lots of numbers to enter to log in), plus I have spreadsheets to maintain and use the calculator a lot.

None of those tasks are impossible with a TKL or smaller keyboard, but I'd have to get used to using the top row of numbers, rather than the side. It can be overcome with training.
Spooky inter process communication at a distance
Tags: shell, unix, bash
Published: 2020-10-25 11:18:23

---
title: Spooky inter process communication at a distance
published: true
tags: shell, unix, bash
---


I recently needed to write a script that can accept input from another script started with systemd timer. FIFO is a no go because of... reasons (also what's the fun of that :D), which leaves me with this fun hacky solution.

The trick we are going to use is the fact that process' information can be accessed under `/proc/[pid]/`. For example, we can use `/proc/$$/comm` to get the complete command line of the current process, and more importantly for us, `/proc/$$/fd/0` is the current process' file descriptor 0. And of course `$$` is just using shell to get the current process id.

To achieve what we want, we just need to get the pid, then write to the process's stdin. However, it is not as straightforward. We can access file descriptor 0, but writing to it does not write to the process' input per se. Because file descriptors point to a file, be it tty or actual file. When we “write” to `/proc/$pid/fd/0` we are actually writing to the underlying file, that does not necessarily mean the input will get sent to the processes, it depends on what kind of file we are talking about, for example, writing to a tty will only print it on screen. As It turns out, a pipe would work perfectly for our case, which means some unfortunate cat abuse.

```sh
# script_a.sh

cat | grep -o 'I want input'
```

```sh
# script_b.sh

echo 'did someone say "I want input"?' > /proc/$(pgrep grep)/fd/0
```

## further reading
https://unix.stackexchange.com/a/385948: A great answer for something very similar to what we are doing. It explains which kind of file has what effect when being written to.
AWS AppSync + WAF is here! Now let's CDK + CF it!
Tags: aws
Published: 2020-10-25 10:58:01

At this start of this month AWS [announced](https://aws.amazon.com/about-aws/whats-new/2020/10/aws-appsync-adds-support-for-aws-waf/) support for AWS WAF with AppSync! If you're a fan of AppSync you might be keen on this as the WAF will give you an easy way to add an extra layer of security to your app.

#### AppSync
As a high-level intro, AppSync is a GraphQL managed API service and is gaining popularity in the app dev space. There are some pretty good built-in security features out of the box like DDoS, SOC and ISO compliance plus others.

#### Demo stack
For this demo I've thrown in a bunch of services just to show the folks reading what a CDK stack or full app stack in AppSync might be like. I haven't seen any demos which show this type of setup so hopefully it's of interest.

You'll get the following:
* AppSync API
* Cognito authentication
* DynamoDB as a datasource
* WAF

On top of the above I've configured the services to integrate together and applied a few options like prohibit guess sign up for cognito.

#### Cloudformation
I've generated the cloudformation stack and supplied a deploy stack button which is available in the open source github repo:

https://github.com/talkncloud/aws/tree/main/appsync-waf

All that is needed to deploy the stack is to click the button and login to your amazon account. Everything happens in your account and you review the code if that helps.

#### CDK
The CDK repo is in the same place, simply **cdk deploy** and you're good to go. 

#### Clean up
A note on clean up, when you delete the stack the DynamoDB table will be left behind, be sure to remove it when you're done.

#### More info
If you are deploying WAF to an existing AppSync deployment check out my detailed post below. If you apply the core ruleset to AppSync requests will be blocked but there is a workaround in the post:

https://www.talkncloud.com/aws-appsync-with-waf-wooo-cdk-cf/

#### Question
I am keen to hear from others about their AppSync setup and how you're managing your deployment, other than CDK & CF there are some cool accelerators out there so I'm interested to see if others are using them.
My first hacktoberfest
Tags: hacktoberfest
Published: 2020-10-25 10:32:04

<!-- ✨This template is only meant to get your ideas going, so please feel free to write your own title, structure, and words! ✨ -->

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/vikezh4z41uqsptoc1kd.png)
### About me
<!-- If you are new to the DEV community, introduce yourself and share a bit about why you joined DEV and decided to participate in Hacktoberfest this year.  --> 
Hi everyone! I am Shubhankar. I am a CSE student and currently a junior. In my sophomore phase, I was very intrigued by the world of open sourcing and it would always be a weird puzzle for me to even understand the term `git` LOL!! I am always excited about learning new stuff though my endurance might be a bit low on sticking to plan.

I like to travel a lot, especially to places which attract the crowd because I love observing people. Apart from that I also like being a tech-geek (I am not but I want to be).
### Background

<!-- Are you brand new to open source? What about coding in general? Tell us about how you got here →
My first exposure to open source was in my freshman year due to some talks of some of the seniors. But my close encounter has been with this open-source community when I was involved in a backend team as the head for building up a website for our institute.

### Progress

<!-- Share a bit about where you’re at in your Hacktoberfest journey. What stage are you at? How has the process been?  -->

Hacktoberfest has been a very nice journey. The full month of October I was busy in my semester exams as well. But by the end of the month somehow I could finish off with my PRs and I have overall made 7 PRs till now in the month of October.


### Contributions

<!-- This is where you can list the contributions you made and explain why you chose the projects you did. Don’t forget to add links!  -->
My interest area is in Angular, javascript and C++, and these contributions justify my choices of working with these issues.

- [todo-app](https://github.com/DevTony101/js-todo-app-indexed_db/pull/5)
- [subreddit-cloud](https://github.com/itsmais/word-cloud-subreddit/pull/5)
- [refactoring web-app](https://github.com/openMF/web-app/pull/1264)
- [refactoring web-app](https://github.com/openMF/web-app/pull/1259)
- [linting practice in C++](https://github.com/DXHeroes/dx-scanner/pull/467)

### Reflections
<!-- Overall, how has your Hacktoberfest 2020 experience been? If you’re a first-timer, will you participate again? What have you learned? Have you made any interesting connections? What is your next step in open source?  -->
The exposure that I got in Hacktoberfest was worth it. I could establish proper communications, had many discussions with the code maintainers as well. Learnt much during each process of making a PR. I was also introduced to some industry-level standards as well.

I will continue and explore repositories and if some idea resonates would try to contribute to it further. 

Looking forward to a much more enriching experience.
How to deploy Ingress with Tilt
Tags: tilt
Published: 2020-10-25 10:22:02

<sub><span>Photo by <a href="https://unsplash.com/@helloimnik">Hello I'm Nik 🎞</a> on <a href="https://unsplash.com/s/photos/process">Unsplash</a></span></sub>

[Tilt](https://tilt.dev/) is an amazing tool to deploy easily services to your local kubernetes file.

But how to deploy ingress with tilt ?

Luckily, browsing tilt issues, i have found this [github](https://github.com/jazzdan/tilt-ingress-objects-example) containing an example.

```yaml
load('ext://namespace', 'namespace_create', 'namespace_inject')

namespace_create('ambassador')

k8s_yaml('ambassador-operator-crds.yaml')
k8s_yaml(namespace_inject('ambassador-operator-kind.yaml', 'ambassador'))
k8s_yaml('ingress-example.yaml')

k8s_resource('ambassador-operator', objects=[
    'ambassadorinstallations.getambassador.io:customresourcedefinition',
    'ambassador-operator:serviceaccount',
    'ambassador-operator:role',
    'ambassador-operator-cluster:clusterrole',
    'ambassador-operator:rolebinding',
    'ambassador-operator-cluster:clusterrolebinding',
    'static-helm-values:configmap',
    'ambassador:ambassadorinstallation',
])

k8s_resource(new_name='ingress', objects=['example-ingress'], resource_deps=['ambassador-operator'])
```

It creates the namespace through a [tilt plugin](https://github.com/tilt-dev/tilt-extensions), and load the yaml resources that will be used using [k8s_yaml](https://docs.tilt.dev/api.html#api.k8s_yaml).

It then creates the ambassador operator using [k8s_resource](https://docs.tilt.dev/api.html#api.k8s_resource). Please note that the : is used to split name from kind.

Finally, it create the ingress.

Hope this helps !
How to extract all links in a website using Python
Tags: python, codenewbie, tutorial, webscraping
Published: 2020-10-25 10:18:10


Hello Pythonistas,
In this tutorial, you’re going to learn how to **extract** all links from a given website or URL using BeautifulSoup and requests.

If you’re new to web scraping I would recommend starting first with [beginner tutorial to Web scraping](https://kalebujordan.com/web-scraping-in-python-tutorial/) and then move to this one once you get comfortable with the basics.

### how do we extract all links?
We will use the **requests** library to get the raw **HTML** page from the website and then we are going to use **BeautifulSoup** to extract all the links from the HTML page.

### Requirements
To follow through with this tutorial you need to have [requests](https://requests.readthedocs.io/en/master/) and [Beautiful Soup]( https://www.crummy.com/software/BeautifulSoup/bs4/doc/) library installed.

#### Installation

```bash
$ pip install requests
$ pip install beautifulsoup4
```

**Below** is a code that will prompt you to enter a **link** to a **website** and then it will use **requests** to send a *GET* request to the server to request the **HTML** page and then use **BeautifulSoup** to *extract* all link tags in the HTML.

```python
import requests
from bs4 import BeautifulSoup
​
def extract_all_links(site):
    html = requests.get(site).text
    soup = BeautifulSoup(html, 'html.parser').find_all('a')
    links = [link.get('href') for link in soup]
    return links
​
site_link = input('Enter URL of the site : ')
all_links = extract_all_links(site_link)
print(all_links)
```

Output:
```python
kalebu@kalebu-PC:~/$ python3 link_spider.py
Enter URL of the site: https://kalebujordan.com/
​
['#main-content', 'mailto://kalebjordan.kj@gmail.com', 
'https://web.facebook.com/kalebu.jordan', 'https://twitter.com/j_kalebu',
'https://kalebujordan.com/'.....]
```
Hope you find it useful, now share it with your fellow developers 

The [Original Article](https://kalebujordan.com/learn-how-to-extract-all-links-from-a-website-in-python/) can be found on [kalebujordan.com](https://kalebujordan.com/)
Github Action : Workflow Files Sync
Tags: github, git, productivity
Published: 2020-10-25 10:15:49

This Github Action can come in handy when you have lot of projects like i do. where in some case certain projects users action workflow which are common across projects. Example : `Project 1` & `Project 2` it can be pain to keep all the workflow updated with Github Action's Module's version.

This also isn't limited to Github Action yaml files.
Another use case could be keeping the `.editorconfig`, `LICENSE`, `tsconfig.json`, `tslint.json`, `.gitignore`, `azure-pieplines.yml`, etc. in sync across all your repositories.

> Here where this action comes in and reduces your stress 😉 it can update all your repository actions file based on the config provided

# How Files Sync Work ?

Before copying the `WORKFLOW_FILES` from the source to destination. this action will provide some flexibility. this searches for a file in various locations for example lets take `settings.yml` as the file that you want to sync for multiple repository

#### Below are the locations that this action search for the file/folder
* `./{OWNER}/{REPO_NAME}/workflows/{filename}`
* `./{OWNER}/workflows/{filename}`
* `./{WORKFLOW_FILES_DIR}/{filename}`
* `./.github/workflows/{filename}`
* `./{OWNER}/{REPO_NAME}/{filename}`
* `./{OWNER}/{filename}`
* `./{filename}`

> if the `settings.yml` is found inside `workflows` folder then the destination is automatically forced to `.github/workflows` in the destination repo
>
> if the `settings.yml` is outside of `workflows` folder then the destination then its copied to the destination

### How this can be useful ?
Lets assume that you want to maintain all the common github files in a single repository and suddenly a repository needs a single file to be changed in that case instead of editing the action yml file. you can just create a folder like `{REPO_OWNER}/{REPO_NAME}/{FILE}` to copy the overriden file to the destination

 {% github varunsridharan/action-github-workflow-sync %}
Front-End, Back-End or Mobile App Development?
Tags: webdev, career, codenewbie, discuss
Published: 2020-10-25 10:11:21

Why do you do what you do what makes it so interesting for you? We live in a world where you have freedom of choice why did you choose to work in your current development environment? I started out as a Front-End Developer and back then the thought of purely working on the Back-End did not appeal to me because I am very visual and I always enjoyed seeing my work come to life in a browser window. 

These days I am more split as my skills are more diverse. But I can imagine that a purely Front-End developer would have no desire to play around with databases. Similarly a Back-End developer would prefer to work on the architecture instead of trying to put together a design using HTML and CSS and having to deal with all of those browser quirks. And then of course there is mobile app development and creating apps.

So what area of development gives you the most passion and if you are a Software Developer or a Full-Stack Developer which area of development gives you the most enjoyment and why?