teleren/devto huggingface dataset:
Day26:regex - 100DayOfRust
Tags: rust
Published: 2019-12-29 00:32:59

You can do regular expression in Rust with 3rd-party crate `Regex`.

In `Cargo.toml`:

```
[dependencies]
regex = "1.3.1"
```

In `main.rs`:

```rust
use regex::{Regex, RegexBuilder, Captures};

fn main() {
    // use r"" to define a raw string
    let re_str1 = r"^(\d{4})-(\d{2})-(\d{2})$";
    let target1 = "2019-12-29";
    let re = Regex::new(re_str1).unwrap();
    // use is_match to check if there is a match
    println!("Is match: {}", re.is_match(target1));

    // iterate all captures
    let re_str2 = r"(\d{4})-(\d{2})-(\d{2})";
    let target2 = "Article created on 2019-12-28, updated on 2019-12-29";
    let re = Regex::new(re_str2).unwrap();
    for cap in re.captures_iter(target2) {
        println!("Year: {} Month: {} Day:{}", &cap[1], &cap[2], &cap[3]);
    }

    // replace
    let re_str3 = r"(\d{4})-(\d{2})-(\d{2})";
    let target3 = "Blog posted on 2019-12-29";
    // use RegexBuilder to create new regex with case-insensitive
    let re = RegexBuilder::new(re_str3)
                            .case_insensitive(true)
                            .build()
                            .unwrap();
    
    let replaced = re.replace(target3, |caps: &Captures| {
        format!("{}/{}/{}", &caps[2], &caps[3], &caps[1])
    });

    println!("Replaced: {}", replaced);
}
```

Result: 

```
Is match: true
Year: 2019 Month: 12 Day:28
Year: 2019 Month: 12 Day:29
Replaced: Blog posted on 12/29/2019
```
Five ways to be productive and finish your projects
Tags: productivity
Published: 2019-12-29 00:00:40

It's the new year, it's even a new decade. What better time to make a new year's resolution. Mine is to be more productive, and to finish more of my own personal projects. 365 days from now, I want to look back and see a nice collection of finished projects. How am I going to do this? I've decided on five rules.

![Infographic showing five ways to finish your projects in 2020](https://thepracticaldev.s3.amazonaws.com/i/k26rnk3i9s2h9d8j48m0.png)

My whole idea centres on the concept of keeping up momentum by doing small, specific pieces of work every day, that all work towards a pre-planned goal. The goal isn't rigidly defined, and is more a direction to go in, but it's specific enough to keep on track.

## Have an objective

Know where you're going. I have a calendar, for each month there is a mini project to complete. By the end of the year I should have 12 completed mini projects. Over time these projects might change, but at the moment I have 12 and that's the main goal.

## Take bitesized chunks

From experimenting, I have about a three week attention span when doing a single piece of work. After week three I am usually bored, or have derailed myself with something else. To help with this, each month long project has a definite end, and I've allowed myself the final week to document the project.

## Do your research

I'm not going into this with a vague plan. The projects I have chosen all fit together and build on each other to produce things greater than their individual parts. To achieve this I've been doing research and collecting information that will help. Already this has made me cut down on some things I want to do, and helped me discover far more interesting projects than I'd originally thought up.

## Review your progress

It's important to stop and reflect regularly. I'll do this monthly to make sure I remember the end goal, and haven't distracted myself with a random side quest. It also means I can maintain momentum by seeing how far I've come.

## Keep going

Small, continual, regular efforts are far more useful than large infrequent bursts of activity. Doing something daily means it's always in your mind, so starting the task becomes easier. It also makes it harder to miss a day.

_Another New Year's Resolution for 2020 of mine is to maintain this blog much more frequently. I have a suspicion that a more frequently updated blog attracts more traffic, and if I see visitors coming here, I'll be more motivated to add content. Build long term goals into your plans for the days when you're really unmotivated!_
Default values in JavaScript
Tags: javascript
Published: 2019-12-29 00:00:00

---
title: "Default values in JavaScript"
date: "2019-12-29"
description: "How I think about default values in JavaScript"
published: true
tags: JavaScript
---

# How I think about default values in JavaScript

First of all, all these things can fall under the Opinions, Concerns, and Nitpick umbrella. The most important thing is just giving thought to the things you have opinions about and always reserve the right to be corrected.

My simple rule of thumb is to try to set initial state to whatever the eventual state will be for Objects and Arrays.

Strings and numbers default to undefined.

## Describing usage

### Problems defaulting to undefined:

A lot of times I am just trying to describe how state will be used, so setting values that will be used later as `undefined` will give future users some understanding of what state might exist

```javascript
// bad
const initialState = {
  // type string
  name: undefined,
  // type number
  age: undefined,
  // type array of strings
  cars: undefined,
  // type deep object {height: string, shoeSize: number}
  metaData: undefined,
}
// initialState.cars.map()
// > TypeError: initialState.cars is undefined
// console.log(initialState.metaData.shoeSize)
// > TypeError: initialState.metaData is undefined
```

Defaulting to `undefined` has been a safer choice overall in my experience, because other authors tend to not set object properties befefore usage, or they might just not exist on some JSON you get back from a server

### Problems defaulting to null:

any time you want to use `typeof` you will need to check for two values. This is super error prone. `typeof initialState.name !== "object" && typeof initialState.name === "string"`

```javascript
// Bad
const initialState = {
  name: null,
  age: null,
  cars: null,
  metaData: null,
}
// typeof initialState.name
// > "object"
// initialState.cars.map()
// > TypeError: initialState.cars is null
// console.log(initialState.metaData.shoeSize)
// > TypeError: initialState.metaData is null
```

### Problems defaulting to the values type

```javascript
const initialState = {
  age: 0, // is 0 a valid age?,
  name: "", // will someone typeof === 'string' and also have to check length?
}
```

### Preference

My preference, which has in my experience been less error prone. The only time I will use null as a default is if some API I am using uses null, and that will be used in state.

1. It describes to future users what state will be availble
2. It is less error prone than other default types as described above
3. It does not limit the `typeof` operator
4. It does not tend to give as many false positives

```javascript
const initialState = {
  age: undefined,
  name: undefined,
  cars: [],
  metaData: { height: undefined, shoeSize: undefined },
}
// typeof initialState.name
// > "undefined"
// initialState.cars.map()
// > works, no error
// console.log(initialState.metaData.shoeSize)
// > undefined
```
Why did Array.from()work?
Tags: javascript, beginners, explainlikeimfive, help
Published: 2019-12-28 23:57:32

I'm watching Shaun Pelling's Modern JavaScript course on Udemy (great way to get started, by the way) — and I just worked through an example that doesn't seem like it should have worked.

The challenge was to iterate through all of the elements within an `article` tag and add a class to each one:

```html
<article id="example-article">
  <h2>Article Title</h2>
  <p>Lorem ipsum dolor sit amet consectetur adipisicing elit.</p>
  <p>Lorem ipsum dolor sit amet consectetur adipisicing elit.</p>
  <p>Lorem ipsum dolor sit amet consectetur adipisicing elit.</p>
  <div>Written by the Some Person</div>
</article>
```
Selecting `querySelector` returns an `HTMLCollection`, which can't be iterated through by using `forEach()`. Instead Shaun recommended using the `Array.from` method and iterating through that instead.

Cool! Easy enough:

```javascript
const article = document.querySelector('#example-article');

const articleContents = article.children;

let copiedContents = Array.from(articleContents);

copiedContents.forEach(child => {
	child.classList.add('article-element');
});
```

And that's it. The DOM was updated with the new classes. Here's my question:

I thought `Array.from()` made a new array from the information in the `HTMLCollection`. I thought for sure that I was going to have to do something like `article.innerHTML = [...copiedContents]` or something, but I didn't have to copy the new array back into the article element *at all*. In fact when I `console.log(article.children);` I get:

```
HTMLCollection(5)
​
0: <h2 class="article-element">​
1: <p class="article-element">​
2: <p class="article-element">​
3: <p class="article-element">​
4: <div class="article-element">
​
length: 5
```

How?
When the exit switch is under your nose and you still miss it
Tags: psychology
Published: 2019-12-28 23:54:29

Ever been so stuck to a particular train of thought that you become tunnel-blind, unable to see the exit switch directly underneath your nose? I have been there, realized that I was in a groove I did not wish to occupy, and broke out of my box, so to speak.

This concerns games and the engines powering them... as a game maker who also wrote a game engine, I became unintentionally tied to its conventions and limitations, to the point that I could not see how to make games any other way. This meant that expanding my horizons suddenly became very difficult; it's the equivalent of digging yourself into a 100-meter hole and only realizing what happened after you are down there.

To break out, I had to force myself to think differently; playing games as well as making them led me to think like a game designer when playing, and after doing this for a while, I had one of those *A-HA!* moments: I saw where I had erred. Now that I know this, many more doors are now open!

(For the curious, my game engine was written in Java, using Swing GUI components, and I became incapable of making games without Swing GUI components. This meant I could not build for mobile devices, along with a host of other limitations from the engine's design. Now free of these chains, I can now do things I've always wanted to, but the engine would not let me do.)
Problem based learning
Published: 2019-12-28 23:11:59

> Software development should be easier to learn

Linked lists, Binary trees, Hash maps, Hash Sets, Big O…

You do need to know all the things mentioned above to become a Software Engineer, but you likely don’t need to know everything to start creating on the web.

What the team at [that good company](https://thatgoodcompany.com) is trying to do is to lower the barrier of entry and make it easier for everyone to start learning and creating for the web.

**How?**

By solving challenges that have all the setup in place, with a clear small goal that will make you realize how certain aspects of the web work.

**Will it work?**

We hope so! problem-based learning has had some great results around the world. The fact that you’re actively learning instead of passively learning it’s a key factor. Passive learning is necessary but it needs to be complemented with action.

**What’s next?**

We’ll be publishing code challenges for you to solve with a variable difficulty level.

## thank you

We want to acknowledge some of the great products and open source projects that are empowering web creators in so many different ways that make it easy for you to create, have a great experience and publish your work: [Next JS](https://nextjs.org), [Zeit](https://zeit.co), [Svelte](https://svelte.dev), [CodeSandbox](https://codesandbox.io) among others that we’ll keep mentioning and using for our challenges.
Stan's Links #3
Published: 2019-12-28 23:05:37

https://www.scrumguides.org/scrum-guide.html#acknowledgements

https://bl.ocks.org/taigereye/10a79a8d5b18a7c3d2833e79231351d8

https://www.w3schools.com/js/js_json_arrays.asp

https://stackoverflow.com/questions/49481934/fetching-local-json

https://www.quora.com/In-JavaScript-how-do-I-read-a-local-JSON-file

https://github.com/d3/d3

https://www.youtube.com/watch?v=nzshmMlOuwI

https://d3js.org/
Java lambda expression 
Published: 2019-12-28 17:06:00

Java is a language multiple platform that used by the most developers. 
After java 8 oracle add a lot of features to java like lambda

All  know anonymous class that we can implement method of class in time executing time 

Lambda is just anonymous class that implement a one method of interface

**Lambda syntax**

```java

// first
l = ()->{ statements };
// second
l = (arg,arg2,arg3,...args)->{ statements };
// third
l = (n)->n; is like (n)->{ return n;};

```
*** Lambda rules *** 

- lambda implement just a one interface and interface most have a one method
- lambda can take 0,* args
- lambda can be implement anywhere
- lambda can be return by any method
- lambda can not be returning by itself
- lambda can be passed as args

** Let begin with simple example **

```java


 interface  says {
     public void show();
 }

public class Lambda  {


    public static void main(String[] args) {

            says  msg = ()->{ System.out.println("hello world");};
            msg.show(); // hello world
        
    }



}

```

**Lambda example with args**

```java

 interface  says {
     public void show(String name);
 }

public class Lambda  {


    public static void main(String[] args) {

           says msg = (name)->{ System.out.println("hello world "+ name );};
            msg.show("jamal"); // hello world jamal
        
    }



}
```

** Lambda with return by another method **

```java




 interface  says {
     public void show(String name);
 }

public class Lambda  {

    public static says m(String msg){


        return (name)->{ System.out.println(msg+" "+name);};
    }


    public static void main(String[] args) {

         m("hello world").show("jamal");

         m("hello world").show("mohammed");
        
    }



}

```

** passing Lambda as arg of a method **

```java 



 interface  says {
     public void show(String name);
 }

public class Lambda  {

    public static void m(says l,String name){

        l.show(name);


    }


    public static void main(String[] args) {
       
         m((name)->{

                System.out.println(name);

         },"hello");

         m((name)->{

             for (int i=0;i<name.length();i++) {

                 System.out.println(name.charAt(i));
                 
             }
         },"hello world");
    }



}



```


the last example is most used in practice 

Java had do a effort to integrate lambda but it's just anonymous class ,
while JavaScript has arrow function that very easy to use
Do a little more testing!
Tags: softwaredevelopment, testing, leadership, coding
Published: 2019-12-28 22:39:15

---
title: Do a little more testing!
published: true
description: 
tags: softwaredevelopment,testing,leadership,coding
---

Even when you’re confident in your work, add a bit of extra caution for good measure.

When you think you have a fix, don’t say so right away. Verify more than you want to.

If youre not careful, you can make mistakes and cost everyone’s time. It won’t be a huge deal, but it’ll be annoying and a little embarrassing.

You’ll want to show all your coworkers what a great engineer you are. You can see the whole thing end to end - it works, it makes sense! Isn’t that great? Ship it!

It takes some emotional maturity to resist that temptation. You have to be deliberate about pumping the breaks.

Even in the most agile and fast-moving organization, the experienced developer knows to mix the excitement with a healthy dose of caution. Move fast, but try not to break things. 😄
Do you scale?
Tags: scale, careerdevelopment, coding, leadership
Published: 2019-12-28 22:36:53

---
title: Do you scale?
published: true
description: 
tags: scale,careerdevelopment,coding,leadership
---

As an engineer, “You don’t scale.”

A very senior manager once told me this as career advice. The point was, to advance your career, you will need to manage people and climb the corporate ladder. You can only write so much code in a day, so your impact has an upper limit. Is this true?

![Scale](https://thepracticaldev.s3.amazonaws.com/i/g9udkav61bzn9ph1cone.png)

In software development in particular, we think a lot about scale. We like our solutions to scale. It’s one of the holy grails of a great product. So we tend to tacitly assume that our careers must scale, too. Suggesting otherwise is like telling us our code is buggy: it’s counter to our intuition, and probably our ego.

Somewhere in every dev’s consciousness is the mythology of the 10Xer: A great engineer can increase their team’s productivity by an order of magnitude or more. There’s exaggeration and truth in this.

Yes, even great developers can only do so much in a day. Whether you work for a startup or a big company, you’re just one piece of a larger machine that can have many bottlenecks. And typically devs are viewed as a part of operating costs. They’re a necessary evil as far as the balance sheet is concerned. They don’t create revenue; they’re just needed to help the business deliver on its commitments.

But bad development and management decisions can certainly cause a project to advance 10 times slower. In software, where complexities multiply at every turn, clarity is golden. And that comes from experience.

Today more than ever, it’s possible to have an outsized impact. For one thing, consider the power of online content. A great developer can evangelize and build community around a technology by giving talks, creating content and interacting on social media.

Also, in this age of digital transformation and heightened consumer expectations, technology architecture is becoming more enmeshed with business decisions. Retailers, construction companies and mom-and-pop shops alike must take their stack seriously just to provide an adequate experience for their customers, let alone get a competitive edge. If [“every company is a software company,”](https://news.microsoft.com/en-gb/2018/11/07/microsoft-ceo-satya-nadella-on-fuelling-tech-intensity-in-the-uk/) even the suits need to be technical.

So personally, I don’t worry about not scaling. I try to have faith that if I keep learning and building stuff, good things will happen. Software (and, uh, life?) is magical like that.
Linux commands useful when performing heavy processing
Tags: linux, commands
Published: 2019-12-28 22:18:57

---
title: Linux commands useful when performing heavy processing
published: true
description: Linux commands useful when performing heavy processing
tags: Linux,commands
---

## sleep

The `sleep` command suspends processing for a certain period of time.

For example, when running a heavy shell script, using the sleep command moderately can reduce the load.

```
# Delay 10 seconds(no option)
sleep 10

# Delay 10 seconds
sleep 10s

# Delay 5 minutes
sleep 5m

# Delay 3 hours
sleep 3h
```

## nice/renice

The `nice` command can be executed with priorities.

For example, when performing a backup or batch process, the process can be performed without affecting other processes.

You will be able to batch process more safely, even at lunchtime when the website is crowded by many people.

```
# Without option, run at +10 priority
nice /path/to/command

# Run at +10 priority
nice -n 10 /path/to/command
```

Priority options can be specified from -20 (higher) to 19 (lower). However, negative values can only be specified by superuser.

You can also use the `renice` command to adjust the priority of already running processes.

```
# Adjust the priority of pid 99999 process
renice 10 -p 99999
```

## nohup

If you use the `nohup` command, you can continue processing even if you log out of the terminal.

After executing the command, you can close the computer and go to bed calmly.

```
nohup /path/to/command &
```

Standard output during execution of the nohup command is saved in the `nohup.out` file.
Is it correct or wrongly? struct type* to struct type[] If I create multiple arcs or rectangles?
Tags: csharp
Published: 2019-12-28 19:48:36

Hello everyone, 

Can I have to give question about drawing multiple rectangles or arcs whatever do you want...


public unsafe static void draw_arcs(..., Arc[] arcs, int num_arcs)
{
...
fixed (Arc* _arcs = arcs)
{
    // m_draw_arcs is an internal method from my dll/so
    m_draw_arcs(display, window, context, _arcs, num_arcs);
}
}

Do you think I am wrong for C#?

Thanks!
create-awesome-package : Released a CLI to bootstrap your awesome package 🚀 📦
Tags: npm, cli, javascript, package
Published: 2019-12-28 19:11:56

CLI - helps to create the package with JS/TS, build system(Webpack/Parcel) and necessary stuff 🔥
It's like create-react-app but for building packages 📦

In our daily life, a lot of times, we need to create a separate package,  so that we can reuse. 

And also sometimes, we want to publish packages to the NPMJS registry,  so that other developers can use them.

But to do that, we need a few things-
- Mainly a bundler like Webpack or Parcel
- Babel to transpire the code

It’s a manual process to arrange all your boilerplate code, Webpack or other build systems to transpile to ES5, etc. and then build your desired package.

To fix that, I have published a CLI tool, which will help us to do those things, and you will be ready to do your actual code right away.


The name of the CLI is <b>create-awesome-package</b>

create-awesome-package helps to create the package with build system and necessary stuff.

You just write your own code 🔥

You can find this on 👉[NPMJS https://www.npmjs.com/package/create-awesome-package](https://www.npmjs.com/package/create-awesome-package)


<h3>How to install</h3>

```
npm i -g create-awesome-package
```

<h3>How to use</h3>

Go to your root of the package you want to build.

Then, Just run

```
create-awesome-package [package-name]
```

OR also you can use npx

```
npx create-awesome-package [package-name]
```
( if you don't want to globally install it)

and you are done!

It will provide you the boilerplate you need to get started!

You can watch the video on YouTube to see the demo how to use it 👋

{% youtube dykr3BHlGck %}

I am working on a few more features for it. I will release those soon.

Cheers!
:wave:

Also posted here [https://shahjada.me/2019/12/28/create-awesome-package-released-a-cli-to-bootstrap-your-awesome-package/](https://shahjada.me/2019/12/28/create-awesome-package-released-a-cli-to-bootstrap-your-awesome-package/)

As I am trying to contribute contents on the Web, you can buy me a coffee for my hours spent on all of these ❤️😊🌸
<a href="https://www.buymeacoffee.com/destromas" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy Me A Coffee" style="height: 51px !important;width: 217px !important;" ></a>

*Inspired from create-react-app*
XODAP ∀ For All
Tags: floss, xodap
Published: 2019-12-28 18:30:17

In Math We Trust
In Trust We Unite
In FLOSS “ ∀ “ We Collaborate

X 🌐 🄳 ∀ ᖘ

X
Xplor
🌐
Openness
🄳
Decentralization
∀
∀ For All
ᖘ
Portal

a place to eXplore Openness which is open source , open speech , open society , open web and world wide web Decentralization for All with portable Portal modularity.

#FLOSS #XODAP #∀ #ForAll
Integrate warden to Ruby on Rails API only app(Very Basic)
Tags: rails, authentication, warden
Published: 2019-12-28 18:27:09

---
title: Integrate warden to Ruby on Rails API only app(Very Basic)
published: true
description: Learn how to integrate warden to your Ruby on Rails API only app
tags: Ruby on Rails, Authentication, warden
---

Here is the link to the tutorial I made: [start now](https://www.youtube.com/playlist?list=PL3tDRmVst0DdPIvIEn5lmCmAbxGXojyQo)
Where to use encryption 🤔
Tags: beginners, help, encryption, react
Published: 2019-12-28 17:36:01

I am developing a nodejs rest API and a react frontend which uses the API. I hope to deploy them on azure. Do I need to enable encryption between the front end and the backend?

**OR**
Is it enough to enable encryption only on the front end?
(I do not plan to expose the API to third parties)