teleren/devto huggingface dataset:
Write your own map filter and reduce
Tags: javascript, webdev
Published: 2019-07-16 22:05:51

So most of us know that these functions already exists.

```javascript
[].map();
[].filter();
[].reduce();
```

But how do they work internally? It's actually pretty easy. So let's just write them ourselves. Cool


### Map

```javascript
function map(array, cb){
   const result = [];
   for(let i = 0; i < array.length; i++){
      const item = array[i];
      result.push(cb(item, i));
   }
   return result;
}
```

Map is pretty simple. 


### Filter

```javascript
function filter(array, cb){
    const result = [];
    for(let i = 0; i < array.length; i++){
       const item = array[i];
       const check = cb(item, i);
       if(check){
            result.push(item);
       }
    }
    return result;

}
```

Also not too tough.

### Reduce

```javascript
function reduce(array, cb, init){
    let result = init;
    for(let i = 0; i < array.length; i++){
        const item = array[i];
        result = cb(result, item, i);
    }

    return result;
}
```

Reduce is a little more involved but it isn't anything too crazy. We just make sure to return what they passed last iteration to the next iteration.


## Final note:


Interestingly enough. Reduce can be our base construct for all our other loops and we can use it to implement `map` and `filter`


### Map using reduce

```javascript
function map(array, cb){
    return reduce(array, (carry, item, i) => {
        const result = cb(item, i);
        carry.push(result);
        return carry;
    }, [])
}
```

### Filter using reduce

```javascript
function filter(array, cb){
    return reduce(array, (carry, item, i) => {
        const check = cb(item, i);
        if(check){
            carry.push(result);
        }
        return carry;
    }, []);
}
```

Anyway don't roll your own reduces and maps unless you have a good reason. But it is nice to know how things work at a lower level. That way you can better utilize them in the future.

Thanks for reading.
Github Engineer Explains How to Drop IE Support — Gracefully
Tags: webdev
Published: 2019-07-16 21:44:34

GitHub [dropped support for Internet Explorer](https://twitter.com/michlbrmly/status/981855020948877312) last summer.
I asked a GitHubber what teams should know to successfully transition their users away from IE.

David Graham answered my call with these tips.
If you find them helpful, thank him on [Twitter](https://twitter.com/davidgraham) or donate to [BlackGirlsCode](http://www.blackgirlscode.com/donations.html).

## Render a Support Banner Server-Side
![IE Support Banner](https://thepracticaldev.s3.amazonaws.com/i/ek1nnl7xxcqgpqp607zj.png)

GitHub's support banner is rendered server-side.
It's rendered sever-side to ensure that it's seen.
Bad JavaScript can halt script execution, preventing code from ever running.
So a message rendered client-side may never get executed.

This is bad if you're attempting to notify users that their browser doesn't support the JavaScript you need.
A client-side message might go unseen by precisely the users who need it.

Render a support banner server-side.

## Check the `User-Agent` string for `Trident`
**Trident** is the engine that powers IE.
Check the request header's [user-agent](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent) string for `Trident`.

How you check the `user-agent` depends on your server technology.
Here's the short version of what we did:

#### Rails/Ruby
```rb
  request.user_agent =~ /Trident/
```
Use the [useragent](https://rubygems.org/gems/useragent/versions/0.16.7) gem for additional detection support.

### Express/NodeJS
```js
  let http = require('http'),
      server = http.createServer(function(request) {
          let isIE = /Trident/.test(request.headers['user-agent']);
      });
```
Use the [express-useragent](https://www.npmjs.com/package/express-useragent) middleware for Express/NodeJS apps.

### Browsers
```js
  /Trident/.test(navigator.userAgent);
```

## Beware of Meddlesome Browser Extensions
Some folks have browser extension that modify their `user-agent` string.
These extensions are often used to access old apps that are *"best in IE"*.

Unfortunately, this means that the `user-agent` sniffing strategy could yield false positives.

To combat these extensions, do a little feature detection on the client.
For example:
IE doesn't support `navigator.mediaDevices`.
If it's present, you user's browser might be lying to you.

Have your server-rendered banner run a few client-side checks.
If you suspect a browser of meddling, trigger a support ticket and handle these cases on an individual basis.

## Don't Pull Your Polyfills on Day One
Be patient with your users.
Don't be too eager to yank the rug out from under them.

Continue to offer support well after your deadline.
Your users will appreciate the extra care.


🕸 [chantastic](https://twitter.com/chantastic)

I'm sure you have tips and tricks for identifying and migrating IE users.
How do **you** do it?
Reading and writing multiple text files from a directory ENOENT Error
Tags: npm
Published: 2019-07-16 21:29:54

I have folder named "Main" on the desktop that has two folders named "Input" and "Output".These folders are created manually (Right Click-New Folder). The script named Verification.js is outside of the folders named "Input" and "Output" folder and inside the "Main" folder. The script reads multiple text files in "Input" folder, runs the logic for all the text files, writes the updated text files in "Output" folder.

My updated program so far in Verification.js script is as follows:

var fs = require('fs')

fs.readdir('Input', (err, files) => {
  if (err) {
      //debugger;
    console.log(err);
    return;
  }
  files.forEach(file => {
    fs.readFile(file, 'utf8', function (err,result) {
      if (err) {
          return console.log(err);
      }
      result = //logic;

      fs.writeFile('Output',result,'utf8', function (err) {
        if (err) {
          return console.log(err);
        }
      });
  });
});



});

I get the following error: It does not recognize the text files.

C:\Users\>cd C:\Users\Desktop\Main

C:\Users\\Desktop\Main>node Verification.js

{ [Error: ENOENT: no such file or directory, open 'C:\Users\\Desktop\Main\TestFile1.txt']
  errno: -4058,
  code: 'ENOENT',
  syscall: 'open',
  path:
   'C:\\Users\\\\Desktop\\Main\\TestFile1.txt' }
{ [Error: ENOENT: no such file or directory, open 'C:\Users\\Desktop\Main\TestFile2.txt']
  errno: -4058,
  code: 'ENOENT',
  syscall: 'open',
  path:
   'C:\\Users\\\\Desktop\\Main\\TestFile2.txt' }
   
How do I rectify it? It doesnt recognize the input folder in the 'path' attribute as shown in the error and also the text files.
TIL — Static Factory Methods
Tags: java, todayilearned, effectivejava
Published: 2019-07-16 21:08:47

---
title: TIL — Static Factory Methods
published: true
description: My run-in with static factory methods
tags: java, til, Effective Java
---

Today my work tasks led me to read about static factory methods, which are a different approach to initializing Java classes.

<img src="https://miro.medium.com/max/1400/0*RFyOEFIPJqOZMCtZ" alt="A bottling factory" />

Effective Java (Addison-Wesley 2018) helped me understand this concept, and here is my brief take on that reading:
Bottles moving through an actual factory.Bottles moving through an actual factory.

-Static factory methods are given names, which helps us as developers better and more quickly understand what they do.
-They save time and memory in your program, because they aren’t required to create new instances when they are run.
-They can create subtypes that differ from release to release. These subtypes don’t even have to have their class written at the time that the method is written.
-They certainly don’t solve every problem. They don’t scale well with growing parameters. But the example given in the book illustrates this concepts use:

```java
public static Boolean valueOf(boolean b) {
       return b ? Boolean.TRUE : Boolean.FALSE;
}
```
Here you dynamically return an initialized boolean with concise and easy-to-understand code. That is just simply worth it.
Cheers.
I (definitely) need some help
Tags: beginners, design, javascript, java
Published: 2019-07-16 16:58:52

Hey guys, this my first post here and I just wanted to ask HOW DID YOU LEARN <strong>AND</strong> KEPT YOUR STUFF IN MIND???

Let me tell you all my sob story:

I started programming about 1 year and a half ago, I started with C# at university and I really like doing some while loops and stuff but that was obviously not enough. I needed money (fast) so I trying learning HTML, CSS and JavaScript so that I could make the BEST websites of the world and sell then at top dollar. Turned out I sucked at design and now I buy Wordpress templates to make a living, shame on me.

I like Web Developing, but I got so frustrated when tried to make first website from totally nothing, that today it is on standby, I guess I can't even make a callback function any more. After this huge deception, I began with PHP, did a little CRUD system, but I hate the language.

I really have an issue, I can't focus at one thing for too long, this programming world have too many options and I like all of them, I even bought a freaking <strong>Machine learning</strong> course at Udemy to learn Python. 

As life goes on, today I am learning Java to develop for Android, but I feel that I will just drop out of it too, I get excited fast and frustrated even faster, I need some small project to exercise all this stuff I have learned, but I don't have enough creativity to start something from the ground.

Could you help me finding somewhere (or maybe someone) to give me small projects so that I can start again with baby steps? If you guys have some magic path I can follow to learn and use some language, I would be extremely grateful for life.
Why Don't More Developers Edit Wikipedia?
Tags: wikipedia, opensource, writing, discuss
Published: 2019-07-16 21:00:45

This is not the start of a rant. I am genuinely curious why more developers don't contribute to Wikipedia, whether about tech topics, or any other interests. A common barrier for many people, namely the archaic _wiki markup_ is less applicable to developers. While most developers **do not** contribute to open source software, many do write bug reports, or push for their companies to use open source because it's standardised and transferable knowledge in many cases. 

There isn't the same incentive or necessity with knowledge on Wikipedia. 

How can we change this? Enclosed my [English Wikipedia profile](https://en.wikipedia.org/wiki/User:Shushugah). Ping me if you want to get more active! Maybe we can organise a virtual Edit-A-Thon here.
Getting Started with C# Lists
Tags: csharp, tutorial, beginners
Published: 2019-07-16 20:39:39

---
title: Getting Started with C# Lists
published: true
tags: csharp,tutorial,beginners
series: C# Collections
cover_image: https://wellsb.com/csharp/wp-content/uploads/sites/2/2019/07/beginners-list-initialize-min.png
---

Collections in C# can be considered "arrays on steroids." A List is a type of collection that enables you to take advantage of the rich sorting, filtering, and aggregation features available in the .NET Core framework through LINQ queries.

In this tutorial, you will learn how to initialize a generic list, List&lt;T>. You will also learn a pair of useful techniques for adding elements to a list.

[Source](https://wellsb.com/csharp/beginners/csharp-initialize-list/)
Plans gone Astray
Tags: personalthoughts
Published: 2019-07-16 20:52:18

---
title: Plans gone Astray
published: true
tags: #personalthoughts
canonical_url: https://distort-roving.blogspot.com/2019/07/plans-gone-astray.html
cover_image: https://images.pexels.com/photos/6189/hand-laptop-notebook-technology.jpg
---

Sometimes, things happen. We look at the situation with the best of intentions, and it simply doesn't work. This short post has taken me well over three hours to produce.  
  
After catching a box that was sliding (heavier than expected) directly on the shoulder joint, my typing has been severely limited, and hand- writing and -drawing even more so. And this is driving me insane.  
  
I want to say I've done a lot of study, and moving forward - but I haven't. I've been hyper-focused on a series of interviews, and attempting to tease out usable information given to me by those that are using another computer language, or a different framework. One of those folks is super-helpful: and makes me wish to go to the keyboard and type - but I can't. And it frustrates her and I.  
  
I have a longer post I've been working on, so I hope the next post is more informative!
UTF-8 csv fix for Excel
Tags: unicode, excel, php, javascript
Published: 2019-07-16 20:36:48


Using *utf-8* for your CSV files sounds obvious and works well in most software processing them.  
Most software except Micrososft's Excel, which, considering its number of users, can sadden your day.

Excel seems to assume *windows-1252* __unless a [Byte order mark](https://en.wikipedia.org/wiki/Byte_order_mark) is provided__.


To fix this without asking your users to navigate a maze of hidden menus, you can add a BOM to a string before saving it to a file or triggering a download.


In JavaScript:
```javascript
let csvString = ["a,b,c", "1,2,3"].join("\n");
csvString = "\ufeff" + csvString;
```

or in PHP:
```php
$csvString = implode("\n", ["a,b,c", "1,2,3"]);
$csvString = chr(0xEF) . chr(0xBB) . chr(0xBF) . $csvString;
```

If you look at the hex dump, you can check for the presence of this byte sequence at the very beginning: `EF BB BF`.
component #3 - Video Player
Tags: react
Published: 2019-07-16 20:23:58

---
title: component #3 - Video Player
published: true
description: This is a part of *30 components / month* challenge.
tags: #react
---
{% codesandbox sjer4 %}

## What I have learned?

- That it's not easy to customize the controls of a video player.
- Support cross browser platforms with the ultimate `||` logical operator.
- Use the mind-blowing `<progress></progress>` html tag.
  

## What are the main challenges?

I haven't tried doing this before. 
So this is my first time making a custom video player and I really enjoy doing it and having fun playing around with their [Media Api](https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement). It's coooool!


## Why am I doing this anyway?

- To learn.
- To have fun.
- To future Joimee (for reference).

Resources:
[Video player styling basics](https://developer.mozilla.org/en-US/docs/Web/Guide/Audio_and_video_delivery/Video_player_styling_basics)
[Media Api](https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement)


Salamat.
Blogging despite fear of Twitter Cool Guys using 1) lists and 2) GIFs
Tags: writing, justdoit, fear, hottakes
Published: 2019-07-16 20:02:47

---
title: Blogging despite fear of Twitter Cool Guys using 1) lists and 2) GIFs
published: true
description: Wouldn't it be nice to just have something to write
tags: writing, justDoIt, fear, hotTakes
cover_image: https://media.giphy.com/media/Ph6v3JkxUVdrCRgD46/giphy.gif
---

I wish it was easier to come up with something to write about! I have a blog over at [aaronransley.com/blog](https://aaronransley.com/blog) that I'm trying to get off the ground, but it's tough to find topics to write about.

---

My process typically goes something like this:

1. I want to write, and share with the world!
2. Oh, I'll write about XYZ from work!
3. Wait, I can't really share that because it's Company Secrets.
4. Maybe I'll write about this cool tech I used!
5. Ok, now to just make it abstract enough that it isn't Company Secrets.
6. Hmm, this is really watered down.
7. These 19 other blog posts do a much better job of explaining this concept.
8. I shouldn't waste anyone's time. 😢

---

Next, I'll pivot to something more pet-project in nature:

1. I want to write, and share with the world!
2. Oh, I'll write about XYZ personal site!
3. Wait, this project is so simple that it doesn't warrant a blog post.
4. I should work on more important side projects, things with value!
5. Wow, that would take a lot of time. I spend so much time at work on Company Secrets.
6. Am I wasting my life working on things I can't share?
7. Oh look, 14 new tools from prolific makers on Twitter!
8. I'm not smart enough to fit in. 😢

---

Ok, one last try. Maybe I'll write about this very thing! Everyone has feelings, right?

1. I want to write about how I want to write but can't quite get there!
2. Ok, here are some Real Thoughts in lists. This is good, I am being honest.
3. Wait, this honesty stuff isn't as easy as the LiveJournal days.
4. If everyone sees this, will they think I'm a `0.1x Beta Professional`?
5. What if I keep adding items to this list, to make it&mdash;like&mdash;a thing?
6. Hmm, this is kind of working. I'm almost to 8 items.
7. What if I just pressed Publish and didn't worry about it?
8. Then I'd have done it! I'll have written and shared! 😊

---

### Am I really going to do this? _Why is it so scary?!_

<img width='420' src='https://media.giphy.com/media/l4pTqdlMJVeqbxXry/giphy.gif'>

> Let me just preview things here... Is my Markdown formatting working OK?

<img width='420' src='https://media.giphy.com/media/2zZKmC3BnDicRHbm8z/giphy.gif'>

> What about the *Hot Takes from The Internet*?!

<img width='420' src='https://media.giphy.com/media/yCzWVYBFTOAik/giphy.gif'>

> Whatever, here we go.

<img width='420' src='https://media.giphy.com/media/3o6oztFarz7aiK2cCc/giphy.gif'>
Microverse Student at 47
Tags: microverse, html, noob, beginners
Published: 2019-07-16 19:56:51

---
title: Microverse Student at 47
published: true
description: Learning to code
tags: #microverse #html #noob #beginner
---
What am I doing at 47?

At 47 what am I doing? After two wars thirteen years apart. Then for the past 14 years helping my love through the hardest fight ever. As she fought for her three boys or um young men and two grandchildren. Brain cancer is a beast it takes allot not just from the one person. But from a growing family.

Now with the boys to guide. I am at 47 moving into the career of programming. Being from Gen X I should have been at the beginning of the computer revolution. So now when it seems that the millennials should have it on lock. I'm scratching my way back in.

Between doctor appointments and so on the last few years. I have struggled to learn on my own. With Udemy.com, YouTube.com, and FreeCodeCamp.org. I am starting again.

This time with a new startup called Microverse. Where they help you by giving you more structure and have you work with a coding partner. Then when you finish a project it is peer-reviewed by students ahead of you. They give you pointers on issues and better ways to go about an issue.
So far I have finished the HTML/CSS section of the Microverse.org curriculum. Adding to what I learned so far. But now it is making sense and sticking better.

Moving from a basic understanding of HTML and CSS. To now have a better grasp of using git, HTML, CSS, linters, SASS and media queries. They all still rattle me at times but I am no longer scared.
47 is just a number. It doesn't matter much but gives you more life experience.

Some of the concepts can be hard but so can life so fight through and it. The concepts will get remembered. Stored away in our brains just like the rest of life.

So at 47, I am a coding baby. Learning to walk and talk. My page is built with HTML but with CSS I can change the view of how it looks. I am learning to communicate better. Learning to guide the boys better since losing their mother. We might look like a web page from the late 90's today. But with time it will be filled with Javascript, Ruby, and algorithms ahhhhhh.

Time to sit back learn and enjoy the ride.
Fun Times At The Company Hackathon
Tags: hackathon, discuss, react, reactnative
Published: 2019-07-16 18:44:42

---
title: Fun Times At The Company Hackathon
published: true
description: 
tags: hackathon, discuss, react, reactnative
---

Last month I was able to participate in my company’s first official hackathon. The rules were simple:

1. Pick a team (no solo hacking).
2. Pick an idea (either product idea or internal tool).
3. Work on it for 2 days.
4. Present the project in 3 minutes or less.

Including myself, I ended up in a group of three. We explored different ideas and ultimately decided on a simple React app that recorded “learning items” as we try to “level up” our tech skills.  In all honesty, this was really just a glorified todo app with some gamification sprinkled on top.  But I found the process of going from whiteboard design to working app (and all the iterations in between) with a group I never worked with in such a short amount time to be pretty invaluable.

We initially used the live feature in CodeSandBox but that quickly didn't work out as we started clobbering over each other's work.  Although we ended up using our own local dev environments and merged them together at the end, it was a good excuse to try out some other collaboration tools.  I would recommend the live feature in CodeSandBox for short bits of collaboration but not for long term ongoing use.   

Whiteboard Design| One Design Iteration
:--------------:|:---------------:
![](https://thepracticaldev.s3.amazonaws.com/i/kpvs0dn3m7hnmm1p5sbc.jpg) |![](https://thepracticaldev.s3.amazonaws.com/i/ir8a9hbge9p35k4juklk.PNG) 

I also got a chance to [play around with React Native](https://vimeo.com/348429332) for the first time in attempt to try to port the app to a mobile platform.  SPOILER ALERT: It's not as simple as just taking your React code and having it render to React Native.  But I will say I was super easy to get up and started using https://snack.expo.io/.

Two days went by VERY quickly and before we knew it, it was time to present.  The concluding 3 minute presentations were all done over [Zoom](https://zoom.us/) so that the remote teams could also participate.  This worked out really well as we able to record everything and no one felt left out if they were not in the office.  At the end of the presentations, the entire company was able to vote for their favorite project.

A couple of things the hackathon accomplished:

1. Gave employees a chance to take a break from their usual tasks.
2. Provided an opportunity to work with different people to create a unique team building experience.
3. Gave employees a chance to explore other technologies and languages.
4. Gave the product teams many prototyped ideas. 
5. Rallied the company together around engineering innovations.

Overall, it was a great experience and I firmly believe it was just as good for the company as it was for the employees.  Apparently the leaders of the company also thought it was success and I've heard rumblings of wanting to do this every 6 months.

I can't wait.

Do you have a cool hackathon experience or project you would like share?
Transforming Tech Recruiting into a meaningful platform
Tags: discuss, career, help
Published: 2019-07-16 18:33:01

After seeing several posts about recruiters and the lack of knowledge needed to properly submit the right candidate to the correct job, I wondered if there was anything else Engineers wished recruiters would do better? As a recruiter, I strive to be the best for both the client and candidate, please help me build a better experience!