teleren/devto huggingface dataset:
How to write a php class that calculates the factorial of an integer?
Tags: fuctorial, php, class
Published: 2020-02-16 01:39:58

Let's understand the two key terms used above;

- FACTORIAL - the product of an integer and all the integers below it; e.g. factorial four ( 4! ) is equal to 24.(4 X 3 X 2 X 1)

- INTEGER - Integer is a number which is not a fraction, you could also say that an integer is a whole number

COOL!

Now let's solve the problem, the class we are asked to write has two main requirements

1) It should filter out the integers 
2) It should return the factorial of that filtered number/integer

To meet 1) above we can use the function is_int() in php , so using the if condition with this function, we could say "if (!is_int(n)) { Do not run the program or perhaps throw an error}"

To return a factorial of a number we can Loop through all the numbers that are less than or equal to the integer that was passed in-while storing the product of all the numbers  in a variable that can be returned when the loop is over. 

Here's a way of doing this,

```
<?php

public function myFactorial()
{

$factorial = 1;

for($i= 1; $i<=$this->number; $i++)
{
  $factorial = $factorial*$i;
}

return $factorial;

}
?>

```

Why are we doing; 

$factorial =  $factorial*$i

And whats the meaning of it ?

$i in the above line is changing each time we loop (ie. it starts at 1 and increments till it reaches the value of the integer that was passed in)

Left hand side $factorial is assigned the product of right hand side $factorial and $i in each iteration.

Let's say we wanted to find the factorial of 3. (then  $this->number would be 3)

First iteration - we will have the following values

$i = 2 , Right hand side $factorial = 1; (although $i starts with one it will be incremented by one during the first iteration as we have $i++ in the for loop)

Therefore  Left hand side $factorial = 1 multiplied by 2 .(ie. 2)

Second iteration 

$i = 3 , Right hand side $factorial = 2;

Therefore Left hand side $factorial = 2 multiplied by 3 . (ie. 6)
 

Ok will there be a third iteration?  "NO" WHY?

Next iteration , $i = 4 and we have a condition in the for loop that says 'Continue the loop as long as $i is less than or equal to 3'.  

Here's the complete solution;

```
<?php

Class find_my_factorial
{

  protected $integer;
   
  public function __construct($passedInt)
  {
    if(!is_int($passedInt))
      {
            throw new InvalidArgumentException('Not a valid integer');
      }

      $this->integer = $passedInt;  
    
  public function myFactorial()
  {
    $factorial = 1;
    for($i = 1; $i<= $this->integer; $i++) 
     {
       $factorial = $factorial *$i;
     }
   return $factorial;
  }
}

//Instantiating the above class,

$Twofact = New find_my_factorial(2);

echo $Twofact->myFactorial();

?>
```
Makers Week 12: The End of the End
Tags: makers, unreal, debugging
Published: 2020-02-16 23:24:39

Weakly Goal:

*Can you use high-quality processes to build an extended project in a team?*

This week was the final week of our final project and our final week of the Makers course. The final week was fun if a little stressful but that's to be expected. But we got it done, it looked good and most importantly it worked.

Day 1

So over the weekend, I started on damage types while I was learning about them I found out something useful called *structures*. Structures are a list of variable that you can add to a blueprint. This was invaluable to me it meant I could add type advantages and weaknesses to each of the enemies. It also allowed me to add types to the attacks too. We also decided to change our project to do a free roam game instead of a turn-based battle game. This wasn’t hard to do because we already had all the things we needed it was just a matter of making some small tweaks.

Day 2

I got started on the damage types on day two because I knew about structures already this was a lot easier than I was expecting. Although it still took some time to set up. I spent the rest of the day trying to solve a bug that popped up the enemies weren't taking any damage. After a while, I thought I'd be better for me to get some rest and look at it with fresh eyes in the morning.

Day 3

So Wednesday I spent the morning fixing the bug the problem was I was casting to the wrong enemy. The reason that was happening was when we split off into different branches we were working on separate enemies. We also started the preparation for our presentation which we had to do Friday we split the presentation into sections I was given the closing section on development tools so a lot of technical talk which gave me a chance to sharpen my knowledge.

Day 4

There was a feature freeze on Wednesday so we stopped adding things and started working on animations. I was doing the spell and attack animations which were a lot of fun. But I also had to make sure to blend animations so that they would look smooth. It was nice to get to throw in some cool looking animations, they tied everything together.

Day 5

The final day we had to three o'clock to get everything done we had to get everything up and running. We had a couple of bugs but we managed to get them working with time to spare so we could practice our presentation. Luckily we got to do our showcase first which gave me a chance to explain our project which gave me a lot more confidence for the presentation and I think it went quite well.

Summary

This was a stressful week due purely because it was the final week but we got everything done. We also had a beautiful looking game and I learned a lot. If I were to do it again it'd a lot easier. Even the presentation went well although it was nerve-racking. So overall an amazing week and let job hunt begin!!
Difference between tilde and caret in package.json
Published: 2020-02-16 10:42:54

Difference between tilde and caret in package.json
If you have updated your npm to the latest version and tried installing the package using npm install moment — save you will see the package moment.js get saved in packages.json with a caret(^)prefix and in the previous version it was saved with tilde(~)prefix. You might think what is the difference between these symbols.
The tilde prefix simply indicates that the tilde (~) symbol will match the most recent patch version or the most recent minor version i.e. the middle number. For example, ~1.2.3 will match all 1.2.x versions but it will not match 1.3.0 or 1.3.x versions.
The caret indicates the first number i.e. the most recent major version. An example is in 1.x.x release the caret will update you and it will match with 1.3.0 but not 2.0.0.
Blender Destructive Physics
Tags: blender
Published: 2020-02-17 01:34:07

Standard Blender with Bullet is missing python callbacks for collision events.  Work is underway now to integrate ODE Physics with Blender2.83. In this is the first stage of integration, a new object property `breakable` will trigger my modified cell fracture script to run, and smash your mesh apart when it hits the ground.  Collision and fracture events can also be scripted, allowing you to attach a python script to the on-collision and on-fracture events.  

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

Metaballs also work with ODE in Blender, and can split apart on collision with the ground.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/rwpv04uwom5rqcrshjuc.gif)
Running (debugging) a bash script line-by-line
Tags: bash, debugging, coding, linux
Published: 2020-02-17 02:50:23

The other day I was running a `Bash` script. It wasn't working as expected so it needed some debugging.

I needed a quick-and-dirty solution.

After some googling, I found this answer. It ended up being quite easy and handy.

All you have to do is place this line on the top of your script and Bash will prompt you after executing every line. Hitting `enter` key is enough to execute the next line of your script.

```
#!/usr/bin/env bash
set -x
trap read debug

< YOUR CODE HERE >
```

It is reported that this works "with bash v4.2.8 and v3.2.25."

For me, it worked like a charm.

Here is the [original answer in stackoverflow](https://stackoverflow.com/questions/9080431/how-execute-bash-script-line-by-line/9080645).

<hr />

Do you have other tips for debugging Bash? I'd like to know.
Code Smell: Side Effects — Solution
Tags: codesmells, webdev, productivity, javascript
Published: 2020-02-17 17:07:49

Recently I wrote about a particular code smell: Side Effects. Several people called me out for not providing a suggested fix to the identified problem. If you didn't read the original article, you can find it [here](https://is-tracking-link-api-prod.appspot.com/api/v1/click/5078485544730624/5570275139911680). You will want to be familiar with what I wrote to continue on here with the solution.

In that article, we saw how we have a side effect in our loadUser function. Let's go through options for addressing this code smell.

Our first task is to look at the calling code. Ultimately this is where the code smell is coming from because it's in the calling code that we SHOULD be handling the responsibility of emptying the cart, but instead, it got put into the loadUser function.

Let's look at some example calling code.

![image](https://cdn-images-1.medium.com/max/800/0*lOld_pgWdZTTfUig?)

Here our handleUserLogin method first creates a new empty user, sets it into the session object's user variable, and finally asks the session to load the User. It's inside this call that the cart is emptied. This is the crux of our issue. That operation of loading the user has some specific tasks. But it's ALSO emptying out the cart. That is perfectly appropriate in the situation of handling the user login. But if we ever needed to load user data and didn't want the side effect of emptying out the cart to happen, (maybe while refreshing data from the server) we don't have that option. A function should only do one thing. The loadUser function does two.

So let's fix that by extracting the cart.empty call out of the loadUser function. The simplest answer is just to move it up one level into our calling code.

![image](https://cdn-images-1.medium.com/max/800/0*_DLWWCYy8BkmrmqV?)

And our loadUser is now clean of side effects:

![image](https://cdn-images-1.medium.com/max/800/0*1WMAzYx6HlOdXOum?)

Now, when someone else comes along and calls loadUser, they will get the result they want, and no unnecessary side effects.

Happy Coding!

Signup for my newsletter at [here.](https://is-tracking-link-api-prod.appspot.com/api/v1/click/4616255200034816/5570275139911680)
Visit Us: [thinkster.io](https://thinkster.io/) | Facebook: @gothinkster | Twitter: @GoThinkster
SVG/ReactJS math patterns
Tags: codepen
Published: 2020-02-17 06:07:25

---
title: SVG/ReactJS math patterns
published: true
tags: codepen
---

<p>I have always been crazy about math generating drawings. So here you are. Using ReactJS to generate SVG can be very interesting. Do share your favourite drawing by writing the Step, Subtract and Accelerate values in a comment :-)
I have saved some examples in the dropdown, try viewing them.
To inverse colors: Click/touch drawing.
UPDATED: Copy SVG to clipboard, Select line type</p>

{% codepen https://codepen.io/netsi1964/pen/qqXBmx %}
PHP extract PPTX or PPT powerpoint files format to TXT Example
Tags: php, pptx, ppt
Published: 2020-02-17 07:55:12

        function pptx_to_text($input_file){
            $zip_handle = new ZipArchive;
            $output_text = "";
            if(true === $zip_handle->open($input_file)){
               $slide_number = 1; //loop through slide files
               while(($xml_index = $zip_handle->locateName("ppt/slides  /slide".$slide_number.".xml")) !== false){
                $xml_datas = $zip_handle->getFromIndex($xml_index);
                $xml_handle = DOMDocument::loadXML($xml_datas, LIBXML_NOENT | LIBXML_XINCLUDE | LIBXML_NOERROR | LIBXML_NOWARNING);
               $output_text .= strip_tags($xml_handle->saveXML());
               $slide_number++;
            }
            if($slide_number == 1){
                $output_text .="";
            }
           $zip_handle->close();
       }else{
           $output_text .="";
       }
          return $output_text;
     }
Chingu Weekly 106
Tags: career
Published: 2020-02-19 19:10:49

---
title: Chingu Weekly 106
published: true
description: 
tags: #career
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/802hw7bylz7qie93ejsd.jpeg

---



## News, Shout-outs & Showcases

🔥Check out this article by Matthew Burfield called [Auto deployment to now.sh and Heroku from Github](https://dev.to/chingu/auto-deployment-to-now-sh-and-heroku-from-github-2p8)! 


🔥A [Favorite Fonts app](https://chingu-solo.github.io/solo-koala-128/index.html) from @ makneta! 
 

🔥@ nellie wrote this awesome article called Lessons from [Blue Collar - How soft skills can come from customer service experience}(https://dev.to/nelliesnoodles_90/lessons-from-blue-collar-bg4). 


🔥Here is an Adam Shaffer wrote called [Looping over arrays and objects in JavaScript](https://medium.com/chingu/looping-over-arrays-and-objects-in-javascript-57e1188c1ba2
)! 


## Overheard in Chingu


>Does my oldest son's wedding this Saturday count as my wife's Valentines Day present?
work for valentines day - perfect.
You know what would be nice, if github had a way to make an in between two repos system. Like, the front-end html goes through the in between, to a backend, backend stuff gets added, and that file, separate goes into the in between too. So changes just aren't all master branch, and front/back can easily compare file alterations that are done, and it's easier for either one to pull a single file over to either side without conflicts.
I actually don't buy waffles so I don't know when they go on sale.
waffles are pretentious pancakes
I'm doing a project right now and I've decided to simply make the most insanely semantic html layout for it as possible. I think I've been focused too much on visual design of a page instead of the legit straight-up content. I'm making a page like it's 1991, then I'll bring the design into current century :) 
HELLO EVERYONE!!
someone find me a web dev who is a cat person!


## Resource of the week

From @ kish! 

>"I had a lot of trouble deploying my react-app to a Github user page (not project page) last week and found a very handy solution. It is not straightforward so I wrote a Medium article on how to do it." 

https://medium.com/@kishandth.sivapalasundaram/how-to-deploy-your-react-app-to-a-github-user-page-d4b925cf5543


## Meme to go
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/y52n64ne6odqg5z72s7k.png)
where can i find more DEVs worth following ?
Tags: watercooler, smn, bmn
Published: 2020-02-17 11:23:39

it seems that some great DEVs are shy and dont create many posts ! so how can i find and follow them ?

here are a couple of ideas 

* follow people who have commented on other peoples posts
* reverse lookup people who have created DEV [github bugs](https://github.com/thepracticaldev/dev.to/issues?q=is%3Aissue+is%3Aopen+label%3A%22type%3A+bug%22) 
* reverse lookup people who have created DEV [github feature requests](https://github.com/thepracticaldev/dev.to/issues?q=is%3Aissue+is%3Aopen+label%3A%22type%3A+feature+request%22)

BTW DEV-DEVs you do know you have ~200 open bugs and ~300 open feature requests ? oooh :lightbulbmoment: maybe thats 500 starter projects right there for coing `#newbies`

are there any more ways to find DEVs worth following ?
I made a bash script to help automate adding new ssh keys
Tags: ssh, bash, showdev, zsh
Published: 2020-02-17 17:47:50

At my work, we have tons of ssh keys that we store in central repo. We have to move them to our `.ssh` folder so we can ssh into server. But you also need to set the permissions on the key file after you move it.

I started to get annoyed with having to set permissions every time so I created a bash file to automate this.

```bash
#!/bin/bash

# add_ssh_key - A script to move ssh key and set permissions

##### Constants

SSH_DIR=~/.ssh/


# Check for path
if [ -z "$1" ]; then
   echo "Please provide the path to the ssh key" 
   exit 1
fi

cp $1 $SSH_DIR
chmod 600 $SSH_DIR$(basename $1)
echo "Copied ${1} to .ssh dir and set permissions to 600"
```

I also have a [gist](https://gist.github.com/GeorgeNance/2a00ab91f225c84ae89b1abbbbbcb489) for it

Download and move that to whatever bin folder you have and run 
`chmod +x` on the filename. For me, I made a bin folder at `~/bin` but you can put it wherever you want.

Then add an alias to your `.bashrc` or whatever file your terminals sources. For me that is a file called `.zshrc`

```bash
alias add_ssh_key="~/bin/add_ssh_key.sh"
```

Then open up a new terminal and you should be able to run:

```bash
add_ssh_key path/to/current/key
```
And pretso! 🎉  You have a key with proper permissions.

Thanks for reading! Let me know any ssh automation you have set up.
Harmony Modern Slim Boilerplate [NEED Upgrade]
Tags: help, php, slimphp
Published: 2020-02-17 22:10:43

---
title: Harmony Modern Slim Boilerplate [NEED Upgrade]
published: true
description: 
tags: help, php, slimphp, discuss
---

Harmony Modern Slim Boilerplate [NEED Upgrade]

I'm still developing and refactoring code, coz migrate from @slimphp 3 to 4 is a little bit hard. So give me time or anyone can help me past through.

Github Repository: [Harmony Modern Slim Boilerplate](https://github.com/harmony-betta/harmony/tree/dev-master)
Documentation: [Harmony Modern Slim Boilerplace Docs](https://bettadevindonesia.github.io/harmony-betta)
Online Business Ideas You Can Start Today
Tags: career, productivity
Published: 2020-02-17 22:57:25

# Blogging

Blogging about your favorite topic is a low cost, low-risk way to produce something that is valuable to people. When you create value for people then you'll receive money. Money is made through selling products, books, consulting services, affiliate marketing and more.

With 10000+ visits a month, you can make money without much trouble. Ads are also a great way to monetize your traffic if you have this much traffic.

Once you find a web host to host your blog, you can make money fast.

# Become An Affiliate Marketer

Once again, a blog is a way to promote affiliate products. Companies also provide affiliate links for people to click to buy their products. If your blog has traffic, then you can promote your affiliate links with your blog.

# Sell Your Own Images and Designs

You can sell your own designs and photos online on many websites. If you have a talent for creating designs or photography, you can get people to buy them if you promote them to enough people.

Also, you can put your images of T-shirts, bags, hats, greeting cards, calendars and more and make more money.

# Build Apps

If you know how to program, then building apps is a great way to make money online. There're still lots of problems that need solving by people with apps. You just have to find out what people have problems with and then solve those problems accordingly.

Apps can be custom solutions for business and also mass-market solutions for a large audience.

# Buy and Sell Domains

A lot of domains are available for sales and many are popular because of their name. We can get ideas from domain auction sites to see what people like, and then we can buy the ones that are popular and then flip them for a profit.

# Conclusion

These are a few ways to make money online with varying amounts of upfront costs.  We can make money off these ideas by experimenting with which ones of these take off for you. It takes time and perseverance to succeed, so you've to prepare not to give up even when times are tough.
React Concurrent Mode
Tags: react
Published: 2020-02-18 03:27:50

---
title: React Concurrent Mode
published: true
description: Regardless of all the optimizations, we do in React apps, rendering process so far has been blocking and cannot be interrupted. With the introduction of new experimental React Concurrent Mode, rendering becomes interruptible.
tags: React
---

![Post](https://seanamarasinghe.com/static/085dadaf056ee052570cfac51cb8a17d/76843/feature.jpg)

## Previous workarounds

Debounce and throttle are common workarounds to mitigate for example stutter in an input field while typing.

Debounce – Only update the list after the user stops typing Throttle – Update the list with a certain maximum frequency

Similar to git branches
Concurrent Mode is like React working on git branches.

Eg:- Navigating between two screens in an app

In React Concurrent Mode, we can tell React to keep showing the old screen(like another git branch), fully interactive, with an inline loading indicator. And when the new screen is ready, React can take us to it.

Read more about React Concurrent Mode [in this article](https://seanamarasinghe.com/developer/react-concurrent-mode)
MESG testnet using Cosmos & Tendermint
Tags: javascript, blockchain, cosmossdk, tendermint
Published: 2020-02-18 09:15:46

The MESG Foundation is building a blockchain of executions powered by the community's sharable microservices and processes. They're using Cosmos & Tendermint to build the network(s), and just released a new testnet.

## New testnet

The new testnet was published on January 15th, 2020. It uses four validators spread around the world.

One validator is located in San Francisco, another is in Singapore, the third is in Frankfurt and the final validator is in Toronto. Four was chosen because it is the number of validators needed to tolerate a situation in which a single validator stops, or acts maliciously, without affecting the blockchain.

The goal of this testnet is to learn how the blockchain behaves under real-world conditions. We haven’t stress-tested the network yet, but this will come in the following weeks, so stay tuned :)

## Explorer

Feel free to [check out the network Explorer here](https://explorer.testnet.mesg.com/?utm_source=devto).

We also connected Grafana to the testnet for additional monitoring. The monitoring tool can be found [here.](https://monitoring.testnet.mesg.com)

For additional information on the testnet, head over to https://docs.mesg.com/guide/network, or to start your Engine on the testnet, execute the following command:

```
mesg-cli daemon:start --network mesg-testnet-01 --path $HOME/.mesg-testnet-01
```

## What's next?

Next, we will be working on updating the Engine to a classic Cosmos-SDK architecture, which will allow us to reuse the existing tools in the Cosmos ecosystem, while also allowing us to share the tools we create with the other parts of the Cosmos ecosystem. [Here are some of our recent contributions.](https://github.com/search?utf8=%E2%9C%93&q=user%3Atendermint+user%3Acosmos+author%3Anicolasmahe+author%3Aantho1404+author%3Akrhubert&type=Issues&ref=advsearch&l=&l=)

Also, we will be working on enabling the Engine to run in specific roles, such as orchestrator, service manager, or blockchain validator-only configurations. The goal of this is to reduce the computational requirements of individual Engines, thus allowing more users to run their own Engine.

View the [full article here](https://blog.mesg.com/mesg-product-update-february-20/?utm_source=devto).
How to start a comic blog like xkcd
Tags: help
Published: 2020-02-18 10:22:53

---
title: How to start a comic blog like xkcd
published: true
tags: help
---
Hello,
I was wondering if someone with blogging experience could give me some insights about it. I already have someone with drawing skills and we have some strips ready; My doubts were about the technologies we should use (wordpress, asp.net + angular spa etc), the hosting..
Any help is appreciated!