teleren/devto huggingface dataset:
PHP Tips: How to Read Remote Text File and Download to Local
Tags: php, beginners
Published: 2020-03-25 09:02:02

Who still use PHP? Raise your hand! Hahaha. OK, because of self-explanatory title, here is how to do it. We will use several functions on PHP for this purpose, such as `fopen`, `feof`, `fgets`, `fwrite` and `fclose` functions. Yes, that's lower level functions.

## Scenario
Suppose we have remote text file stored on a website, let's called it 
```
https://bolabanget.id/myfile.json
```
We want to create a PHP script that download that file (`myfile.json`) to our local computer with name (`myfile.local.json`).

Here is the script.

## The Code

File: `download_file.php`

```php
<?php
// open the source file with read-only mode
$source = fopen('https://bolabanget.id/myfile.json', "r") or die("Unable to open file!");
// prepare local file with write mode (if not exists it will try to create one)
$target = fopen('myfile.local.json', 'w') or die("Unable to open file");

// prepare variable for content of the source file
$content = '';

// tests for end-of-file on a source file pointer
while(!feof($source)) {
  // fgets will get line from file pointer
  $content .= fgets($source);
}

// write the $content variable to target file handle
fwrite($target, $content);

// close all open files from our operation above
fclose($source);
fclose($target);
```

Run it like below.

```
php download_file.php
```

If everything OK, you should have file `myfile.local.json` on your current folder.

## Alternative Code

[@hepisec](https://dev.to/hepisec) comes with additional alternative on comments, we can do above task as well with the following code. This code using higher level functions such as `file_get_contents` and `file_put_contents`. Thank you!

```php
<?php
$src = file_get_contents('https://bolabanget.id/myfile.json');
file_put_contents('myfile.local.json', $src);
```

I hope you enjoy it and any additional code or comments are welcome.

## Credits
- PHP Documentation at https://www.php.net/manual/en/
- Cover photo by Christina Morillo at https://www.pexels.com/photo/two-women-looking-at-the-code-at-laptop-1181263/
- Thanks to [@hepisec](https://dev.to/hepisec) for the additional code
Should Robots Ever Look Like Us
Tags: darrenhuston, robots, engineering
Published: 2020-03-25 08:42:32

	
Humanoid robots are a recognizable trope in popular culture, but do machines look a bit creepy and possibly harmful like us?

Whether it’s the robotics books by Isaac Asimov, the 1980s film character Johnny 5, Hollywood’s Avengers: The Age of Ultron or the sci-fi drama Humans by Channel 4, there has long been a fascination with robots becoming sensitive in popular culture-humans who can experience emotions and human-like consciousness.

But how realistic is the prospect of robots that become almost indistinguishable from humans-and desirable?


Ben Goertzel, the creator of Sophia, a Hanson Robotics-based social humanoid robot from Hong Kong, thinks that robots should look like humans to assist “break down doubts and reservations that individuals may have” about interacting with them.

“Because individuals like them, you’ll have humanoid robots,” he informs the BBC. “They’d rather give orders or complain about their girlfriend to a humanoid robot than to the Roomba [a vacuum cleaner robot].” “I think [Softbank’s] pepper robot is very ugly. It’s kind of like a rolling kiosk. Sophia’s going to look at you in the eye; it’s going to mirror your facial movements.

There are now 20 Sophia robots in existence, six of which are used worldwide to deliver speeches and show the technology.

Companies have approached Hanson Robotics with an interest in using Sophia to greet their clients, but, Mr Goertzel acknowledges, humanoid robots such as Sophia and Pepper are still very costly to produce.

Source: https://ceojournals.com/tag/darren-huston/
FREE COURSES - Laravel Daily 100% discount codes.
Tags: offers
Published: 2020-03-25 08:10:14

Get all of [Laravel Daily's](https://laraveldaily.teachable.com/) courses for free, its difficult to overstate how much value is in these courses.

They have helped me with my personal career, to become a better developer.

I'm a huge fan of Povilas Korop he is doing great work in the Technical community. Want to get to grips with Laravel, and make something, have a look at this free mini-course. https://lnkd.in/dnTkv7d

In addition, you can use this discount code to get all of his courses at 100% off **STAYHOME**.

His work on [Structuring Laravel Projects](https://laraveldaily.teachable.com/courses/475842) is probably one of my favorite online courses I have ever consume and it helped me to expand my overall knowledge of backend development patterns.

Enjoy

Matt
How to create route in OpenShift?
Tags: openshift, redhat, kubernetes, devops
Published: 2020-03-25 08:04:36

### Objective
- Access application via Service IP within cluster
- Access application via Service IP outside cluster
- Create route
- Access application via HTTP Route
- Create Edge Terminating Route
- Access application via HTTPS Route

#### Step 1: Deploy Nginx application
Refer [How to manage Users & Project in Openshift?](https://dev.to/sagarjadhv23/learn-how-to-manage-users-project-in-openshift-15ni)

#### Step 2: List services
```
oc get svc
```

#### Step 3: Access application via service ip within cluster
```
curl http://<SERVICE_IP>:80
```

#### Step 4: Access application via service ip outside cluster
```
From browser, Browse http://<SERVICE_IP>:80
```

#### Step 5: Create route
```
oc expose service <SERVICE_NAME>
```

#### Step 6: Describe route
```
oc get route
```

#### Step 7: Access application via HTTP route
```
From browser, Browse http://<ROUTE_URL>
```

#### Step 8: Create self-signed certificates
```
openssl genrsa -out example.key 2048
```
```
openssl req -new -key example.key -out example.csr -subj "/C=US/ST=CA/L=Los Angeles/O=Example/OU=IT/CN=test.example.com"
```
```
openssl x509 -req -days 366 -in example.csr -signkey example.key -out example.crt
```

#### Step 9: Create edge terminated route
```
oc create route edge --service=nginx --key=example.key --cert=example.crt
```

#### Step 6: Describe route
```
oc get route
```

#### Step 7: Access application via HTTPS route
``` 
From browser, Browse https://<ROUTE_URL>
```

{% youtube yO-PECEA-Nc %}
Algorithm 101: 2 Ways to FizzBuzz a Range of Numbers
Tags: algorithms, javascript, beginners, fizzbuzz
Published: 2020-03-25 07:29:43

In the [last article](https://dev.to/ebereplenty/algorithm-101-4-ways-to-fizzbuzz-a-single-number-380d), we looked at how we can fizzBuzz a signle number. This article is taking us further to how we can fizzBuzz a range of number. It is going to however, depend upon the ``function`` from the last article - [4 Ways to FizzBuzz a Single Number](https://dev.to/ebereplenty/algorithm-101-4-ways-to-fizzbuzz-a-single-number-380d).

```javascript
fizzBuzzRange([1, 9]) 
/* 
  1
  2
  Fizz
  4
  Buzz
  Fizz
  7
  8
  Fizz
*/
fizzBuzzRange([30, 25])
/*
  FizzBuzz
  29
  28
  Fizz
  26
  Buzz
*/
```
Are you already thinking it out? I will be showing you 2 ways to do this both for a descending range (example: from 9 to 1) and ascending range (example: from 1 to 9)

### Prerequisite
To benefit from this article, you need to check out the [preceding article](https://dev.to/ebereplenty/algorithm-101-4-ways-to-fizzbuzz-a-single-number-380d) and possess basic understanding of javascript's array methods.

### Let's FizzBuzz a Range of Numbers Using:

* if...statement and for...loop

```javascript
      function fizzBuzzRange(array) {
        if (array[0] < array[1]) {
          for (let i = array[0]; i <= array[1]; i++) {
            console.log(fizzBuzz(i));
          }
        }

        if (array[0] > array[1]) {
          for (let i = array[0]; i >= array[1]; i--) {
            console.log(fizzBuzz(i));
          }
        }
      }
```

* switch...statement and while...loop

```javascript
      function fizzBuzzRange(array) {
        switch (array[0] < array[1]) {
          case true:
            counter = array[0];
            while (counter <= array[1]) {
              console.log(fizzBuzz(counter));
              counter++;
            }
            break;

          case false:
            counter = array[0];
            while (counter >= array[1]) {
              console.log(fizzBuzz(counter));
              counter--;
            }
            break;
        }
      }
```

### Conclusion

There are many ways to solve problems programmatically. I will love to know other ways you solved yours in the comment section.

> Up Next: [Algorithm 101: 3 Ways to Get the Fibonacci Sequence](https://dev.to/ebereplenty/algorithm-101-3-ways-to-get-the-fibonacci-sequence-1i1c)

If you have questions, comments or suggestions, please drop them in the comment section.

You can also follow and message me on social media platforms. 

**[Twitter](https://twitter.com/eberetwit) | [LinkedIn](https://www.linkedin.com/in/samson-ebere-njoku-profile/) | [Github](https://github.com/EBEREGIT)**

Thank You For Your Time.
Is there good Ruby/Rails repos to read and learn good architecture/coding manners?
Tags: question, discuss, ruby, rails
Published: 2020-03-25 06:53:14

---
title: Is there good Ruby/Rails repos to read and learn good architecture/coding manners?
published: true
description: 
tags: question, discuss, ruby, rails
---

Recently, I've found that reading other's code can bring a lot of new ideas and best practices. Spy good examples of specs or clean architecture examples.

If you know something well-written and covered with specs, or code which inspired you lately, please drop a line in comments.

Cheers! Appreciate every link 🤓
Leer la salida de un comando desde vim
Tags: bash, vim
Published: 2020-03-25 06:52:50

---
title: Leer la salida de un comando desde vim
published: true
description: Dentro de vim se puede ejecutar un comando del shell y ver la salida como un archivo
tags: bash, vim
---
Dentro de `vim` se puede ejecutar un comando escribiendo 
```vim
<esc>:!comando
```
![ejecutando :!pwd](https://dev-to-uploads.s3.amazonaws.com/i/vxeglw2bsm0ip8x3sbvj.png)

Esto da como resultado
![salida :!pwd](https://dev-to-uploads.s3.amazonaws.com/i/opurwqtn5uk70nwu1dtt.png)

Pero si esta salida la queremos directamente dentro de `vim` se puede emplear
```vim
<esc>:read !comando
```
![ejecutando :read !pwd](https://dev-to-uploads.s3.amazonaws.com/i/lq5ycd9e9114gaiw4yob.png)

Con lo que obtenemos
![salida :read !pwd](https://dev-to-uploads.s3.amazonaws.com/i/jwj2bo86ap0f8ezs3o59.png)
Git commit amend: Way to quickly fix last commit mistakes
Tags: git, adviceandopinion, gitamend, sourcecontrol
Published: 2020-03-25 07:14:03

---
title: Git commit amend: Way to quickly fix last commit mistakes
published: true
date: 2020-03-25 06:52:13 UTC
canonical_url: https://automationhacks.io/2020/03/25/git-commit-amend-way-to-quickly-fix-last-commit-mistakes/
---

A quick post on how git amend command can help you fix and change your last commit if you want to add something more or have made a mistake.

![jelleke-vanooteghem-kabtmcdcAbk-unsplash.jpg](https://automationhacksblog.files.wordpress.com/2020/03/jelleke-vanooteghem-kabtmcdcabk-unsplash.jpg?w=1100)

Photo by [Jelleke Vanooteghem](https://unsplash.com/@ilumire?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText) on [Unsplash](https://unsplash.com/s/photos/oops?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText)

## A mistake

First, a little bit of context, Let’s say you are starting a new Kotlin project with Gradle. The first usual thing to do is to check in a `.gitignore` file with directives to ignore certain IDE generated files.

I wanted to ignore any temporary files generated by Gradle which are typically situated in `.gradle` folder among the IDE files generated by IntelliJ in `.idea` folder.

So I added below in the `.gitignore` file:

```
gradle/
.idea/
```

And then went ahead with adding and committing my changes

```
git add .git commit -m "Ignore IDE files and gradle generated files"
```

## Oops

However, when I checked my current files, I could still see a lot of the Gradle temporary files.

Turns out, Instead of adding `.gradle` folder, I added `gradle` (Notice the missing dot) ![🤦🏻‍♂️](https://s0.wp.com/wp-content/mu-plugins/wpcom-smileys/twemoji/2/72x72/1f926-1f3fb-200d-2642-fe0f.png)

## The fix

Well, A quick fix would be to just change the `.gitignore` file and update to:

```
.gradle/
.idea/
```

And then add and commit with a new message right?

Well, That is how I used to do things **before!**

I wouldn’t ideally **like** to not show this trivial mistake in my git history when I can fix it. And why to necessarily clutter the git history with these small fixes.

Turns out Git has this awesome command that we can use.

In this particular case, I want to change the files that were checked in the last commit and maybe add some new files as well.

We can just stage any new files or change files that we need and execute below

```
git commit --amend --no-edit
```

This would  **modify** your last commit files and retain the message

If you want to even change the message, Just add `-m <msg>` to this command

```
git commit --amend -m "an updated commit message"
```

## Conclusion:

Use **git amend** if you have made a mistake and fix your last commit. Note, This changes your last commit and it would not be recoverable.

Overall this is a very nice command to have in your git toolbox and allows you to have a better Git history.

The wonderful folks at Atlassian have written an even detailed blog on this. [Check it out.](https://www.atlassian.com/git/tutorials/rewriting-history)
Guys! Learn Git!
Tags: git, challenge, learngitinanhour
Published: 2020-03-25 06:50:31

Alrighty, guys, this will be a super short post, cuz I am just trying to make a challenge called #learn-git-in-an-hour, yes, learn it in an hour, I just finished it and hope this challenge can give you the courage to learn git, good luck! 
(If you finished, remember to comment below!)
How to implement the functionality to host any web app on a given domain through a single command similar to the discourse?
Tags: webdev, help, mernstack, seniordevs
Published: 2020-03-25 06:38:37

---
title: How to implement the functionality to host any web app on a given domain through a single command similar to the discourse?
published: True
description: The functionality to set up on to the server should be like this [!click](https://www.linuxhelp.com/how-to-install-discourse-on-ubuntu-16-04)
tags: web-dev, help, MERN-STACK, Senior-Devs
---
Leadership in times of crisis
Tags: leadership, discuss
Published: 2020-03-25 06:33:23

---
title: Leadership in times of crisis
published: true
description: What is the most important thing you can do as a leader in time of crisis: ensure a continuous, open, and honest communication in your team
tags: leadership, discuss
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/c6uj330zm00w4iujguag.jpg
---

As we enter uncharted waters in our workplaces, many delving into working remotely for the first time, we as leaders must step up to the circumstances and **lead**.

In these times of uncertainty we must ensure that we maintain an ongoing, open, and honest communication with and within our team.

Most of us are used to work colocated, where we can just pop up to a colleague's desk to ask a question or discuss a problem. And even though we have likely been using online chat applications like Slack, MS Teams, or the like, we know that those are not the right forums for nuanced conversations.

Everyday, as we have our *daily forum* (standup is a loaded word for me), I remind my team to jump on a video call to discuss the work at hand with each other. We have the tools to make this work, it's just a case of forming a new habit.

Forming habits, and breaking habits, is hard, so our job is to help our teams form the habits that will make them succeed in these times of crisis.

So what's the most important habit we need to help our teams develop?

> COMMUNICATION, COMMUNICATION, COMMUNICATION

How are you leading your team to succeed? I look forward to hear and learn from your insights!
Embedding Graphs Into Your Sphinx Documents
Tags: python, documentation, sphinx, graphviz
Published: 2020-03-25 21:17:28

---
title: Embedding Graphs Into Your Sphinx Documents
description: Embed GraphViz ‘dot language’ graphs into your documentation, and hot-link the nodes to any HTTP resource.
published: true
date: 2020-03-25 05:00:00 UTC
tags: python, documentation, sphinx, graphviz
cover_image: https://jhermann.github.io/blog/images/copied_from_nb/img/python/sphinx-ext-graphviz.png
canonical_url: https://jhermann.github.io/blog/python/documentation/2020/03/25/sphinx_ext_graphviz.html
---
> *Embed GraphViz ‘dot language’ graphs into your documentation, and hot-link the nodes to any HTTP resource.*

The [sphinx.ext.graphviz](https://www.sphinx-doc.org/en/master/usage/extensions/graphviz.html) extension allows you to directly embed GraphViz ‘dot language’ graphs into your document files. They are then rendered to PNG or SVG images, which get added to your generated HTML documentation. Using SVG allows you to hot-link your nodes to any HTTP resource.

Before use, you have to activate the extension with just a few changes to your `docs/conf.py`
```python
extensions = [
    # …
    'sphinx.ext.graphviz',
]

# …

# -- GraphViz configuration ----------------------------------
graphviz_output_format = 'svg'
```
This is an example for what you can then add to your documentation:

![Sphinx and GraphViz Data Flow](https://jhermann.github.io/blog/images/copied_from_nb/img/python/sphinx-ext-graphviz-sample.svg)

As long as the nodes have a `href` attribute, the SVG rendering contains them and thus node labels become clickable hyperlinks.

And here's the related markup that needs to be added to one of your `.rst` files:
```json
.. graphviz::
    :name: sphinx.ext.graphviz
    :caption: Sphinx and GraphViz Data Flow
    :alt: How Sphinx and GraphViz Render the Final Document
    :align: center

     digraph "sphinx-ext-graphviz" {
         size="6,4";
         rankdir="LR";
         graph [fontname="Verdana", fontsize="12"];
         node [fontname="Verdana", fontsize="12"];
         edge [fontname="Sans", fontsize="9"];

         sphinx [label="Sphinx", shape="component",
                 href="https://www.sphinx-doc.org/",
                 target="_blank"];
         dot [label="GraphViz", shape="component",
              href="https://www.graphviz.org/",
              target="_blank"];
         docs [label="Docs (.rst)", shape="folder",
               fillcolor=green, style=filled];
         svg_file [label="SVG Image", shape="note", fontcolor=white,
                   fillcolor="#3333ff", style=filled];
         html_files [label="HTML Files", shape="folder",
                     fillcolor=yellow, style=filled];

         docs -> sphinx [label=" parse "];
         sphinx -> dot [label=" call ", style=dashed, arrowhead=none];
         dot -> svg_file [label=" draw "];
         sphinx -> html_files [label=" render "];
         svg_file -> html_files [style=dashed];
     }
```
For all this to work, you need the [GraphViz suite of tools](https://www.graphviz.org/) installed on the machine that renders the documentation.
can't declare url and path variables useRouteMatch in class
Tags: react, javascript
Published: 2020-03-25 04:10:42



Now i do so:
```
constructor(props) {
    super(props);
    let r = useRouteMatch();
    this.path = r.path;
    this.url = r.url;
}
```
but this does not work and throws errors: url is not defined, if i use them in render()
This code is indicated in the documentation:
```
let {path, url} = useRouteMatch();
```
It works for functional programming, not for class. How to declare these variables in this as one line? Or something
Number Theory: Primality Test in O(sqrt(n))
Tags: numbertheory, datastructures
Published: 2020-03-25 03:48:23

A number is said to be prime if it is divisible by a number other than 1 and itself.
<b> 1 is not considered to be a prime number.</b>

`Primality Test` is to determine whether the input integer is a prime number or not.

For instance,

5: Prime Number
12: Not a prime number
7: Prime Number
14: Not a prime number

For instance, 12 is prime because it is divisible by 2,3 and 6.

## Approach 1

```
bool isPrime(int n) {

  if (n == 1) {
    return false;
  }

  for (int i = 2; i < n; i++) {
    if (n % i == 0) return false;
  }

  return true;
}
```
In this method, we traverse from 1 to n, hence the time complexity, in this case, is: `O(n)`.

## Approach 2: The Better One

Now, consider a pair `a*b = n`. Here, a and b are the factors of n.
For instance,

```
n = 12
(a,b) can be (1,12),(2,6),(3,4)
```

On observing the equation, we can infer that the maximum value of a and b can be the square root of n.

`sqrt(n)*sqrt(n) = n`

Since, if both of the values go beyond `sqrt(n)`, then `a*b` would be greater than n.

Also, If a is less than `sqrt(n)`, then b will be greater then `sqrt(n)`.
Similarly, if a is greater than `sqrt(n)`, b will be smaller than `sqrt(n)`.

We can conclude that one of the numbers is `<= sqrt(n)`, and the other one is `>= sqrt(n)`.

And to prove that n is prime, we just need to find one of the numbers - a or b.
If no such number exists, it means that n is not prime.

Hence, to do the primality test, we need not run loop till n, this can be done by running the loop till `sqrt(n)` itself.

```
bool isPrime(int n) {

  if (n == 1) {
    return false;
  }

  for (int i = 2; i*i < n; i++) {
    if (n % i == 0) return false;
  }

  return true;
}
```



<b>Note:</b> Using the libraries such as `sqrt()` can sometimes give unexpected values. Hence, instead of checking for `i < sqrt(n)` in the for loop, we check for `i*i< n`.

The loop runs from 2 to `sqrt(n)`, hence the time complexity would be `O(sqrt(n))`.

Keep Coding! :)